6 use Test::More tests => 13;
7 use Test::MockObject::Extends;
12 my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Credential::HTTP") }
14 can_ok( $m, "authenticate_http" );
15 can_ok( $m, "authorization_required" );
16 can_ok( $m, "authorization_required_response" );
18 my $req = Test::MockObject->new;
19 my $req_headers = HTTP::Headers->new;
21 $req->set_always( headers => $req_headers );
23 my $res = Test::MockObject->new;
26 $res->mock(status => sub { $status = $_[1] });
28 my $res_headers = HTTP::Headers->new;
29 $res->set_always( headers => $res_headers );
31 my $c = Test::MockObject::Extends->new( $m );
34 $c->mock( login => sub { shift; @login_info = @_; 1 } );
35 $c->set_false( "detach" );
36 $c->set_always( config => {} );
37 $c->set_always( req => $req );
38 $c->set_always( res => $res );
41 ok( !$c->authenticate_http, "http auth fails without header");
43 $req_headers->authorization_basic( qw/foo bar/ );
45 ok( $c->authenticate_http, "auth successful with header");
46 is_deeply( \@login_info, [qw/foo bar/], "login info delegated");
48 ok( $c->authorization_required, "authorization required with successful authentication");
49 ok( !$c->called("detach"), "didnt' detach");
54 ok( !$c->authorization_required, "authorization required with bad authentication");
55 $c->called_ok("detach", "detached");
57 is( $status, 401, "401 status code" );
58 like( $res_headers->www_authenticate, qr/^Basic/, "WWW-Authenticate header set");