8 eval { require Test::WWW::Mechanize::Catalyst }
10 "Test::WWW::Mechanize::Catalyst is needed for this test";
11 eval { require Catalyst::Plugin::Cache }
13 "Catalyst::Plugin::Cache is needed for this test";
14 eval { require Cache::FileCache }
16 "Cache::FileCache is needed for this test";
22 use Test::WWW::Mechanize::Catalyst qw/AuthDigestTestApp/;
27 my $mech = Test::WWW::Mechanize::Catalyst->new;
28 $mech->get("http://localhost/moose");
29 is( $mech->status, 401, "status is 401" );
30 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
31 my %www_auth_params = map {
32 my @key_val = split /=/, $_, 2;
33 $key_val[0] = lc $key_val[0];
34 $key_val[1] =~ s{"}{}g; # remove the quotes
36 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
37 $mech->content_lacks( "foo", "no output" );
40 my $password = 'Circle Of Life';
41 my $realm = $www_auth_params{realm};
42 my $nonce = $www_auth_params{nonce};
43 my $cnonce = '0a4f113b';
44 my $opaque = $www_auth_params{opaque};
49 my $ctx = Digest::MD5->new;
50 $ctx->add( join( ':', $username, $realm, $password ) );
51 my $A1_digest = $ctx->hexdigest;
52 $ctx = Digest::MD5->new;
53 $ctx->add( join( ':', $method, $uri ) );
54 my $A2_digest = $ctx->hexdigest;
55 my $digest = Digest::MD5::md5_hex(
57 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
60 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
62 my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
64 $r->headers->push_header( Authorization => $response );
66 is( $mech->status, 200, "status is 200" );
67 $mech->content_contains( $username, "Mufasa output" );
72 do_test('Mufasa', '/moose?moose_id=1'); # Digest auth includes the full URL path, so need to test query strings