6 eval { require Test::WWW::Mechanize::Catalyst }
8 "Test::WWW::Mechanize::Catalyst is needed for this test";
9 eval { require Catalyst::Plugin::Cache::FileCache }
11 "Catalyst::Plugin::Cache::FileCache is needed for this test";
19 Authentication::Store::Minimal
20 Authentication::Credential::HTTP
26 my ( $self, $c ) = @_;
27 $c->authorization_required( realm => 'testrealm@host.com' );
28 $c->res->body( $c->user->id );
30 __PACKAGE__->config->{authentication}{http}{type} = 'digest';
31 __PACKAGE__->config->{authentication}{users} = $users = {
32 Mufasa => { password => "Circle Of Life", },
36 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
37 my $mech = Test::WWW::Mechanize::Catalyst->new;
38 $mech->get("http://localhost/moose");
39 is( $mech->status, 401, "status is 401" );
40 my $www_auth = $mech->res->headers->header('WWW-Authenticate');
41 my %www_auth_params = map {
42 my @key_val = split /=/, $_, 2;
43 $key_val[0] = lc $key_val[0];
44 $key_val[1] =~ s{"}{}g; # remove the quotes
46 } split /, /, substr( $www_auth, 7 ); #7 == length "Digest "
47 $mech->content_lacks( "foo", "no output" );
50 my $username = 'Mufasa';
51 my $password = 'Circle Of Life';
52 my $realm = $www_auth_params{realm};
53 my $nonce = $www_auth_params{nonce};
54 my $cnonce = '0a4f113b';
55 my $opaque = $www_auth_params{opaque};
60 my $ctx = Digest::MD5->new;
61 $ctx->add( join( ':', $username, $realm, $password ) );
62 my $A1_digest = $ctx->hexdigest;
63 $ctx = Digest::MD5->new;
64 $ctx->add( join( ':', $method, $uri ) );
65 my $A2_digest = $ctx->hexdigest;
66 my $digest = Digest::MD5::md5_hex(
68 $A1_digest, $nonce, $qop ? ( $nc, $cnonce, $qop ) : (), $A2_digest )
71 $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
73 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
75 $r->headers->push_header( Authorization => $response );
77 is( $mech->status, 200, "status is 200" );
78 $mech->content_contains( "Mufasa", "Mufasa output" );