9 eval { require Test::WWW::Mechanize::Catalyst }
11 "Test::WWW::Mechanize::Catalyst is needed for this test";
12 eval { require Catalyst::Plugin::Cache::FileCache }
14 "Catalyst::Plugin::Cache::FileCache is needed for this test";
25 Authentication::Store::Minimal
26 Authentication::Credential::HTTP
35 my ( $self, $c ) = @_;
37 $c->authorization_required( realm => 'testrealm@host.com' );
39 $c->res->body( $c->user->id );
41 __PACKAGE__->config->{authentication}{http}{type} = 'digest';
42 __PACKAGE__->config->{authentication}{users} = $users = {
43 Mufasa => { password => "Circle Of Life", },
49 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
51 my $mech = Test::WWW::Mechanize::Catalyst->new;
53 $mech->get("http://localhost/moose");
54 is( $mech->status, 401, "status is 401" );
56 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
57 my %www_auth_params = map {
59 my @key_val = split /=/, $_, 2;
61 $key_val[0] = lc $key_val[0];
63 $key_val[1] =~ s{"}{}g; # remove the quotes
67 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
69 $mech->content_lacks( "foo", "no output" );
73 my $username = 'Mufasa';
75 my $password = 'Circle Of Life';
77 my $realm = $www_auth_params{realm};
79 my $nonce = $www_auth_params{nonce};
81 my $cnonce = '0a4f113b';
83 my $opaque = $www_auth_params{opaque};
93 my $ctx = Digest::MD5->new;
95 $ctx->add( join( ':', $username, $realm, $password ) );
97 my $A1_digest = $ctx->hexdigest;
99 $ctx = Digest::MD5->new;
101 $ctx->add( join( ':', $method, $uri ) );
103 my $A2_digest = $ctx->hexdigest;
105 my $digest = Digest::MD5::md5_hex(
109 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
114 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
117 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
120 $r->headers->push_header( Authorization => $response );
123 is( $mech->status, 200, "status is 200" );
124 $mech->content_contains( "Mufasa", "Mufasa output" );