File: session_events.t

package info (click to toggle)
libapache-asp-perl 2.62-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 4,108 kB
  • ctags: 830
  • sloc: perl: 6,033; php: 417; sh: 65; lisp: 22; makefile: 10
file content (104 lines) | stat: -rw-r--r-- 2,681 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/local/bin/perl

use lib qw(. .. t);
use Apache::ASP::CGI;
use T;

use strict;
use File::Basename qw(dirname basename);
#$SIG{__DIE__} = \&Carp::confess;
#$SIG{__WARN__} = \&Carp::cluck;
$SIG{__WARN__} = sub { };

$0 =~ /^(.*)$/;
$0 = $1;
chdir(dirname($0));
$0 = basename($0);

my $t = T->new();

my %config = (
	      'NoState' => 0,
	      'SessionTimeout' => 20,
	      'Debug' => 0,
	      'SessionCount' => 1,
	      'Global' => 'session_events',
	      'SessionQuery' => 1,
	      );

my $r = Apache::ASP::CGI->init($0);
map { $r->dir_config->set($_, $config{$_}) } keys %config;

my $ASP = Apache::ASP->new($r);
$ASP->Session->{MARK} = 1;
#print STDERR "HERE\n";
#sleep 5;
my @sessions = keys %{$ASP->Application};
#&session_count_ok($ASP, scalar(@sessions));

# cleanup old sessions
for my $session_id ( @sessions ) {
    next if ($session_id eq $ASP->Session->SessionID);
    my $Session = $ASP->Application->GetSession($session_id);
    $Session->Abandon;
}
$ASP->{Internal}{CleanupMaster} = undef;
$ASP->CleanupGroups('PURGE');
$ASP->{Internal}{SessionCount}  = 1;

&session_count_ok($ASP, 1);
$ASP->Session->Abandon;
&session_count_ok($ASP, 1);
$ASP->CleanupGroups('PURGE');
&session_count_ok($ASP, 0);
$ASP->DESTROY;

for(1..10) {
    $ASP = Apache::ASP->new($r);
    &session_count_ok($ASP, $_);
    $ASP->DESTROY;
}

$ASP = Apache::ASP->new($r);
&session_count_ok($ASP, 11);
$ASP->Session->Abandon;
$ASP->CleanupGroups('PURGE');
&session_count_ok($ASP, 10);
$ASP->DESTROY;

# Session_OnEnd test repeat on expired session
{
    my $abandon_session_id;
    $ASP = Apache::ASP->new($r);
    $ASP->Session->{WriteMark}++;
    $ASP->Session->Abandon();
    $abandon_session_id = $ASP->Session->SessionID;
#    print STDERR $ASP->Session->SessionID."\n";
    # do not PURGE cleanup here, let next script get initialized with old session id
    $ASP->DESTROY;

    local $ENV{QUERY_STRING} = 'session-id='.$abandon_session_id;
    $ASP = Apache::ASP->new($r);
    $t->eok($abandon_session_id ne $ASP->Session->SessionID, "abandoned session restored");
    $ASP->Session->Abandon();
#    print STDERR $ASP->Session->SessionID."\n";
    $ASP->CleanupGroups('PURGE');
    $ASP->DESTROY;

    $ASP = Apache::ASP->new($r);
    $t->eok($abandon_session_id ne $ASP->Session->SessionID, "abandoned session restored");
    $ASP->Session->Abandon();
#    print STDERR $ASP->Session->SessionID."\n";
    $ASP->CleanupGroups('PURGE');
    $ASP->DESTROY;
}

$t->done;

## helpers

sub session_count_ok {
    my($ASP, $count) = @_;
    $t->eok($ASP->Application->SessionCount == $count, 
	    "$count sessions should have been counted, found ".$ASP->Application->SessionCount);
}