Changeset 18008
- Timestamp:
- 08/22/08 05:39:49 (5 years ago)
- Location:
- lang/perl/Nanto/trunk
- Files:
-
- 3 modified
-
lib/Nanto/Web/Plugin/Authorizer/Basic.pm (modified) (3 diffs)
-
t/030_web_plugin/Authorizer-BasicAuth.t (modified) (1 diff)
-
t/Utils.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Nanto/trunk/lib/Nanto/Web/Plugin/Authorizer/Basic.pm
r17981 r18008 5 5 is => 'ro', 6 6 isa => 'ArrayRef[HashRef]', 7 required => 1, 8 ); 9 10 has 'realm' => ( 11 is => 'ro', 12 isa => 'Str', 7 13 required => 1, 8 14 ); … … 17 23 status => 401, 18 24 headers => { 19 'WWW-Authenticate' => qq(Basic Realm=" ulgori")25 'WWW-Authenticate' => qq(Basic Realm="@{[ $self->realm ]}") 20 26 }, 21 27 ); … … 30 36 my $sent_cred = $req->headers->authorization_basic; 31 37 if ($sent_cred && $sent_cred eq $cred) { 32 DEBUG "BASIC AUTH OK"; 33 return 1; 38 return 1; ### ok 34 39 } 35 40 } 36 41 37 return 0; # failed42 return 0; ### failed 38 43 } 39 44 -
lang/perl/Nanto/trunk/t/030_web_plugin/Authorizer-BasicAuth.t
r18000 r18008 1 1 use strict; 2 2 use warnings; 3 use HTTP::Engine; 3 use t::Utils; 4 use Test::More tests => 5; 4 5 5 HTTP::Engine->new( 6 interface => { 7 module => 'Test', 8 request_handler => sub { 9 }, 10 }, 11 ); 6 handler->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 17 do { 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 26 do { 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 39 do { 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 6 6 use lib 't/lib'; 7 7 use Foo::Web::Dispatcher; 8 use Nanto::ClassLoader; 9 use Nanto::Web::Handler; 10 use HTTP::Engine; 8 11 9 12 my $handler; 10 sub handler {13 sub handler() { 11 14 $handler ||= Nanto::Web::Handler->new( 12 15 dispatcher => 'Foo::Web::Dispatcher', … … 19 22 20 23 sub run_engine { 21 my $req = shift;24 my @args = @_; 22 25 my $res = HTTP::Engine->new( 23 26 interface => { … … 29 32 }, 30 33 }, 31 )->run( $req);34 )->run(HTTP::Request->new( @args )); 32 35 return $res; 33 36 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)