7 'Test::WWW::Mechanize::Catalyst' => '0.51',
8 'Catalyst::Plugin::Cache' => '0',
9 'Cache::FileCache' => undef,
17 use Test::WWW::Mechanize::Catalyst;
20 my ($username, $uri, $emulate_dotnet, $fail) = @_;
21 my $app = $fail ? 'AuthDigestTestApp' : 'AuthDigestDotnetTestApp';
22 my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => $app);
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};
45 if ($emulate_dotnet) {
46 $auth_uri =~ s/\?.*//;
48 my $ctx = Digest::MD5->new;
49 $ctx->add( join( ':', $username, $realm, $password ) );
50 my $A1_digest = $ctx->hexdigest;
51 $ctx = Digest::MD5->new;
52 $ctx->add( join( ':', $method, $auth_uri ) );
53 my $A2_digest = $ctx->hexdigest;
54 my $digest = Digest::MD5::md5_hex(
56 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
59 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$auth_uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
61 my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
63 $r->headers->push_header( Authorization => $response );
66 is( $mech->status, 400, "status is 400" );
68 is( $mech->status, 200, "status is 200" );
69 $mech->content_contains( $username, "Mufasa output" );
75 # Test with query string
76 do_test('Mufasa2', '/moose?moose_id=1');
77 # Test with query string, emulating .NET, which omits the query string
78 # from the Authorization header
79 do_test('Mufasa2', '/moose?moose_id=1', 1);
81 # Test with query string, emulating .NET, against app without .NET setting;
82 # authorization should fail
83 do_test('Mufasa2', '/moose?moose_id=1', 1, 1);