HTTP auth live app test
Yuval Kogman [Mon, 5 Dec 2005 08:29:48 +0000 (08:29 +0000)]
lib/Catalyst/Plugin/Authentication/Credential/HTTP.pm
t/live_app.t [new file with mode: 0644]

index 75fee7a..2efb00f 100644 (file)
@@ -33,7 +33,7 @@ sub authorization_required {
 
     $c->authorization_required_response( %opts );
 
-    $c->detach( sub { } );
+    die $Catalyst::DETACH;
 }
 
 sub authorization_required_response {
diff --git a/t/live_app.t b/t/live_app.t
new file mode 100644 (file)
index 0000000..d95e197
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use HTTP::Request;
+
+{
+       package AuthTestApp;
+       use Catalyst qw/
+               Authentication
+               Authentication::Store::Minimal
+               Authentication::Credential::HTTP
+       /;
+
+       use Test::More;
+       use Test::Exception;
+
+       use Digest::MD5 qw/md5/;
+
+       our $users;
+
+       sub moose : Local {
+               my ( $self, $c ) = @_;
+
+        $c->authorization_required;
+
+        $c->res->body("foo");
+       }
+
+       __PACKAGE__->config->{authentication}{users} = $users = {
+               foo => {
+                       password => "s3cr3t",
+               },
+               bar => {
+                       crypted_password => crypt("s3cr3t", "x8"),
+               },
+               gorch => {
+                       hashed_password => md5("s3cr3t"),
+                       hash_algorithm => "MD5",
+               },
+               baz => {},
+       };
+
+       __PACKAGE__->setup;
+}
+
+use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
+
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+
+$mech->get("http://localhost/moose");
+is( $mech->status, 401, "status is 401");
+
+$mech->content_lacks("foo", "no output");
+
+my $r = HTTP::Request->new( GET => "http://localhost/moose" );
+$r->authorization_basic(qw/foo s3cr3t/);
+
+$mech->request( $r );
+is( $mech->status, 200, "status is 200");
+$mech->content_contains("foo", "foo output");
+
+