[Catalyst-commits] r10885 - in Catalyst-Authentication-Credential-OpenID: . 0.14 0.14/lib/Catalyst/Authentication/Credential 0.14/t 0.14/t/TestApp/lib 0.14/t/TestApp/lib/TestApp/Controller 0.14/t/TestApp/script

apv at dev.catalyst.perl.org apv at dev.catalyst.perl.org
Wed Jul 15 02:09:08 GMT 2009


Author: apv
Date: 2009-07-15 02:09:07 +0000 (Wed, 15 Jul 2009)
New Revision: 10885

Added:
   Catalyst-Authentication-Credential-OpenID/0.14/
   Catalyst-Authentication-Credential-OpenID/0.14/xt/
Modified:
   Catalyst-Authentication-Credential-OpenID/0.14/Changes
   Catalyst-Authentication-Credential-OpenID/0.14/lib/Catalyst/Authentication/Credential/OpenID.pm
   Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp.pm
   Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp/Controller/Root.pm
   Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/script/testapp_server.pl
   Catalyst-Authentication-Credential-OpenID/0.14/t/live_app.t
Log:
Trying to untangle a mess. Live tests fail in the test but run fine when done manually in the browser.

Copied: Catalyst-Authentication-Credential-OpenID/0.14 (from rev 8688, Catalyst-Authentication-Credential-OpenID/0.13)

Modified: Catalyst-Authentication-Credential-OpenID/0.14/Changes
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/Changes	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/Changes	2009-07-15 02:09:07 UTC (rev 10885)
@@ -1,5 +1,9 @@
 Revision history for Catalyst::Authentication::Credential::OpenID
 
+0.14  Mon Dec  8 20:01:53 PST 2008
+      - Added a test case to see if bad openid URIs cause failure.
+      - Added a test case to see if "tarpit" URIs cause failure.
+
 0.13  Mon Dec  1 19:42:31 PST 2008
       - s/Meno/Menno/ and version fix in the Pod are the only changes. Sigh.
 

Modified: Catalyst-Authentication-Credential-OpenID/0.14/lib/Catalyst/Authentication/Credential/OpenID.pm
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/lib/Catalyst/Authentication/Credential/OpenID.pm	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/lib/Catalyst/Authentication/Credential/OpenID.pm	2009-07-15 02:09:07 UTC (rev 10885)
@@ -1,13 +1,13 @@
 package Catalyst::Authentication::Credential::OpenID;
 use strict;
-# use warnings; no warnings "uninitialized"; # for testing, not production
+use warnings; no warnings "uninitialized"; # for testing, not production 321
 use parent "Class::Accessor::Fast";
 
 BEGIN {
     __PACKAGE__->mk_accessors(qw/ _config realm debug secret /);
 }
 
-our $VERSION = "0.13";
+our $VERSION = "0.14";
 
 use Net::OpenID::Consumer;
 use Catalyst::Exception ();
@@ -49,13 +49,13 @@
     my ( $self, $c, $realm, $authinfo ) = @_;
 
     $c->log->debug("authenticate() called from " . $c->request->uri) if $self->debug;
-
+return 1;
     my $field = $self->{_config}->{openid_field};
 
     my $claimed_uri = $authinfo->{ $field };
 
     # Its security related so we want to be explicit about GET/POST param retrieval.
-    $claimed_uri ||= $c->req->method eq 'GET' ? 
+    $claimed_uri ||= $c->req->method eq 'GET' ?
         $c->req->query_params->{ $field } : $c->req->body_params->{ $field };
 
     my $csr = Net::OpenID::Consumer->new(
@@ -75,10 +75,10 @@
             if $self->_config->{extension_args};
 
         my $check_url = $identity->check_url(
-            return_to  => $current . '?openid-check=1',
-            trust_root => $current,
-            delayed_return => 1,
-        );
+                                             return_to  => $current . '?openid-check=1',
+                                             trust_root => $current,
+                                             delayed_return => 1,
+                                            );
         $c->res->redirect($check_url);
         $c->detach();
     }
@@ -87,7 +87,7 @@
         if ( my $setup_url = $csr->user_setup_url )
         {
             $c->res->redirect($setup_url);
-            return;
+            $c->detach();
         }
         elsif ( $csr->user_cancel )
         {
@@ -97,8 +97,8 @@
         {
             # This is where we ought to build an OpenID user and verify against the spec.
             my $user = +{ map { $_ => scalar $identity->$_ }
-                qw( url display rss atom foaf declared_rss declared_atom declared_foaf foafmaker ) };
-            
+                          qw( url display rss atom foaf declared_rss declared_atom declared_foaf foafmaker ) };
+
             for(keys %{$self->{_config}->{extensions}}) {
                 $user->{extensions}->{$_} = $identity->signed_extension_fields($_);
             }
@@ -134,7 +134,7 @@
 
 =head1 VERSION
 
-0.13
+0.14
 
 =head1 SYNOPSIS
 

Modified: Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/t/TestApp/lib/TestApp/Controller/Root.pm	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp/Controller/Root.pm	2009-07-15 02:09:07 UTC (rev 10885)
@@ -133,11 +133,26 @@
                        );
 }
 
-sub end : Private {
+sub not_a_valid_openid_uri : Global {
     my ( $self, $c ) = @_;
+    $c->response->body("OPENID. UR DOIN IT RONG.");
+}
+
+sub i_can_has_tarpit : Global {
+    my ( $self, $c ) = @_;
+    local $/ = 1;
     $c->response->content_type("text/html");
+    # Expect an arbitrary, biggish amount of content; it's a lie.
+    $c->response->headers->header("Content-length" => 1_024 * 100);
+    # Do this for 30 seconds; tests will timeout at 10 or 15.
+    sleep 1 && $c->response->write("sucker\n") for 1 .. 30;
 }
 
+sub end : Private {
+    my ( $self, $c ) = @_;
+    $c->response->content_type("text/html") unless $c->response->content_type;
+}
+
 =head1 LICENSE
 
 This library is free software, you can redistribute it and modify

Modified: Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp.pm
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/t/TestApp/lib/TestApp.pm	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/lib/TestApp.pm	2009-07-15 02:09:07 UTC (rev 10885)
@@ -69,6 +69,9 @@
 
 __PACKAGE__->setup();
 
+use YAML; die YAML::Dump \%INC;
+
+
 1;
 
 __END__

Modified: Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/script/testapp_server.pl
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/t/TestApp/script/testapp_server.pl	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/t/TestApp/script/testapp_server.pl	2009-07-15 02:09:07 UTC (rev 10885)
@@ -1,10 +1,10 @@
-#!/usr/local/bin/perl -w
+#!/usr/bin/env perl
 
-BEGIN { 
+BEGIN {
     $ENV{CATALYST_ENGINE} ||= 'HTTP';
-    $ENV{CATALYST_SCRIPT_GEN} = 31;
+    $ENV{CATALYST_SCRIPT_GEN} = 39;
     require Catalyst::Engine::HTTP;
-}  
+}
 
 use strict;
 use warnings;
@@ -20,51 +20,93 @@
 my $port              = $ENV{TESTAPP_PORT} || $ENV{CATALYST_PORT} || 3000;
 my $keepalive         = 0;
 my $restart           = $ENV{TESTAPP_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
-my $restart_delay     = 1;
-my $restart_regex     = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$';
-my $restart_directory = undef;
-my $follow_symlinks   = 0;
+my $background        = 0;
+my $pidfile           = undef;
 
+my $check_interval;
+my $file_regex;
+my $watch_directory;
+my $follow_symlinks;
+
 my @argv = @ARGV;
 
 GetOptions(
     'debug|d'             => \$debug,
-    'fork'                => \$fork,
+    'fork|f'              => \$fork,
     'help|?'              => \$help,
     'host=s'              => \$host,
-    'port=s'              => \$port,
+    'port|p=s'            => \$port,
     'keepalive|k'         => \$keepalive,
     'restart|r'           => \$restart,
-    'restartdelay|rd=s'   => \$restart_delay,
-    'restartregex|rr=s'   => \$restart_regex,
-    'restartdirectory=s@' => \$restart_directory,
+    'restartdelay|rd=s'   => \$check_interval,
+    'restartregex|rr=s'   => \$file_regex,
+    'restartdirectory=s@' => \$watch_directory,
     'followsymlinks'      => \$follow_symlinks,
+    'background'          => \$background,
+    'pidfile=s'           => \$pidfile,
 );
 
 pod2usage(1) if $help;
 
-if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) {
-    $ENV{CATALYST_ENGINE} = 'HTTP::Restarter';
-}
 if ( $debug ) {
     $ENV{CATALYST_DEBUG} = 1;
 }
 
-# This is require instead of use so that the above environment
-# variables can be set at runtime.
-require TestApp;
+# If we load this here, then in the case of a restarter, it does not
+# need to be reloaded for each restart.
+require Catalyst;
 
-TestApp->run( $port, $host, {
-    argv              => \@argv,
-    'fork'            => $fork,
-    keepalive         => $keepalive,
-    restart           => $restart,
-    restart_delay     => $restart_delay,
-    restart_regex     => qr/$restart_regex/,
-    restart_directory => $restart_directory,
-    follow_symlinks   => $follow_symlinks,
-} );
+# If this isn't done, then the Catalyst::Devel tests for the restarter
+# fail.
+$| = 1 if $ENV{HARNESS_ACTIVE};
 
+my $runner = sub {
+    # This is require instead of use so that the above environment
+    # variables can be set at runtime.
+    require TestApp;
+
+    TestApp->run(
+        $port, $host,
+        {
+            argv       => \@argv,
+            'fork'     => $fork,
+            keepalive  => $keepalive,
+            background => $background,
+            pidfile    => $pidfile,
+        }
+    );
+};
+
+if ( $restart ) {
+    die "Cannot run in the background and also watch for changed files.\n"
+        if $background;
+
+    require Catalyst::Restarter;
+
+    my $subclass = Catalyst::Restarter->pick_subclass;
+
+    my %args;
+    $args{follow_symlinks} = 1
+        if $follow_symlinks;
+    $args{directories} = $watch_directory
+        if defined $watch_directory;
+    $args{sleep_interval} = $check_interval
+        if defined $check_interval;
+    $args{filter} = qr/$file_regex/
+        if defined $file_regex;
+
+    my $restarter = $subclass->new(
+        %args,
+        start_sub => $runner,
+        argv      => \@argv,
+    );
+
+    $restarter->run_and_watch;
+}
+else {
+    $runner->();
+}
+
 1;
 
 =head1 NAME
@@ -86,6 +128,7 @@
    -r -restart        restart when files get modified
                       (defaults to false)
    -rd -restartdelay  delay between file checks
+                      (ignored if you have Linux::Inotify2 installed)
    -rr -restartregex  regex match files that trigger
                       a restart when modified
                       (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
@@ -94,6 +137,9 @@
                       (defaults to '[SCRIPT_DIR]/..')
    -follow_symlinks   follow symlinks in search directories
                       (defaults to false. this is a no-op on Win32)
+   -background        run the process in the background
+   -pidfile           specify filename for pid file
+
  See also:
    perldoc Catalyst::Manual
    perldoc Catalyst::Manual::Intro
@@ -102,14 +148,13 @@
 
 Run a Catalyst Testserver for this application.
 
-=head1 AUTHOR
+=head1 AUTHORS
 
-Sebastian Riedel, C<sri at oook.de>
-Maintained by the Catalyst Core Team.
+Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut

Modified: Catalyst-Authentication-Credential-OpenID/0.14/t/live_app.t
===================================================================
--- Catalyst-Authentication-Credential-OpenID/0.13/t/live_app.t	2008-12-02 03:46:21 UTC (rev 8688)
+++ Catalyst-Authentication-Credential-OpenID/0.14/t/live_app.t	2009-07-15 02:09:07 UTC (rev 10885)
@@ -1,26 +1,24 @@
 #!perl
-
 use strict;
 use warnings;
-
 use FindBin;
 use IO::Socket;
 use Test::More;
 use Test::WWW::Mechanize;
 
 # plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
-eval "use Catalyst::Devel 1.0";
+eval "use Catalyst::Devel";
 plan skip_all => 'Catalyst::Devel required' if $@;
 
-plan tests => 17;
+plan tests => 20;
 
 # How long to wait for test server to start and timeout for UA.
 my $seconds = 30;
 
 # Spawn the standalone HTTP server.
-my $port = 30000 + int rand(1 + 10000);
+my $port = 3000 + int rand(1 + 1000);
 
- my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -fork -port $port |";
+ my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -p $port |";
 
 # my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port 2>&1 |";
 
@@ -45,13 +43,13 @@
     close $server;
     die "Could not run test: $@\n$pipe";
 }
-    
+
 my $root = $ENV{CATALYST_SERVER} = "http://localhost:$port";
 
 # Tests start --------------------------------------------
 ok("Started");
+eval {
 
-
 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
 
 $mech->get_ok($root, "GET $root");
@@ -69,17 +67,15 @@
                       "Trying cleartext login, 'memebers' realm");
 
 $mech->content_contains("signed in", "Signed in successfully");
-
 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
-
 $mech->content_contains("Sign in with OpenID", "Content looks right");
 
 my $claimed_uri = "$root/provider/paco";
 
 $mech->submit_form_ok({ form_name => "openid",
                         fields => { openid_identifier => $claimed_uri,
-                                },
-                    },
+                                  },
+                      },
                       "Trying OpenID login, 'openid' realm");
 
 $mech->content_contains("You did it with OpenID!",
@@ -88,14 +84,20 @@
 $mech->get_ok($root, "GET $root");
 
 $mech->content_contains("provider/paco", "OpenID signed in");
-#$mech->content_contains("paco", "OpenID signed in as paco");
 
-# can't be verified
+# Bad claimed URL.
+$mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
+my $non_openid_uri = "$root/not_a_valid_openid_uri";
+$mech->submit_form_ok({ form_name => "openid",
+                        fields => { openid_identifier => $non_openid_uri,
+                                  },
+                      },
+                      "FAIL");
 
+# Can't be verified.
 $mech->get_ok("$root/logout", "GET $root/logout");
-
+$mech->content_contains("You are not signed in", "Content looks right");
 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
-
 $mech->content_contains("Sign in with OpenID", "Content looks right");
 
 $mech->submit_form_ok({ form_name => "openid",
@@ -105,10 +107,15 @@
                       "Trying OpenID login, 'openid' realm");
 
 $mech->content_contains("can't be verified",
-                        "Proper failure for unauthenticated memember.");
+                        "Proper failure for unauthenticated memember.")
+    or diag($mech->content);
 
+
+};
 # Tests end ----------------------------------------------
 
+<>;
+
 # shut it down
 kill 'INT', $pid;
 close $server;




More information about the Catalyst-commits mailing list