fix a session bug where, when using noFuss, user session scratch was not cleaned up
This commit is contained in:
parent
980ff3e972
commit
45eb45fa3e
2 changed files with 59 additions and 10 deletions
|
|
@ -161,7 +161,9 @@ The specific sessionId you want to instantiate.
|
||||||
|
|
||||||
=head3 noFuss
|
=head3 noFuss
|
||||||
|
|
||||||
A boolean, that if true will not update the session, or check if it's expired. This is mainly for WebGUI session maintenance, and shouldn't normally be used by anyone.
|
A boolean, that if true will not update the session, or check if it's
|
||||||
|
expired. This is mainly for WebGUI session maintenance, and shouldn't
|
||||||
|
normally be used by anyone.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
@ -173,19 +175,28 @@ sub new {
|
||||||
my $noFuss = shift;
|
my $noFuss = shift;
|
||||||
if ($sessionId eq "") { ##New session
|
if ($sessionId eq "") { ##New session
|
||||||
$self->start(1);
|
$self->start(1);
|
||||||
} else { ##existing session requested
|
}
|
||||||
$self->{_var} = $session->db->quickHashRef("select * from userSession where sessionId=?",[$sessionId]);
|
else { ##existing session requested
|
||||||
|
$self->{_var} = $session->db->quickHashRef("select * from userSession where sessionId=?",[$sessionId]);
|
||||||
|
##We have to make sure that the session variable has a sessionId, otherwise downstream users of
|
||||||
|
##the object will break
|
||||||
|
if ($noFuss && $self->{_var}{sessionId}) {
|
||||||
|
$self->session->{_sessionId} = $self->{_var}{sessionId};
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
return $self if $noFuss && $self->{_var}{sessionId};
|
return $self if $noFuss && $self->{_var}{sessionId};
|
||||||
if ($self->{_var}{expires} && $self->{_var}{expires} < $session->datetime->time()) { ##Session expired, start a new one with the same Id
|
if ($self->{_var}{expires} && $self->{_var}{expires} < $session->datetime->time()) { ##Session expired, start a new one with the same Id
|
||||||
$self->end;
|
$self->end;
|
||||||
$self->start(1,$sessionId);
|
$self->start(1,$sessionId);
|
||||||
} elsif ($self->{_var}{sessionId} ne "") { ##Fetched an existing session. Update variables with recent data.
|
}
|
||||||
|
elsif ($self->{_var}{sessionId} ne "") { ##Fetched an existing session. Update variables with recent data.
|
||||||
$self->{_var}{lastPageView} = $session->datetime->time();
|
$self->{_var}{lastPageView} = $session->datetime->time();
|
||||||
$self->{_var}{lastIP} = $session->env->getIp;
|
$self->{_var}{lastIP} = $session->env->getIp;
|
||||||
$self->{_var}{expires} = $session->datetime->time() + $session->setting->get("sessionTimeout");
|
$self->{_var}{expires} = $session->datetime->time() + $session->setting->get("sessionTimeout");
|
||||||
$self->session->{_sessionId} = $self->{_var}{sessionId};
|
$self->session->{_sessionId} = $self->{_var}{sessionId};
|
||||||
$session->db->setRow("userSession","sessionId",$self->{_var});
|
$session->db->setRow("userSession","sessionId",$self->{_var});
|
||||||
} else { ##Start a new default session with the requested, non-existant id.
|
}
|
||||||
|
else { ##Start a new default session with the requested, non-existant id.
|
||||||
$self->start(1,$sessionId);
|
$self->start(1,$sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,53 @@ use WebGUI::Workflow::Activity::DeleteExpiredSessions;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
plan tests => 1; # increment this value for each test you create
|
plan tests => 4; # increment this value for each test you create
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
TODO: {
|
my $origSessionTimeout = $session->setting->get('sessionTimeout');
|
||||||
local $TODO = "Tests that need to be written";
|
|
||||||
ok(0, 'Test allowPrivateMessages=friends, with various userIds');
|
|
||||||
}
|
|
||||||
|
|
||||||
my $sessionCount = $session->db->quickScalar('select count(*) from userSession');
|
my $sessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||||
my $scratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
my $scratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||||
|
|
||||||
|
my @sessions;
|
||||||
|
|
||||||
|
foreach (1..2) {
|
||||||
|
push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
##Force automatic expiration of the sessions
|
||||||
|
$session->setting->set('sessionTimeout', -500);
|
||||||
|
|
||||||
|
foreach (1..2) {
|
||||||
|
push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
$session->setting->set('sessionTimeout', $origSessionTimeout );
|
||||||
|
|
||||||
|
$sessions[1]->scratch->set('scratch1', 1);
|
||||||
|
$sessions[3]->scratch->set('scratch3', 3);
|
||||||
|
|
||||||
|
my $newSessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||||
|
my $newScratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||||
|
|
||||||
|
is ($newSessionCount, $sessionCount+4, 'all new sessions created correctly');
|
||||||
|
is ($newScratchCount, $scratchCount+2, 'two of the new sessions have scratch entries');
|
||||||
|
|
||||||
|
my $activity = WebGUI::Workflow::Activity::DeleteExpiredSessions->create($session);
|
||||||
|
$activity->execute();
|
||||||
|
|
||||||
|
$newSessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||||
|
$newScratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||||
|
|
||||||
|
is ($newSessionCount, $sessionCount+2, 'two of the sessions were deleted');
|
||||||
|
is ($newScratchCount, $scratchCount+1, 'one of the new sessions have scratch entries were deleted');
|
||||||
|
|
||||||
|
foreach my $testSession (@sessions) {
|
||||||
|
$testSession->var->end;
|
||||||
|
$testSession->close;
|
||||||
|
}
|
||||||
|
|
||||||
##Add 4 sessions:
|
##Add 4 sessions:
|
||||||
## 1) Active session
|
## 1) Active session
|
||||||
## 2) Active session with scratch
|
## 2) Active session with scratch
|
||||||
|
|
@ -42,3 +77,6 @@ my $scratchCount = $session->db->quickScalar('select count(*) from userSessionSc
|
||||||
## Make sure that one scratch session was deleted and the other kept.
|
## Make sure that one scratch session was deleted and the other kept.
|
||||||
## Close and end all four sessions
|
## Close and end all four sessions
|
||||||
|
|
||||||
|
END: {
|
||||||
|
$session->setting->set('sessionTimeout', $origSessionTimeout );
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue