7 'Test::WWW::Mechanize::Catalyst' => '0.51',
8 'Catalyst::Plugin::Cache' => '0',
9 'Cache::FileCache' => undef,
18 my ($username, $uri, $emulate_dotnet, $fail) = @_;
19 my $app = $fail ? 'AuthDigestTestApp' : 'AuthDigestDotnetTestApp';
20 my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => $app);
21 $mech->get("http://localhost/moose");
22 is( $mech->status, 401, "status is 401" );
23 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
24 my %www_auth_params = map {
25 my @key_val = split /=/, $_, 2;
26 $key_val[0] = lc $key_val[0];
27 $key_val[1] =~ s{"}{}g; # remove the quotes
29 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
30 $mech->content_lacks( "foo", "no output" );
33 my $password = 'Circle Of Life';
34 my $realm = $www_auth_params{realm};
35 my $nonce = $www_auth_params{nonce};
36 my $cnonce = '0a4f113b';
37 my $opaque = $www_auth_params{opaque};
43 if ($emulate_dotnet) {
44 $auth_uri =~ s/\?.*//;
46 my $ctx = Digest::MD5->new;
47 $ctx->add( join( ':', $username, $realm, $password ) );
48 my $A1_digest = $ctx->hexdigest;
49 $ctx = Digest::MD5->new;
50 $ctx->add( join( ':', $method, $auth_uri ) );
51 my $A2_digest = $ctx->hexdigest;
52 my $digest = Digest::MD5::md5_hex(
54 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
57 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$auth_uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
59 my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
61 $r->headers->push_header( Authorization => $response );
64 is( $mech->status, 400, "status is 400" );
66 is( $mech->status, 200, "status is 200" );
67 $mech->content_contains( $username, "Mufasa output" );
73 # Test with query string
74 do_test('Mufasa2', '/moose?moose_id=1');
75 # Test with query string, emulating .NET, which omits the query string
76 # from the Authorization header
77 do_test('Mufasa2', '/moose?moose_id=1', 1);
79 # Test with query string, emulating .NET, against app without .NET setting;
80 # authorization should fail
81 do_test('Mufasa2', '/moose?moose_id=1', 1, 1);