6 eval { require Test::WWW::Mechanize::Catalyst }
8 "Test::WWW::Mechanize::Catalyst is needed for this test";
9 eval { require Catalyst::Plugin::Cache }
11 "Catalyst::Plugin::Cache is needed for this test";
12 eval { require Cache::FileCache }
14 "Cache::FileCache is needed for this test";
22 Authentication::Store::Minimal
23 Authentication::Credential::HTTP
29 my ( $self, $c ) = @_;
30 $c->authorization_required( realm => 'testrealm@host.com' );
31 $c->res->body( $c->user->id );
33 __PACKAGE__->config->{cache}{backend} = {
34 class => 'Cache::FileCache',
36 __PACKAGE__->config->{authentication}{http}{type} = 'digest';
37 __PACKAGE__->config->{authentication}{users} = $users = {
38 Mufasa => { password => "Circle Of Life", },
42 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
43 my $mech = Test::WWW::Mechanize::Catalyst->new;
44 $mech->get("http://localhost/moose");
45 is( $mech->status, 401, "status is 401" );
46 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
47 my %www_auth_params = map {
48 my @key_val = split /=/, $_, 2;
49 $key_val[0] = lc $key_val[0];
50 $key_val[1] =~ s{"}{}g; # remove the quotes
52 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
53 $mech->content_lacks( "foo", "no output" );
56 my $username = 'Mufasa';
57 my $password = 'Circle Of Life';
58 my $realm = $www_auth_params{realm};
59 my $nonce = $www_auth_params{nonce};
60 my $cnonce = '0a4f113b';
61 my $opaque = $www_auth_params{opaque};
66 my $ctx = Digest::MD5->new;
67 $ctx->add( join( ':', $username, $realm, $password ) );
68 my $A1_digest = $ctx->hexdigest;
69 $ctx = Digest::MD5->new;
70 $ctx->add( join( ':', $method, $uri ) );
71 my $A2_digest = $ctx->hexdigest;
72 my $digest = Digest::MD5::md5_hex(
74 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
77 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
79 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
81 $r->headers->push_header( Authorization => $response );
83 is( $mech->status, 200, "status is 200" );
84 $mech->content_contains( "Mufasa", "Mufasa output" );