9 eval { require Test::WWW::Mechanize::Catalyst }
11 "Test::WWW::Mechanize::Catalyst is needed for this test";
12 eval { require Catalyst::Plugin::Cache::FileCache }
14 "Catalyst::Plugin::Cache::FileCache is needed for this test";
25 Authentication::Store::Minimal
26 Authentication::Credential::HTTP
35 my ( $self, $c ) = @_;
37 $c->authorization_required( realm => 'testrealm@host.com' );
39 $c->res->body( $c->user->id );
41 __PACKAGE__->config->{authentication}{http}{type} = 'digest';
42 __PACKAGE__->config->{authentication}{users} = $users = {
43 Mufasa => { password => "Circle Of Life", },
49 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
51 my $mech = Test::WWW::Mechanize::Catalyst->new;
53 $mech->get("http://localhost/moose");
54 is( $mech->status, 401, "status is 401" );
56 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
57 my %www_auth_params = map {
\r
58 my @key_val = split /=/, $_, 2;
\r
59 $key_val[0] = lc $key_val[0];
\r
60 $key_val[1] =~ s{"}{}g; # remove the quotes
\r
62 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
64 $mech->content_lacks( "foo", "no output" );
68 my $username = 'Mufasa';
\r
69 my $password = 'Circle Of Life';
\r
70 my $realm = $www_auth_params{realm};
\r
71 my $nonce = $www_auth_params{nonce};
\r
72 my $cnonce = '0a4f113b';
\r
73 my $opaque = $www_auth_params{opaque};
\r
74 my $nc = '00000001';
\r
79 my $ctx = Digest::MD5->new;
\r
80 $ctx->add( join( ':', $username, $realm, $password ) );
\r
81 my $A1_digest = $ctx->hexdigest;
83 $ctx = Digest::MD5->new;
\r
84 $ctx->add( join( ':', $method, $uri ) );
\r
85 my $A2_digest = $ctx->hexdigest;
87 my $digest = Digest::MD5::md5_hex(
\r
89 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
\r
92 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
95 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
98 $r->headers->push_header( Authorization => $response );
101 is( $mech->status, 200, "status is 200" );
102 $mech->content_contains( "Mufasa", "Mufasa output" );