Changeset 18008

Show
Ignore:
Timestamp:
08/22/08 05:39:49 (5 years ago)
Author:
tokuhirom
Message:

added test case for Authorizer::BasicAuth?
fixed bugs around A::Basic

Location:
lang/perl/Nanto/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Nanto/trunk/lib/Nanto/Web/Plugin/Authorizer/Basic.pm

    r17981 r18008  
    55    is       => 'ro', 
    66    isa      => 'ArrayRef[HashRef]', 
     7    required => 1, 
     8); 
     9 
     10has 'realm' => ( 
     11    is       => 'ro', 
     12    isa      => 'Str', 
    713    required => 1, 
    814); 
     
    1723            status => 401, 
    1824            headers => { 
    19                 'WWW-Authenticate' => qq(Basic Realm="ulgori") 
     25                'WWW-Authenticate' => qq(Basic Realm="@{[ $self->realm ]}") 
    2026            }, 
    2127        ); 
     
    3036        my $sent_cred = $req->headers->authorization_basic; 
    3137        if ($sent_cred && $sent_cred eq $cred) { 
    32             DEBUG "BASIC AUTH OK"; 
    33             return 1; 
     38            return 1; ### ok 
    3439        } 
    3540    } 
    3641 
    37     return 0; # failed 
     42    return 0; ### failed 
    3843} 
    3944 
  • lang/perl/Nanto/trunk/t/030_web_plugin/Authorizer-BasicAuth.t

    r18000 r18008  
    11use strict; 
    22use warnings; 
    3 use HTTP::Engine; 
     3use t::Utils; 
     4use Test::More tests => 5; 
    45 
    5 HTTP::Engine->new( 
    6     interface => { 
    7         module => 'Test', 
    8         request_handler => sub { 
    9         }, 
    10     }, 
    11 ); 
     6handler->load_plugin({ 
     7    module => 'Authorizer::Basic', 
     8    config => { 
     9        acl => [ 
     10            {username => 'foo', password => 'bar'}, 
     11        ], 
     12        realm => 'this is test', 
     13    } 
     14}); 
     15 
     16# no pass 
     17do { 
     18    my $res = run_engine( 
     19        'GET', '/' 
     20    ); 
     21    is $res->code, 401; 
     22    is $res->www_authenticate, 'Basic Realm="this is test"'; 
     23}; 
     24 
     25# invalid pass 
     26do { 
     27    my $res = run_engine( 
     28        'GET', '/', do { 
     29            my $headers = HTTP::Headers->new(); 
     30            $headers->authorization_basic('foo', 'iyan'); 
     31            $headers; 
     32        } 
     33    ); 
     34    is $res->code, 401; 
     35    is $res->www_authenticate, 'Basic Realm="this is test"'; 
     36}; 
     37 
     38# success 
     39do { 
     40    my $res = run_engine( 
     41        'GET', '/', do { 
     42            my $headers = HTTP::Headers->new(); 
     43            $headers->authorization_basic('foo', 'bar'); 
     44            $headers; 
     45        } 
     46    ); 
     47    is $res->code, 200; 
     48}; 
     49 
  • lang/perl/Nanto/trunk/t/Utils.pm

    r18000 r18008  
    66use lib 't/lib'; 
    77use Foo::Web::Dispatcher; 
     8use Nanto::ClassLoader; 
     9use Nanto::Web::Handler; 
     10use HTTP::Engine; 
    811 
    912my $handler; 
    10 sub handler { 
     13sub handler() { 
    1114    $handler ||= Nanto::Web::Handler->new( 
    1215        dispatcher => 'Foo::Web::Dispatcher', 
     
    1922 
    2023sub run_engine { 
    21     my $req = shift; 
     24    my @args = @_; 
    2225    my $res = HTTP::Engine->new( 
    2326        interface => { 
     
    2932            }, 
    3033        }, 
    31     )->run($req); 
     34    )->run(HTTP::Request->new( @args )); 
    3235    return $res; 
    3336}