From: Jens Gassmann Date: Wed, 8 Jun 2011 11:43:18 +0000 (+0000) Subject: Test for verify address and fix reset __address X-Git-Tag: v0.32~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a1463db58f97ac9bb1a7e99c314877c3fa54712;p=catagits%2FCatalyst-Plugin-Session.git Test for verify address and fix reset __address --- diff --git a/lib/Catalyst/Plugin/Session.pm b/lib/Catalyst/Plugin/Session.pm index c13297c..db19dc6 100644 --- a/lib/Catalyst/Plugin/Session.pm +++ b/lib/Catalyst/Plugin/Session.pm @@ -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( diff --git a/t/lib/SessionTestApp.pm b/t/lib/SessionTestApp.pm index fc9d60b..9f211e7 100644 --- a/t/lib/SessionTestApp.pm +++ b/t/lib/SessionTestApp.pm @@ -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; diff --git a/t/lib/SessionTestApp/Controller/Root.pm b/t/lib/SessionTestApp/Controller/Root.pm index ff80dd6..34070b9 100644 --- a/t/lib/SessionTestApp/Controller/Root.pm +++ b/t/lib/SessionTestApp/Controller/Root.pm @@ -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 index 0000000..7b04db6 --- /dev/null +++ b/t/live_verify_address.t @@ -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'); + + +