X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbasic.t;h=35d733a23912a461c6ecead2e36c2699cb1264a4;hb=e9684b75e36759a90cdf18513300638b0cef4092;hp=84d68225bfe90f3acd728f6935ebee25c1add654;hpb=2022b950f27ae8a320b6aac0aa9d1f03a0959fbf;p=catagits%2FCatalyst-Authentication-Credential-HTTP.git diff --git a/t/basic.t b/t/basic.t index 84d6822..35d733a 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,58 +1,48 @@ #!/usr/bin/perl - use strict; use warnings; - use Test::More tests => 13; use Test::MockObject::Extends; use Test::MockObject; +use Test::Exception; use HTTP::Headers; - my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Credential::HTTP") } - can_ok( $m, "authenticate_http" ); can_ok( $m, "authorization_required" ); can_ok( $m, "authorization_required_response" ); - my $req = Test::MockObject->new; my $req_headers = HTTP::Headers->new; - $req->set_always( headers => $req_headers ); - my $res = Test::MockObject->new; - my $status; $res->mock(status => sub { $status = $_[1] }); - my $res_headers = HTTP::Headers->new; $res->set_always( headers => $res_headers ); - my $c = Test::MockObject::Extends->new( $m ); - +my $cache = Test::MockObject->new; +$cache->mock(set => sub { shift->{$_[0]} = $_[1] }); +$cache->mock(get => sub { return shift->{$_[0]} }); +$c->mock(cache => sub { $cache }); my @login_info; $c->mock( login => sub { shift; @login_info = @_; 1 } ); -$c->set_false( "detach" ); $c->set_always( config => {} ); $c->set_always( req => $req ); $c->set_always( res => $res ); - ok( !$c->authenticate_http, "http auth fails without header"); - $req_headers->authorization_basic( qw/foo bar/ ); - ok( $c->authenticate_http, "auth successful with header"); is_deeply( \@login_info, [qw/foo bar/], "login info delegated"); - -ok( $c->authorization_required, "authorization required with successful authentication"); -ok( !$c->called("detach"), "didnt' detach"); - +lives_ok { + $c->authorization_required +} "no detach on authorization required with successful authentication"; $req_headers->clear; $c->clear; - -ok( !$c->authorization_required, "authorization required with bad authentication"); -$c->called_ok("detach", "detached"); - +throws_ok { + $c->authorization_required( realm => "foo" ); +} qr/^ $Catalyst::DETACH $/x, "detached on no authorization required with bad auth"; is( $status, 401, "401 status code" ); -like( $res_headers->www_authenticate, qr/^Basic/, "WWW-Authenticate header set"); +like( ($res_headers->header('WWW-Authenticate'))[0], qr/^Digest/, "WWW-Authenticate header set: digest"); +like( ($res_headers->header('WWW-Authenticate'))[1], qr/^Basic/, "WWW-Authenticate header set: basic"); +like( ($res_headers->header('WWW-Authenticate'))[1], qr/realm=foo/, "WWW-Authenticate header set: basic with realm");