Make mech tests skip unless mech new enough. RT#55303
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app_digest.t
index 32afff6..2755f3c 100644 (file)
@@ -1,9 +1,15 @@
 #!/usr/bin/perl
 use strict;
 use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/lib";
 use Test::More;
 BEGIN {
-    eval { require Test::WWW::Mechanize::Catalyst }
+    do {
+        eval { require Test::WWW::Mechanize::Catalyst }
+        and
+        Test::WWW::Mechanize::Catalyst->VERSION('0.51')
+    }
       or plan skip_all =>
       "Test::WWW::Mechanize::Catalyst is needed for this test";
     eval { require Catalyst::Plugin::Cache }
@@ -12,56 +18,16 @@ BEGIN {
     eval { require Cache::FileCache }
       or plan skip_all =>
       "Cache::FileCache is needed for this test";
-    plan tests => 8;
+    plan tests => 12;
 }
 use Digest::MD5;
 use HTTP::Request;
-{
-    package AuthTestApp;
-    use Catalyst qw/
-      Authentication
-      Cache
-      /;
-    use Test::More;
-    our %users;
-    sub moose : Local {
-        my ( $self, $c ) = @_;
-        #$c->authenticate( { realm => 'testrealm@host.com' } );
-        $c->authenticate();
-        $c->res->body( $c->user->id );
-    }
-    my $digest_pass = Digest::MD5->new;
-    $digest_pass->add('Mufasa2:testrealm@host.com:Circle Of Life');
-    %users = ( 
-        Mufasa  => { pass         => "Circle Of Life",          }, 
-        Mufasa2 => { pass         => $digest_pass->hexdigest, },
-    );
-    __PACKAGE__->config->{cache}{backend} = {
-        class => 'Cache::FileCache',
-    };
-    __PACKAGE__->config( authentication => {
-        default_realm => 'testrealm@host.com',
-        realms => {
-            'testrealm@host.com' => {
-                store => {
-                    class => 'Minimal',
-                    users => \%users,
-                },
-                credential => {
-                    class => 'HTTP',
-                    type  => 'digest',
-                    password_type => 'clear', 
-                    password_field => 'pass'
-                },
-            },
-        },
-    });
-    __PACKAGE__->setup;
-}
-use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
+use Test::More;
+use Test::WWW::Mechanize::Catalyst qw/AuthDigestTestApp/;
 
 sub do_test {
     my $username = shift;
+    my $uri = shift;
     my $mech = Test::WWW::Mechanize::Catalyst->new;
     $mech->get("http://localhost/moose");
     is( $mech->status, 401, "status is 401" );
@@ -83,7 +49,7 @@ sub do_test {
         my $nc       = '00000001';
         my $method   = 'GET';
         my $qop      = 'auth';
-        my $uri      = '/moose';
+        $uri         ||= '/moose';
         my $ctx = Digest::MD5->new;
         $ctx->add( join( ':', $username, $realm, $password ) );
         my $A1_digest = $ctx->hexdigest;
@@ -97,7 +63,7 @@ sub do_test {
 
         $response = qq{Digest username="$username", realm="$realm", nonce="$nonce", uri="$uri", qop=$qop, nc=$nc, cnonce="$cnonce", response="$digest", opaque="$opaque"};
     }
-    my $r = HTTP::Request->new( GET => "http://localhost/moose" );
+    my $r = HTTP::Request->new( GET => "http://localhost" . $uri );
     $mech->request($r);
     $r->headers->push_header( Authorization => $response );
     $mech->request($r);
@@ -106,4 +72,5 @@ sub do_test {
 }
 
 do_test('Mufasa');
-do_test('Mufasa2');
\ No newline at end of file
+do_test('Mufasa2');
+do_test('Mufasa', '/moose?moose_id=1'); # Digest auth includes the full URL path, so need to test query strings