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";
20 use Test::WWW::Mechanize::Catalyst qw/AuthDigestTestApp/;
25 my $mech = Test::WWW::Mechanize::Catalyst->new;
26 $mech->get("http://localhost/moose");
27 is( $mech->status, 401, "status is 401" );
28 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
29 my %www_auth_params = map {
30 my @key_val = split /=/, $_, 2;
31 $key_val[0] = lc $key_val[0];
32 $key_val[1] =~ s{"}{}g; # remove the quotes
34 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
35 $mech->content_lacks( "foo", "no output" );
38 my $password = 'Circle Of Life';
39 my $realm = $www_auth_params{realm};
40 my $nonce = $www_auth_params{nonce};
41 my $cnonce = '0a4f113b';
42 my $opaque = $www_auth_params{opaque};
47 my $ctx = Digest::MD5->new;
48 $ctx->add( join( ':', $username, $realm, $password ) );
49 my $A1_digest = $ctx->hexdigest;
50 $ctx = Digest::MD5->new;
51 $ctx->add( join( ':', $method, $uri ) );
52 my $A2_digest = $ctx->hexdigest;
53 my $digest = Digest::MD5::md5_hex(
55 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
58 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
60 my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
62 $r->headers->push_header( Authorization => $response );
64 is( $mech->status, 200, "status is 200" );
65 $mech->content_contains( $username, "Mufasa output" );
70 do_test('Mufasa', '/moose?moose_id=1'); # Digest auth includes the full URL path, so need to test query strings