Test for verify address and fix reset __address
Jens Gassmann [Wed, 8 Jun 2011 11:43:18 +0000 (11:43 +0000)]
lib/Catalyst/Plugin/Session.pm
t/lib/SessionTestApp.pm
t/lib/SessionTestApp/Controller/Root.pm
t/live_verify_address.t [new file with mode: 0644]

index c13297c..db19dc6 100644 (file)
@@ -225,6 +225,7 @@ sub _load_session {
 
             no warnings 'uninitialized';    # ne __address
             if (   $c->_session_plugin_config->{verify_address}
+                && exists $session_data->{__address}
                 && $session_data->{__address} ne $c->request->address )
             {
                 $c->log->warn(
index fc9d60b..9f211e7 100644 (file)
@@ -9,6 +9,10 @@ use warnings;
 __PACKAGE__->config('Plugin::Session' => {
     # needed for live_verify_user_agent.t; should be harmless for other tests 
     verify_user_agent => 1,  
+    
+    # need for live_verify_address.t; should be harmless for other tests
+    verify_address => 1,
+
 });
 
 __PACKAGE__->setup;
index ff80dd6..34070b9 100644 (file)
@@ -13,6 +13,14 @@ sub login : Global {
     $c->res->output("logged in");
 }
 
+sub login_without_address : Global {
+    my ( $self, $c ) = @_;
+    $c->session;
+    $c->log->debug($c->request->address);
+    delete $c->session->{__address};
+    $c->res->output("logged in (without address)");
+}
+
 sub logout : Global {
     my ( $self, $c ) = @_;
     $c->res->output(
diff --git a/t/live_verify_address.t b/t/live_verify_address.t
new file mode 100644 (file)
index 0000000..7b04db6
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+    eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
+      or plan skip_all =>
+      "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
+
+    eval {
+        require Test::WWW::Mechanize::Catalyst;
+        Test::WWW::Mechanize::Catalyst->VERSION(0.51);
+    }
+    or plan skip_all =>
+        'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
+
+    plan tests => 12;
+}
+
+use lib "t/lib";
+use Test::WWW::Mechanize::Catalyst "SessionTestApp";
+
+# Test without delete __address
+local $ENV{REMOTE_ADDR} = "192.168.1.1";
+
+my $ua = Test::WWW::Mechanize::Catalyst->new( {} );
+$ua->get_ok( "http://localhost/login" );
+$ua->content_contains('logged in');
+
+$ua->get_ok( "http://localhost/set_session_variable/logged/in" );
+$ua->content_contains('session variable set');
+
+
+# Change Client 
+local $ENV{REMOTE_ADDR} = "192.168.1.2";
+
+$ua->get_ok( "http://localhost/get_session_variable/logged");
+$ua->content_contains('VAR_logged=n.a.');
+
+# Inital Client
+local $ENV{REMOTE_ADDR} = "192.168.1.1";
+
+$ua->get_ok( "http://localhost/login_without_address" );
+$ua->content_contains('logged in (without address)');
+
+$ua->get_ok( "http://localhost/set_session_variable/logged/in" );
+$ua->content_contains('session variable set');
+
+# Change Client 
+local $ENV{REMOTE_ADDR} = "192.168.1.2";
+
+$ua->get_ok( "http://localhost/get_session_variable/logged" );
+$ua->content_contains('VAR_logged=in');
+
+
+