X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_app.t;h=40e2ced646ab748e511827255e616b1d0bce8aa5;hb=87ccaba73a1a7fc4f22d24a4bd2cec37b7a385fe;hp=770115db6a0cb385d90fc02261465c801622a9a6;hpb=ed61ff6d1bf42ac1afee878dd50f62dfc5861c1f;p=catagits%2FCatalyst-Authentication-Credential-HTTP.git diff --git a/t/live_app.t b/t/live_app.t index 770115d..40e2ced 100644 --- a/t/live_app.t +++ b/t/live_app.t @@ -1,60 +1,46 @@ #!/usr/bin/perl - use strict; use warnings; -use Test::More; +use FindBin qw/$Bin/; +use lib "$Bin/lib"; +use Test::More; BEGIN { - eval { require Test::WWW::Mechanize::Catalyst } + do { + eval { require Test::WWW::Mechanize::Catalyst } + and + Test::WWW::Mechanize::Catalyst->VERSION('0.51') + } or plan skip_all => "Test::WWW::Mechanize::Catalyst is needed for this test"; - plan tests => 4; } - use HTTP::Request; -{ - - package AuthTestApp; - use Catalyst qw/ - Authentication - Authentication::Store::Minimal - Authentication::Credential::HTTP - /; - - use Test::More; - - our $users; - - sub moose : Local { - my ( $self, $c ) = @_; - - $c->authorization_required; - - $c->res->body( $c->user->id ); - } - - __PACKAGE__->config->{authentication}{users} = $users = { - foo => { password => "s3cr3t", }, - }; - - __PACKAGE__->setup; -} - -use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; - -my $mech = Test::WWW::Mechanize::Catalyst->new; - +use Test::More; +use Test::WWW::Mechanize::Catalyst; +my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); $mech->get("http://localhost/moose"); -is( $mech->status, 401, "status is 401" ); - +is( $mech->status, 401, "status is 401" ) or die $mech->content; $mech->content_lacks( "foo", "no output" ); - my $r = HTTP::Request->new( GET => "http://localhost/moose" ); $r->authorization_basic(qw/foo s3cr3t/); - $mech->request($r); is( $mech->status, 200, "status is 200" ); $mech->content_contains( "foo", "foo output" ); +AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(1); +$mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); +$mech->get("http://localhost/moose"); +isnt( $mech->status, 401, "status isnt 401" ) or die $mech->content; + +AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(0); +AuthTestApp->get_auth_realm('test')->credential->require_ssl(1); +$mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); +$r = HTTP::Request->new( GET => "http://localhost/moose" ); +$r->authorization_basic(qw/foo s3cr3t/); +$mech->request($r); +is( $mech->status, 401, "status is 401" ); + +done_testing; +