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