X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_app.t;h=e9b9ea0eeded9baab2f46c57e14fcc50eee2403e;hb=6cd8c8c7d08ee9846718912d2733dec956341eee;hp=943681a3c6618de3273893d6dbaa7b37a286d8dc;hpb=0914298e67babb131596ff9d7317b737a0c1ec6a;p=catagits%2FCatalyst-Authentication-Credential-HTTP.git diff --git a/t/live_app.t b/t/live_app.t index 943681a..e9b9ea0 100644 --- a/t/live_app.t +++ b/t/live_app.t @@ -1,65 +1,59 @@ #!/usr/bin/perl - use strict; use warnings; - -use Test::More tests => 4; +use Test::More; +BEGIN { + eval { require Test::WWW::Mechanize::Catalyst } + 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; - use Test::Exception; - - use Digest::MD5 qw/md5/; - - 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", - }, - bar => { - crypted_password => crypt("s3cr3t", "x8"), - }, - gorch => { - hashed_password => md5("s3cr3t"), - hash_algorithm => "MD5", - }, - baz => {}, - }; - - __PACKAGE__->setup; + package AuthTestApp; + use Catalyst qw/ + Authentication + /; + use Test::More; + our %users; + __PACKAGE__->config(authentication => { + default_realm => 'test', + realms => { + test => { + store => { + class => 'Minimal', + users => \%users, + }, + credential => { + class => 'HTTP', + type => 'basic', + password_type => 'clear', + password_field => 'password' + }, + }, + }, + }); + sub auto : Private { + my ($self, $c) = @_; + $c->authenticate(); + } + sub moose : Local { + my ( $self, $c ) = @_; + $c->res->body( $c->user->id ); + } + %users = ( + foo => { password => "s3cr3t", }, + ); + __PACKAGE__->setup; } - use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; - my $mech = Test::WWW::Mechanize::Catalyst->new; - $mech->get("http://localhost/moose"); -is( $mech->status, 401, "status is 401"); - -$mech->content_lacks("foo", "no output"); - +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"); - +$mech->request($r); +is( $mech->status, 200, "status is 200" ); +$mech->content_contains( "foo", "foo output" );