Commit | Line | Data |
2a1463db |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
2a1463db |
7 | BEGIN { |
8 | eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) } |
9 | or plan skip_all => |
10 | "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test"; |
11 | |
12 | eval { |
83a3f0e9 |
13 | require Test::WWW::Mechanize::PSGI; |
14 | #Test::WWW::Mechanize::Catalyst->VERSION(0.51); |
2a1463db |
15 | } |
16 | or plan skip_all => |
83a3f0e9 |
17 | 'Test::WWW::Mechanize::PSGI is required for this test'; |
2a1463db |
18 | |
19 | plan tests => 12; |
20 | } |
21 | |
22 | use lib "t/lib"; |
83a3f0e9 |
23 | use Test::WWW::Mechanize::PSGI; |
24 | use SessionTestApp; |
25 | my $ua = Test::WWW::Mechanize::PSGI->new( |
26 | app => SessionTestApp->psgi_app(@_), |
27 | cookie_jar => {} |
28 | ); |
2a1463db |
29 | |
30 | # Test without delete __address |
31 | local $ENV{REMOTE_ADDR} = "192.168.1.1"; |
32 | |
2a1463db |
33 | $ua->get_ok( "http://localhost/login" ); |
34 | $ua->content_contains('logged in'); |
35 | |
36 | $ua->get_ok( "http://localhost/set_session_variable/logged/in" ); |
37 | $ua->content_contains('session variable set'); |
38 | |
39 | |
40 | # Change Client |
83a3f0e9 |
41 | #local $ENV{REMOTE_ADDR} = "192.168.1.2"; |
42 | use Plack::Builder; |
43 | my $app = SessionTestApp->psgi_app(@_); |
44 | builder { |
45 | enable 'ForceEnv' => REMOTE_ADDR => "192.168.1.2"; |
46 | $app; |
47 | }; |
48 | my $ua2 = Test::WWW::Mechanize::PSGI->new( |
49 | app => $app, |
50 | cookie_jar => {} |
51 | ); |
52 | $ua2->get_ok( "http://localhost/get_session_variable/logged"); |
53 | $ua2->content_contains('VAR_logged=n.a.'); |
2a1463db |
54 | |
55 | # Inital Client |
56 | local $ENV{REMOTE_ADDR} = "192.168.1.1"; |
57 | |
58 | $ua->get_ok( "http://localhost/login_without_address" ); |
59 | $ua->content_contains('logged in (without address)'); |
60 | |
61 | $ua->get_ok( "http://localhost/set_session_variable/logged/in" ); |
62 | $ua->content_contains('session variable set'); |
63 | |
64 | # Change Client |
65 | local $ENV{REMOTE_ADDR} = "192.168.1.2"; |
66 | |
67 | $ua->get_ok( "http://localhost/get_session_variable/logged" ); |
68 | $ua->content_contains('VAR_logged=in'); |
69 | |
70 | |
71 | |