add some tests to t/cat_test.t
[catagits/Catalyst-Plugin-Session.git] / t / live_verify_address.t
CommitLineData
2a1463db 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
2a1463db 7BEGIN {
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
22use lib "t/lib";
83a3f0e9 23use Test::WWW::Mechanize::PSGI;
24use SessionTestApp;
25my $ua = Test::WWW::Mechanize::PSGI->new(
26 app => SessionTestApp->psgi_app(@_),
27 cookie_jar => {}
28);
2a1463db 29
30# Test without delete __address
31local $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
32f97098 40# Change Client
83a3f0e9 41#local $ENV{REMOTE_ADDR} = "192.168.1.2";
42use Plack::Builder;
43my $app = SessionTestApp->psgi_app(@_);
32f97098 44builder {
83a3f0e9 45 enable 'ForceEnv' => REMOTE_ADDR => "192.168.1.2";
46 $app;
47};
48my $ua2 = Test::WWW::Mechanize::PSGI->new(
49 app => $app,
50 cookie_jar => {}
32f97098 51);
83a3f0e9 52$ua2->get_ok( "http://localhost/get_session_variable/logged");
53$ua2->content_contains('VAR_logged=n.a.');
2a1463db 54
55# Inital Client
56local $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
32f97098 64# Change Client
2a1463db 65local $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