7 'Test::WWW::Mechanize::Catalyst' => '0.51',
8 'Catalyst::Plugin::Cache' => '0',
9 'Cache::FileCache' => undef,
17 use Test::WWW::Mechanize::Catalyst qw/AuthDigestTestApp/;
22 my $mech = Test::WWW::Mechanize::Catalyst->new;
23 $mech->get("http://localhost/moose");
24 is( $mech->status, 401, "status is 401" );
25 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
26 my %www_auth_params = map {
27 my @key_val = split /=/, $_, 2;
28 $key_val[0] = lc $key_val[0];
29 $key_val[1] =~ s{"}{}g; # remove the quotes
31 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
32 $mech->content_lacks( "foo", "no output" );
35 my $password = 'Circle Of Life';
36 my $realm = $www_auth_params{realm};
37 my $nonce = $www_auth_params{nonce};
38 my $cnonce = '0a4f113b';
39 my $opaque = $www_auth_params{opaque};
44 my $ctx = Digest::MD5->new;
45 $ctx->add( join( ':', $username, $realm, $password ) );
46 my $A1_digest = $ctx->hexdigest;
47 $ctx = Digest::MD5->new;
48 $ctx->add( join( ':', $method, $uri ) );
49 my $A2_digest = $ctx->hexdigest;
50 my $digest = Digest::MD5::md5_hex(
52 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
55 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
57 my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
59 $r->headers->push_header( Authorization => $response );
61 is( $mech->status, 200, "status is 200" );
62 $mech->content_contains( $username, "Mufasa output" );
67 do_test('Mufasa', '/moose?moose_id=1'); # Digest auth includes the full URL path, so need to test query strings