File: 06_expiry.t

package info (click to toggle)
libcgi-application-plugin-session-perl 1.05-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 236 kB
  • ctags: 53
  • sloc: perl: 538; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,289 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use Test::More tests => 16;
use File::Spec;
BEGIN { use_ok('CGI::Application::Plugin::Session') };

use lib './t';
use strict;

$ENV{CGI_APP_RETURN_ONLY} = 1;

use CGI;
use TestAppExpiry;

$ENV{DEFAULT_EXPIRY} = '+1h';
my $t1_obj = TestAppExpiry->new(QUERY=>CGI->new());
my $t1_output = $t1_obj->run();


# Set-Cookie: CGISESSID=d7fc7bab0f9e1301fd21717c556337fe; path=/; expires=Sat, 11-Jun-2005 17:47:28 GMT
like($t1_output, qr/\(3600\)/, 'expiry set correctly');
like($t1_output, qr/Set-Cookie: CGISESSID=[a-zA-Z0-9]+/, 'session cookie set');
like($t1_output, qr/expires=\w{3}, /, 'session cookie expiry set');
my ($year) = $t1_output =~ /\d+\-\w{3}\-(\d+) /s;

my ($id1) = $t1_output =~ /CGISESSID=([a-zA-Z0-9]+)/s;
ok($id1, 'found session id');

undef $t1_obj;

# Set a cookie in $ENV{HTTP_COOKIE}
$ENV{HTTP_COOKIE} = CGI::Session->name.'='.$id1;

# Change the default expiry
$ENV{DEFAULT_EXPIRY} = '+1y';
$t1_obj = TestAppExpiry->new(QUERY=>CGI->new());
$t1_output = $t1_obj->run();


like($t1_output, qr/\(3600\)/, 'expiry set correctly');
like($t1_output, qr/Set-Cookie: CGISESSID=[a-zA-Z0-9]+/, 'session cookie set');
like($t1_output, qr/expires=\w{3}, /, 'session cookie expiry set');
my ($year2) = $t1_output =~ /\d+\-\w{3}\-(\d+) /s;

# This test will fail during the last hour of the year, but I can't be bother to
# test for that :)
is($year2, $year, 'Expiry should not change');

my ($id2) = $t1_output =~ /CGISESSID=([a-zA-Z0-9]+)/s;
ok($id2, 'found session id');
is($id2, $id1, "Session was reused");

undef $t1_obj;

unlink File::Spec->catdir('t', 'cgisess_'.$id1);


delete $ENV{HTTP_COOKIE};
# Change the default expiry
$ENV{DEFAULT_EXPIRY} = '-1y';
$t1_obj = TestAppExpiry->new();
$t1_output = $t1_obj->run();

like($t1_output, qr/\(\-31536000\)/, 'expiry set correctly');
like($t1_output, qr/Set-Cookie: CGISESSID=[a-zA-Z0-9]+/, 'session cookie set');
like($t1_output, qr/expires=\w{3}, /, 'session cookie expiry set');
($year2) = $t1_output =~ /\d+\-\w{3}\-(\d+) /s;

# This test will fail during the last hour of the year, but I can't be bother to
# test for that :)
is($year2, $year-1, 'Expiry should not change');

($id2) = $t1_output =~ /CGISESSID=([a-zA-Z0-9]+)/s;
ok($id2, 'found session id');

undef $t1_obj;

unlink File::Spec->catdir('t', 'cgisess_'.$id2);