[Catalyst-commits] r10802 - in trunk/Catalyst-Plugin-RequireSSL: . lib/Catalyst/Plugin t t/lib/TestApp/C

norbi at dev.catalyst.perl.org norbi at dev.catalyst.perl.org
Mon Jul 6 21:45:41 GMT 2009


Author: norbi
Date: 2009-07-06 21:45:40 +0000 (Mon, 06 Jul 2009)
New Revision: 10802

Modified:
   trunk/Catalyst-Plugin-RequireSSL/
   trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm
   trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t
   trunk/Catalyst-Plugin-RequireSSL/t/lib/TestApp/C/SSL.pm
Log:
 r10825 at vger:  mendel | 2009-07-06 23:45:33 +0200
 Implemented $c->allow_ssl.



Property changes on: trunk/Catalyst-Plugin-RequireSSL
___________________________________________________________________
Name: svk:merge
   + cf8fe1c1-d5c0-41b4-84a9-31cb5e8e0cbe:/local/catalyst/Catalyst-Plugin-RequireSSL:10825

Modified: trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm	2009-07-05 22:51:39 UTC (rev 10801)
+++ trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm	2009-07-06 21:45:40 UTC (rev 10802)
@@ -6,7 +6,7 @@
 
 our $VERSION = '0.07';
 
-__PACKAGE__->mk_accessors( qw/_require_ssl _ssl_strip_output/ );
+__PACKAGE__->mk_accessors( qw/_require_ssl _allow_ssl _ssl_strip_output/ );
 
 sub require_ssl {
     my $c = shift;
@@ -25,6 +25,12 @@
     }
 }
 
+sub allow_ssl {
+    my $c = shift;
+
+    $c->_allow_ssl(1);
+}
+
 sub finalize {
     my $c = shift;
     
@@ -44,7 +50,7 @@
         # we're already required to be in SSL for this request
         last REDIRECT if $c->_require_ssl;
         # or the user doesn't want us to redirect
-        last REDIRECT if $c->config->{require_ssl}->{remain_in_ssl};
+        last REDIRECT if $c->config->{require_ssl}->{remain_in_ssl} || $c->_allow_ssl;
         
         $c->res->redirect( $c->_redirect_uri('http') );
     }
@@ -187,6 +193,16 @@
 The browser will be redirected to the same path on your SSL server.  POST
 requests are never redirected.
 
+=head2 allow_ssl
+
+Call allow_ssl in any controller method you wish to access both in SSL and
+non-SSL mode.
+
+    $c->allow_ssl;
+
+The browser will not be redirected, independently of whether the request was
+made to the SSL or non-SSL server.
+
 =head2 setup
 
 Disables this plugin if running under an engine which does not support SSL.

Modified: trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t	2009-07-05 22:51:39 UTC (rev 10801)
+++ trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t	2009-07-06 21:45:40 UTC (rev 10802)
@@ -6,7 +6,7 @@
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 15;
+use Test::More tests => 19;
 use Catalyst::Test 'TestApp';
 use HTTP::Request::Common;
 
@@ -20,6 +20,10 @@
 ok( $res = request('http://localhost/ssl/secured?a=2&a=1&b=3&c=4'), 'request ok' );
 is( $res->header('location'), 'https://localhost/ssl/secured?a=1&a=2&b=3&c=4', 'redirect with params ok' );
 
+# test that it does not redirect for actions where SSL mode is optional
+ok( my $res = request('http://localhost/ssl/maybe_secured'), 'request ok' );
+is( $res->code, 200, 'no redirect for optional SSL action' );
+
 # test that it doesn't redirect on POST
 my $request = POST( 'http://localhost/ssl/secured', 
     'Content'      => '',
@@ -45,5 +49,9 @@
     # test redirection params
     ok( $res = request('https://localhost/ssl/unsecured?a=2&a=1&b=3&c=4'), 'request ok' );
     is( $res->header('location'), 'http://localhost/ssl/unsecured?a=1&a=2&b=3&c=4', 'redirect with params ok' );
+
+    # test that it does not redirect for actions where SSL mode is optional
+    ok( $res = request('https://localhost/ssl/maybe_secured'), 'request ok' );
+    is( $res->code, 200, 'no redirect for optional SSL action' );
 }
 

Modified: trunk/Catalyst-Plugin-RequireSSL/t/lib/TestApp/C/SSL.pm
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/t/lib/TestApp/C/SSL.pm	2009-07-05 22:51:39 UTC (rev 10801)
+++ trunk/Catalyst-Plugin-RequireSSL/t/lib/TestApp/C/SSL.pm	2009-07-06 21:45:40 UTC (rev 10802)
@@ -17,4 +17,12 @@
     $c->res->output( 'Unsecured' );
 }
 
+sub maybe_secured : Local {
+    my ( $self, $c ) = @_;
+    
+    $c->allow_ssl;
+    
+    $c->res->output( 'Maybe secured' );
+}
+
 1;




More information about the Catalyst-commits mailing list