diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm
index ad1036c68..442ea532d 100644
--- a/lib/WebGUI/Admin.pm
+++ b/lib/WebGUI/Admin.pm
@@ -754,7 +754,7 @@ sub www_view {
$var->{backToSiteUrl} = $url->page;
# temporary! We are now in admin mode!
- $session->var->switchAdminOn;
+ $session->switchAdminOn;
# Add vars for AdminBar
$var->{adminPlugins} = $self->getAdminPluginTemplateVars;
diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm
index b6fa1ded3..7f084893d 100644
--- a/lib/WebGUI/Asset.pm
+++ b/lib/WebGUI/Asset.pm
@@ -454,7 +454,7 @@ The missing URL.
sub addMissing {
my $self = shift;
my $assetUrl = shift;
- return undef unless ($self->session->var->isAdminOn);
+ return undef unless ($self->session->isAdminOn);
my $i18n = WebGUI::International->new($self->session, "Asset");
my $output = $i18n->get("missing page query");
$output .= '
@@ -592,14 +592,15 @@ to SSL.
sub checkView {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
- my ($conf, $var, $http) = $self->session->quick(qw(config var http));
+ my $session = $self->session;
+ my ($conf, $http) = $self->session->quick(qw(config http));
if ($conf->get("sslEnabled") && $self->get("encryptPage") && ! $self->session->request->secure) {
# getUrl already changes url to https if 'encryptPage'
$http->setRedirect($self->getUrl);
$http->sendHeader;
return "chunked";
}
- elsif ($var->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash
+ elsif ($session->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash
my $queryFrag = "func=manageTrash";
if ($self->session->form->process('revision')) {
$queryFrag .= ";revision=".$self->session->form->process('revision');
@@ -608,7 +609,7 @@ sub checkView {
$http->sendHeader;
return "chunked";
}
- elsif ($var->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard
+ elsif ($session->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard
my $queryFrag = "func=manageClipboard";
if ($self->session->form->process('revision')) {
$queryFrag .= ";revision=".$self->session->form->process('revision');
@@ -679,7 +680,7 @@ sub dispatch {
my $session = $self->session;
my $state = $self->get('state');
##Only allow interaction with assets in certain states
- return if $state ne 'published' && $state ne 'archived' && !$session->var->isAdminOn;
+ return if $state ne 'published' && $state ne 'archived' && !$session->isAdminOn;
my $func = $session->form->param('func') || 'view';
my $viewing = $func eq 'view' ? 1 : 0;
my $sub = $self->can('www_'.$func);
@@ -1594,7 +1595,7 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
sub getToolbar {
my $self = shift;
- return undef unless $self->canEdit && $self->session->var->isAdminOn;
+ return undef unless $self->canEdit && $self->session->isAdminOn;
return $self->{_toolbar}
if (exists $self->{_toolbar});
my $userUiLevel = $self->session->user->profileField("uiLevel");
@@ -2372,7 +2373,7 @@ sub processTemplate {
}
if (! Exception::Class->caught() ) {
$var = { %{ $var }, %{ $self->getMetaDataAsTemplateVariables } };
- $var->{'controls'} = $self->getToolbar if $session->var->isAdminOn;
+ $var->{'controls'} = $self->getToolbar if $session->isAdminOn;
$var->{'assetIdHex'} = $session->id->toHex($self->getId);
my %vars = (
%{$self->get},
@@ -2683,7 +2684,7 @@ The default view method for any asset that doesn't define one. Under all normal
sub view {
my $self = shift;
- if ($self->session->var->isAdminOn) {
+ if ($self->session->isAdminOn) {
return $self->getToolbar.' '.$self->getTitle;
} else {
return "";
diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm
index 28c871024..12b8ec526 100644
--- a/lib/WebGUI/Asset/File.pm
+++ b/lib/WebGUI/Asset/File.pm
@@ -564,7 +564,7 @@ Generate the view method for the Asset, and handle caching.
sub view {
my $self = shift;
- if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
+ if (!$self->session->isAdminOn && $self->get("cacheTimeout") > 10) {
my $out = $self->session->cache->get($self->getViewCacheKey);
return $out if $out;
}
@@ -574,7 +574,7 @@ sub view {
$var{fileIcon} = $self->getFileIconUrl;
$var{fileSize} = Number::Format::format_bytes($self->get("assetSize"));
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
+ if (!$self->session->isAdminOn && $self->get("cacheTimeout") > 10) {
$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"));
}
return $out;
diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm
index 38613c581..c117bf05f 100644
--- a/lib/WebGUI/Asset/File/Image.pm
+++ b/lib/WebGUI/Asset/File/Image.pm
@@ -210,7 +210,7 @@ sub view {
my $session = $self->session;
my $cache = $session->cache;
my $cacheKey = $self->getWwwCacheKey('view');
- if (!$session->var->isAdminOn && $self->cacheTimeout > 10) {
+ if (!$session->isAdminOn && $self->cacheTimeout > 10) {
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@@ -233,7 +233,7 @@ sub view {
$var{annotateJs} = $crop_js . $domMe;
$var{parameters} .= sprintf(q{ id="%s"}, $self->getId);
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if (!$session->var->isAdminOn && $self->cacheTimeout > 10) {
+ if (!$session->isAdminOn && $self->cacheTimeout > 10) {
$cache->set( $cacheKey, $out, $self->get("cacheTimeout") );
}
return $out;
diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm
index e2bd61571..fc62fb3ca 100644
--- a/lib/WebGUI/Asset/File/ZipArchive.pm
+++ b/lib/WebGUI/Asset/File/ZipArchive.pm
@@ -209,7 +209,7 @@ sub view {
my $self = shift;
my $cache = $self->session->cache;
my $cacheKey = $self->getWwwCacheKey('view');
- if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
+ if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@@ -232,7 +232,7 @@ sub view {
$var{noInitialPage} = $i18n->get('noInitialPage');
$var{noFileSpecified} = $i18n->get('noFileSpecified');
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
+ if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
$cache->set( $cacheKey, $out, $self->cacheTimeout);
}
return $out;
@@ -268,7 +268,7 @@ Web facing method which is the default view page. This method does a
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
- if ($self->session->var->isAdminOn) {
+ if ($self->session->isAdminOn) {
return $self->session->asset($self->getContainer)->www_view;
}
$self->session->http->setRedirect($self->getFileUrl($self->showPage));
diff --git a/lib/WebGUI/Asset/Redirect.pm b/lib/WebGUI/Asset/Redirect.pm
index a5ad06223..d250aed76 100644
--- a/lib/WebGUI/Asset/Redirect.pm
+++ b/lib/WebGUI/Asset/Redirect.pm
@@ -99,7 +99,7 @@ Display the redirect url when in admin mode.
sub view {
my $self = shift;
- if ($self->session->var->isAdminOn) {
+ if ($self->session->isAdminOn) {
return $self->getToolbar.' '.$self->getTitle.' '.$self->redirectUrl;
}
else {
@@ -121,7 +121,7 @@ sub www_view {
my $i18n = WebGUI::International->new($self->session, "Asset_Redirect");
my $url = $self->redirectUrl;
WebGUI::Macro::process($self->session, \$url);
- if ($self->session->var->isAdminOn() && $self->canEdit) {
+ if ($self->session->isAdminOn() && $self->canEdit) {
return $self->getAdminConsole->render($i18n->get("what do you want to do with this redirect").'
- '.$i18n->get("go to the redirect url").'
diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm
index a2739ec65..a347b9068 100644
--- a/lib/WebGUI/Asset/Shortcut.pm
+++ b/lib/WebGUI/Asset/Shortcut.pm
@@ -239,7 +239,7 @@ Shortcut that the Visitor would see, or their own.
sub discernUserId {
my $self = shift;
- return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
+ return ($self->canManage && $self->session->isAdminOn) ? '1' : $self->session->user->userId;
}
#-------------------------------------------------------------------
@@ -464,7 +464,7 @@ admin mode is on.
sub _overridesCacheTag {
my $self = shift;
#cache by userId, assetId of this shortcut, and whether adminMode is on or not.
- return ["shortcutOverrides", $self->getId, $self->session->user->userId, $self->session->var->isAdminOn];
+ return ["shortcutOverrides", $self->getId, $self->session->user->userId, $self->session->isAdminOn];
}
#-------------------------------------------------------------------
@@ -488,7 +488,7 @@ sub getOverrides {
my $overridesRef = $cache->get($self->_overridesCacheTag);
##If admin mode is not on, and the cache is valid, and not expired, and the user object was not updated,
##return the cached value.
- if ( ! $session->var->isAdminOn
+ if ( ! $session->isAdminOn
&& $overridesRef
&& $overridesRef->{cacheNotExpired}
&& $overridesRef->{userLastUpdated} >= $u->get('lastUpdated')) {
@@ -591,7 +591,7 @@ sub getShortcutByCriteria {
if ($assetId) {
$scratchId = "Shortcut_" . $assetId;
if($self->session->scratch->get($scratchId) && !$self->disableContentLock) {
- unless ($self->session->var->isAdminOn) {
+ unless ($self->session->isAdminOn) {
return WebGUI::Asset->newById($self->session, $self->session->scratch->get($scratchId));
}
}
@@ -990,8 +990,8 @@ sub www_getUserPrefsForm {
my @fielden = $self->getPrefFieldsToShow;
my $f = WebGUI::HTMLForm->new($self->session,extras=>' onsubmit="submitForm(this,\''.$self->getId.'\',\''.$self->getUrl.'\');return false;"');
$f->raw('');
- my $allowedToSave = ( ! $session->var->isAdminOn && $self->getParent->canPersonalize )
- || ( $session->var->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
+ my $allowedToSave = ( ! $session->isAdminOn && $self->getParent->canPersonalize )
+ || ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
if ($allowedToSave) {
$f->hidden(
-name => 'func',
@@ -1090,7 +1090,7 @@ sub www_saveUserPrefs {
my $self = shift;
my $session = $self->session;
return '' unless $self->getParent->canPersonalize
- || ( $session->var->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
+ || ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
my @fellowFields = $self->getPrefFieldsToShow;
my %data = ();
$self->uncacheOverrides;
diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm
index df8c8f6eb..521f6ea2d 100644
--- a/lib/WebGUI/Asset/Sku/Product.pm
+++ b/lib/WebGUI/Asset/Sku/Product.pm
@@ -1654,7 +1654,7 @@ sub view {
my $session = $self->session;
my $cache = $session->cache;
my $cacheKey = $self->getWwwCacheKey( 'view' );
- if (!$session->var->isAdminOn && $self->get("cacheTimeout") > 10){
+ if (!$session->isAdminOn && $self->get("cacheTimeout") > 10){
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@@ -1856,7 +1856,7 @@ sub view {
$var{continueShoppingUrl} = $self->getUrl;
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && $self->{_hasAddedToCart} != 1){
+ if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && $self->{_hasAddedToCart} != 1){
$cache->set( $cacheKey, $out, $self->cacheTimeout );
}
return $out;
diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm
index aeaf109d4..9d5955dbc 100644
--- a/lib/WebGUI/Asset/Snippet.pm
+++ b/lib/WebGUI/Asset/Snippet.pm
@@ -253,7 +253,7 @@ sub view {
my $session = $self->session;
my $versionTag = WebGUI::VersionTag->getWorking($session, 1);
my $noCache =
- $session->var->isAdminOn
+ $session->isAdminOn
|| $self->cacheTimeout <= 10
|| ($versionTag && $versionTag->getId eq $self->tagId);
my $cacheKey = $self->getWwwCacheKey('view', $calledAsWebMethod);
@@ -265,7 +265,7 @@ sub view {
? $self->snippetPacked
: $self->snippet
;
- $output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
+ $output = $self->getToolbar.$output if ($session->isAdminOn && !$calledAsWebMethod);
if ($self->processAsTemplate) {
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
}
diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm
index e7df99f65..1f55e6c68 100644
--- a/lib/WebGUI/Asset/Template.pm
+++ b/lib/WebGUI/Asset/Template.pm
@@ -564,13 +564,13 @@ sub process {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->log->warn('process called on template in trash: '.$self->getId
.'. The template was called through this url: '.$session->asset->url);
- return $session->var->isAdminOn ? $i18n->get('template in trash') : '';
+ return $session->isAdminOn ? $i18n->get('template in trash') : '';
}
elsif ($self->state =~ /^clipboard/) {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->log->warn('process called on template in clipboard: '.$self->getId
.'. The template was called through this url: '.$session->asset->url);
- return $session->var->isAdminOn ? $i18n->get('template in clipboard') : '';
+ return $session->isAdminOn ? $i18n->get('template in clipboard') : '';
}
# Return a JSONinfied version of vars if JSON is the only requested content type.
diff --git a/lib/WebGUI/Asset/Template/Parser.pm b/lib/WebGUI/Asset/Template/Parser.pm
index b37f606f5..2771736d6 100644
--- a/lib/WebGUI/Asset/Template/Parser.pm
+++ b/lib/WebGUI/Asset/Template/Parser.pm
@@ -39,7 +39,7 @@ sub addSessionVars {
$vars->{"session.user.username"} = $self->session->user->username;
$vars->{"session.user.firstDayOfWeek"} = $self->session->user->profileField("firstDayOfWeek");
$vars->{"session.config.extrasurl"} = $self->session->url->extras();
- $vars->{"session.var.adminOn"} = $self->session->var->isAdminOn;
+ $vars->{"session.var.adminOn"} = $self->session->isAdminOn;
$vars->{"session.setting.companyName"} = $self->session->setting->get("companyName");
$vars->{"session.setting.anonymousRegistration"} = $self->session->setting->get("anonymousRegistration");
my $forms = $self->session->form->paramsHashRef();
diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm
index ce08d4bd1..b963285c6 100644
--- a/lib/WebGUI/Asset/Wobject/Article.pm
+++ b/lib/WebGUI/Asset/Wobject/Article.pm
@@ -320,7 +320,7 @@ returns the output.
sub view {
my $self = shift;
my $cache = $self->session->cache;
- if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
+ if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
!$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) {
my $out = $cache->get($self->getViewCacheKey);
return $out if $out;
@@ -384,7 +384,7 @@ sub view {
}
$p->appendTemplateVars(\%var);
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
+ if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
!$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) {
$cache->set($self->getViewCacheKey, $out, $self->cacheTimeout);
}
diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm
index af0aa67ad..c5aa3c1f4 100644
--- a/lib/WebGUI/Asset/Wobject/Calendar.pm
+++ b/lib/WebGUI/Asset/Wobject/Calendar.pm
@@ -957,7 +957,7 @@ sub view {
##### Process the template
# Add any global variables
# Admin
- if ($self->session->var->isAdminOn) {
+ if ($self->session->isAdminOn) {
$var->{'admin'} = 1;
$var->{'adminControls'} = $self->getToolbar;
}
diff --git a/lib/WebGUI/Asset/Wobject/Dashboard.pm b/lib/WebGUI/Asset/Wobject/Dashboard.pm
index 4d67eaa48..512078b6e 100644
--- a/lib/WebGUI/Asset/Wobject/Dashboard.pm
+++ b/lib/WebGUI/Asset/Wobject/Dashboard.pm
@@ -121,7 +121,7 @@ Dashboard that Visitor would see, or their own.
sub discernUserId {
my $self = shift;
- return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
+ return ($self->canManage && $self->session->isAdminOn) ? '1' : $self->session->user->userId;
}
#-------------------------------------------------------------------
@@ -243,7 +243,7 @@ turned on.
sub isManaging {
my $self = shift;
- return 1 if ($self->canManage && $self->session->var->isAdminOn());
+ return 1 if ($self->canManage && $self->session->isAdminOn());
return 0;
}
@@ -415,7 +415,7 @@ sub view {
}
}
}
- $vars{showAdmin} = ($self->session->var->isAdminOn && $self->canEdit);
+ $vars{showAdmin} = ($self->session->isAdminOn && $self->canEdit);
$vars{"dragger.init"} = '
\n\n|,
diff --git a/t/Macro/UsersOnline.t b/t/Macro/UsersOnline.t
index 108922b34..6858060d2 100644
--- a/t/Macro/UsersOnline.t
+++ b/t/Macro/UsersOnline.t
@@ -15,7 +15,6 @@ use JSON;
use WebGUI::Test;
use WebGUI::International;
use WebGUI::Session;
-use WebGUI::Session::Var;
use WebGUI::User;
use WebGUI::Macro::UsersOnline;
diff --git a/t/Session.t b/t/Session.t
index 03a4702a8..810a97ab5 100644
--- a/t/Session.t
+++ b/t/Session.t
@@ -16,8 +16,7 @@ use WebGUI::Session;
use WebGUI::User;
use Test::More;
-
-plan tests => 5; # increment this value for each test you create
+use Test::Deep;
my $session = WebGUI::Test->session;
@@ -32,12 +31,14 @@ is($userId, $user->userId, 'changing session user changes sessionId inside userS
$session->user({userId => 3});
is($session->user->userId, 3, 'Set session user to Admin, check userId==3');
-is($session->user->profileField('uiLevel'), 9, 'Set session user to Admin, check uiLevel==9');
+is($session->user->get('uiLevel'), 9, 'Set session user to Admin, check uiLevel==9');
my $dupe = $session->duplicate;
WebGUI::Test->addToCleanup($dupe);
-is $session->getId, $dupe->getId, 'duplicated session has the same sessionId';
+is($session->get('sessionId'), $session->getId, 'getId returns sessionId');
+
+is $dupe->getId, $session->getId, 'duplicated session has the same sessionId';
################################################################
#
@@ -59,4 +60,159 @@ WebGUI::Test->addToCleanup(sub {$session->config->delete('dbslave2');});
my $slave2 = $session->dbSlave;
isa_ok($slave2, 'WebGUI::SQL::db');
+cmp_ok($session->get("lastPageView"), '>', 0, "lastPageView set to something");
+
+can_ok($session, qw/isAdminOn switchAdminOn switchAdminOff/);
+is($session->isAdminOn, 0, "isAdminOn()");
+$session->switchAdminOn;
+is($session->isAdminOn, 1, "switchAdminOn()");
+$session->switchAdminOff;
+is($session->isAdminOn, 0, "switchAdminOff()");
+
+my $token = $session->scratch->get('webguiCsrfToken');
+ok( $token, 'CSRF token set');
+ok( $session->id->valid($token), '...is a valid GUID');
+
+my $id = $session->getId;
+my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?", [$id]);
+is($count, 1, "created an user session entry in the database");
+
+my $env;
+$session->request->env->{REMOTE_ADDR} = '192.168.0.34';
+
+my $varSession = WebGUI::Session->open($session->config, $session->request->env);
+WebGUI::Test->addToCleanup($varSession);
+my $varTime = time();
+isnt($varSession->scratch->get('webguiCsrfToken'), $token, '... calling new without sessionId creates a new token');
+isnt($varSession->getId, $session->getId, "new session has a different id from current session");
+
+my $varExpires = $varTime + $session->setting->get('sessionTimeout');
+cmp_ok(abs($varSession->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly');
+cmp_ok(abs($varSession->get('expires') - $varExpires), '<=', 1, 'expires set correctly');
+
+is($varSession->get('userId'), 1, 'default userId is 1');
+
+is($varSession->get('adminOn'), $varSession->isAdminOn, "get('adminOn') and isAdminOn return the same thing");
+is($varSession->get('adminOn'), 0, "adminOn is off by default"); ##retest
+is($varSession->get('lastIP'), '192.168.0.34', "lastIP fetched");
+
+
+my $illegalSessionId = 'illegalSessionIdThatIsTooLong';
+# '1234567890123456789012'
+my $varIllegal = WebGUI::Session->open($session->config, undef, );
+WebGUI::Test->addToCleanup($varIllegal);
+
+isa_ok($varIllegal, 'WebGUI::Session', 'invalid sessionId will still produce a Session object');
+ok($session->id->valid($varIllegal->getId), 'valid ID created for the new session, when bad Id was suggested');
+ok(index($varIllegal->getId, $illegalSessionId) == -1, 'illegal session was not truncated to make the new Id');
+
+$session->request->env->{REMOTE_ADDR} = '10.0.0.5';
+my $varCopy = WebGUI::Session->open($session->config, $session->request->env, $varSession->getId);
+is($varCopy->scratch->get('webguiCsrfToken'), $varSession->scratch->get('webguiCsrfToken'), 'opening a copy of a user session did not change the CSRF token');
+
+cmp_deeply(
+ $varCopy,
+ methods(
+ ['get', 'sessionId'] => $varSession->get('sessionId'),
+ ['get', 'userId'] => $varSession->get('userId'),
+ ['get', 'adminOn'] => $varSession->get('adminOn'),
+ ),
+ 'similar methods in copy of original var object'
+);
+
+is($varCopy->get('lastIP'), '10.0.0.5', "lastIP set on copy");
+
+my $varSessionId = $varSession->getId;
+$varSession->end;
+($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$varSession->getId]);
+ok($count == 0,"end() removes current entry from database");
+
+{
+ my $sessionId = 'nonExistantIdButValid0';
+ # '1234567890123456789012'
+ my $testSession = WebGUI::Session->open($session->config, undef, $sessionId);
+ my $guard = WebGUI::Test->cleanupGuard($testSession);
+ isa_ok($testSession, 'WebGUI::Session', 'non-existant sessionId will still produce a Var object');
+ is($testSession->getId, $sessionId, 'user session Id set to non-existant Id');
+}
+
+{
+ my $expire = WebGUI::Session->open($session->config);
+ my $guard = WebGUI::Test->cleanupGuard($expire);
+ $expire->switchAdminOn;
+ # jury rig the database and the cache to expire
+ my $expire_time = $expire->get('lastPageView') - 1;
+ $session->db->write("update userSession set userId=?, expires=? where sessionId=?", [3, $expire_time, $expire->getId]);
+ $session->user({userId => 3});
+ my $copyOfSession = { %{ $expire->get() } };
+ $copyOfSession->{expires} = $expire_time;
+ $session->cache->set($expire->getId, $copyOfSession);
+
+ my $copy = WebGUI::Session->open($session->config, undef, $expire->getId);
+ my $guard2 = WebGUI::Test->cleanupGuard($copy);
+ is $copy->getId, $expire->getId, 'new Var object has correct id';
+ isnt $copy->isAdminOn, $expire->isAdminOn, 'new adminOn not equal to old adminOn';
+ is $copy->isAdminOn, 0, 'new Var object has default adminOn';
+ isnt $copy->get('userId'), 3, 'new userId not equal to old userId';
+}
+
+{
+ ##Var objects for noFuss tests
+ my $trial = WebGUI::Session->open($session->config);
+ my $expiring = WebGUI::Session->open($session->config);
+ my $guard = WebGUI::Test->cleanupGuard($trial, $expiring);
+ $session->db->write("update userSession set expires=? where sessionId=?", [$expiring->get('lastPageView')-5, $expiring->getId]);
+ $expiring->{_var}{expires} = $expiring->get('lastPageView')-5;
+
+ ##Valid fetch with no fuss
+ my $varTest = WebGUI::Session->open($session->config, $session->request->env, $trial->getId, 1);
+ my $guard2 = WebGUI::Test->cleanupGuard($varTest);
+
+ cmp_deeply(
+ $varTest,
+ methods(
+ ['get', 'sessionId'] => $trial->getId,
+ ['get', 'userId'] => 1,
+ ['get', 'adminOn'] => 0,
+ ['get', 'lastIP'] => '127.0.0.1',
+ ['get', 'expires'] => $trial->get('expires'),
+ ['get', 'lastPageView'] => $trial->get('lastPageView'),
+ ),
+ 'fetching a valid session with noFuss does not update the object info'
+ );
+
+ ##Test a valid fetch
+ my $expired = WebGUI::Session->open($session->config, undef, $expiring->getId, 1);
+ my $guard3 = WebGUI::Test->cleanupGuard($expired);
+
+ cmp_deeply(
+ $expired,
+ methods(
+ ['get', 'sessionId'] => $expiring->getId,
+ ['get', 'userId'] => 1,
+ ['get', 'adminOn'] => 0,
+ ['get', 'lastIP'] => '127.0.0.1',
+ ['get', 'lastPageView'] => $expiring->get('lastPageView'),
+ ['get', 'expires'] => $expiring->get('expires'),
+ ),
+ 'fetching a valid session with noFuss does not update the object info, even if it has expired'
+ );
+
+}
+
+my $varId4 = 'idDoesNotExist00779988';
+# '1234567890123456789012'
+my $varTest = WebGUI::Session->open($session->config, undef, $varId4, 1);
+WebGUI::Test->addToCleanup($varTest);
+isa_ok($varTest, "WebGUI::Session", "non-existant Id with noFuss returns a valid object...");
+is($varTest->getId, $varId4, "...and we got our requested Id");
+
+$varTest->start(3, $varTest->getId);
+is($varTest->get('userId'), 3, 'userId set via start');
+$varTest->start("", $varTest->getId);
+is($varTest->get('userId'), 1, 'calling start with null userId returns default user (visitor)');
+
+
+done_testing;
+
#vim:ft=perl
diff --git a/t/Session/Http.t b/t/Session/Http.t
index 92237691d..3f5684e11 100644
--- a/t/Session/Http.t
+++ b/t/Session/Http.t
@@ -32,7 +32,7 @@ use Test::MockObject::Extends;
##try and implement the mod_perl cookie handling code.
$http = Test::MockObject::Extends->new($http);
my $cookieName = $session->config->getCookieName;
-my $varId = $session->var->getId();
+my $varId = $session->getId();
$http->mock( getCookies => sub { return {$cookieName => $varId} } );
diff --git a/t/Session/Var.t b/t/Session/Var.t
deleted file mode 100644
index 20dcaea4c..000000000
--- a/t/Session/Var.t
+++ /dev/null
@@ -1,216 +0,0 @@
-#-------------------------------------------------------------------
-# WebGUI is Copyright 2001-2009 Plain Black Corporation.
-#-------------------------------------------------------------------
-# Please read the legal notices (docs/legal.txt) and the license
-# (docs/license.txt) that came with this distribution before using
-# this software.
-#-------------------------------------------------------------------
-# http://www.plainblack.com info@plainblack.com
-#-------------------------------------------------------------------
-
-use strict;
-
-use WebGUI::Test;
-use WebGUI::Session;
-use WebGUI::Session::Var;
-
-use Test::More tests => 44; # increment this value for each test you create
-use Test::Deep;
-
-my $session = WebGUI::Test->session;
-
-ok($session->var->getId ne "", "getId()");
-cmp_ok($session->var->get("lastPageView"), '>', 0, "get(lastPageView)");
-is($session->var->isAdminOn, 0, "isAdminOn()");
-$session->var->switchAdminOn;
-is($session->var->isAdminOn, 1, "switchAdminOn()");
-$session->var->switchAdminOff;
-is($session->var->isAdminOn, 0, "switchAdminOff()");
-
-my $token = $session->scratch->get('webguiCsrfToken');
-ok( $token, 'CSRF token set');
-ok( $session->id->valid($token), '...is a valid GUID');
-
-my $id = $session->var->getId;
-my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$id]);
-is($count, 1, "created an user session entry in the database");
-
-my $env = $session->request->env;
-$env->{REMOTE_ADDR} = '192.168.0.34';
-
-my $var = WebGUI::Session::Var->new($session);
-my $varTime = time();
-my $varExpires = $varTime + $session->setting->get('sessionTimeout');
-isa_ok($var, 'WebGUI::Session::Var', 'new returns Var object');
-isnt($session->scratch->get('webguiCsrfToken'), $token, '... calling new without sessionId creates a new token');
-$token = $session->scratch->get('webguiCsrfToken');
-
-cmp_ok(abs($var->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly');
-cmp_ok(abs($var->get('expires') - $varExpires), '<=', 1, 'expires set correctly');
-
-is($var->get('userId'), 1, 'default userId is 1');
-
-is($var->get('sessionId'), $var->getId, "get('sessionId') and getId return the same thing");
-isnt($var->getId, $session->var->getId, "a sessionId different from our Session's var sessionId was created");
-is($var->getId, $session->getId, 'SessionId set to userSessionId from var');
-
-is($var->get('adminOn'), $var->isAdminOn, "get('adminOn') and isAdminOn return the same thing");
-is($var->get('adminOn'), 0, "adminOn is off by default"); ##retest
-
-is($var->get('lastIP'), '192.168.0.34', "lastIP fetched");
-
-isa_ok($var->session, 'WebGUI::Session', 'session method returns a Session object');
-is($var->session->getId, $session->getId, 'session method returns our Session object');
-
-sleep(2);
-$env->{REMOTE_ADDR} = '10.0.5.5';
-
-#Grab a more recent version of our user session object
-$varTime = time();
-my $var2 = WebGUI::Session::Var->new($session, $session->getId);
-$varExpires = $varTime + $session->setting->get('sessionTimeout');
-is($var2->session->scratch->get('webguiCsrfToken'), $token, 'opening a new user session did not change the CSRF token');
-
-cmp_deeply(
- $var2,
- methods(
- ['get', 'sessionId'] => $var->get('sessionId'),
- ['get', 'userId'] => $var->get('userId'),
- ['get', 'adminOn'] => $var->get('adminOn'),
- ),
- 'similar methods in copy of original var object'
-);
-
-cmp_ok(abs($var2->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly on copy');
-cmp_ok(abs($var2->get('expires') - $varExpires), '<=', 1, 'expires set correctly on copy');
-is($var2->get('lastIP'), '10.0.5.5', "lastIP set on copy");
-
-my $var2Id = $var2->getId;
-$var2->end;
-($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$var2->getId]);
-ok($count == 0,"end() removes current entry from database");
-$var->end;
-
-$var2 = WebGUI::Session::Var->new($session, 'illegalSessionIdThatIsTooLong');
-# '1234567890123456789012'
-isa_ok($var2, 'WebGUI::Session::Var', 'invalid sessionId will still produce a Var object');
-($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$var2->getId]);
-is($count, 0, "object store of sessionId does not match database record");
-$var2Id = $var2->getId;
-$var2->end;
-my $idToDelete = substr $var2Id,0,22;
-($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$idToDelete]);
-is($count, 1, "Unable to delete database record for Var object with invalid sessionId");
-
-my $varId3 = 'nonExistantIdButValid0';
-# '1234567890123456789012'
-$var = WebGUI::Session::Var->new($session, $varId3);
-isa_ok($var, 'WebGUI::Session::Var', 'non-existant sessionId will still produce a Var object');
-is($var->getId, $varId3, 'user session Id set to non-existant Id');
-is($session->getId, $varId3, 'session Id set to non-existant Id');
-
-cmp_deeply(
- $var,
- methods(
- ['get', 'sessionId'] => $varId3,
- ['get', 'userId'] => 1,
- ['get', 'adminOn'] => 0,
- ['get', 'lastIP'] => '10.0.5.5',
- ),
- 'non-existant Id returns default values'
-);
-
-$var->end;
-
-##Grab a new Var object that we'll expire. We'll detect the expiration
-##by looking for admin status and userId
-$var2 = WebGUI::Session::Var->new($session);
-$var2->switchAdminOn;
-
-# jury rig the database and the cache to expire
-$session->db->write("update userSession set userId=? where sessionId=?",
- [3, $var2->getId]);
-$session->db->write("update userSession set expires=? where sessionId=?",
- [$var2->get('lastPageView')-1, $var2->getId]);
-my %copyOfVar2 = %{$var2->{_var}};
-$copyOfVar2{expires} = $var2->get('lastPageView')-1;
-$copyOfVar2{userId} = 3;
-$session->cache->set($var2->getId, \%copyOfVar2);
-
-my $var3 = WebGUI::Session::Var->new($session, $var2->getId);
-is $var3->getId, $var2->getId, 'new Var object has correct id';
-isnt $var3->isAdminOn, $var2->isAdminOn, 'new adminOn not equal to old adminOn';
-is $var3->isAdminOn, 0, 'new Var object has default adminOn';
-isnt $var3->get('userId'), 3, 'new userId not equal to old userId';
-$var2->end;
-$var3->end;
-
-##Var objects for noFuss tests
-my $var4 = WebGUI::Session::Var->new($session);
-my $varExpiring = WebGUI::Session::Var->new($session);
-$session->db->write("update userSession set expires=? where sessionId=?",
- [$varExpiring->get('lastPageView')-1, $varExpiring->getId]);
-$varExpiring->{_var}{expires} = $varExpiring->get('lastPageView')-1;
-
-sleep 1;
-
-$env->{REMOTE_ADDR} = '127.0.0.1';
-
-##Test a valid fetch
-my $varTest = WebGUI::Session::Var->new($session, $var4->getId, 1);
-
-cmp_deeply(
- $varTest,
- methods(
- ['get', 'sessionId'] => $var4->getId,
- ['get', 'userId'] => 1,
- ['get', 'adminOn'] => 0,
- ['get', 'lastIP'] => '10.0.5.5',
- ['get', 'expires'] => $var4->get('expires'),
- ['get', 'lastPageView'] => $var4->get('lastPageView'),
- ),
- 'fetching a valid session with noFuss does not update the object info'
-);
-
-$varTest->end;
-$var4->end;
-
-##Test a valid fetch
-$varTest = WebGUI::Session::Var->new($session, $varExpiring->getId, 1);
-
-cmp_deeply(
- $varTest,
- methods(
- ['get', 'sessionId'] => $varExpiring->getId,
- ['get', 'userId'] => 1,
- ['get', 'adminOn'] => 0,
- ['get', 'lastIP'] => '10.0.5.5',
- ['get', 'lastPageView'] => $varExpiring->get('lastPageView'),
- ['get', 'expires'] => $varExpiring->get('expires'),
- ),
- 'fetching a valid session with noFuss does not update the object info, even if it has expired'
-);
-
-$varExpiring->end;
-$varTest->end;
-
-my $varId4 = 'idDoesNotExist00779988';
-# '1234567890123456789012'
-$varTest = WebGUI::Session::Var->new($session, $varId4, 1);
-isa_ok($varTest, "WebGUI::Session::Var", "non-existant Id with noFuss returns a valid object...");
-is($varTest->getId, $varId4, "...and we got our requested Id");
-
-$varTest->start(3, $varTest->getId);
-is($varTest->get('userId'), 3, 'userId set via start');
-$varTest->start("", $varTest->getId);
-is($varTest->get('userId'), 1, 'calling start with null userId returns default user (visitor)');
-
-END {
-
- foreach my $varObj ($var, $var2, $var3, $var4, $varExpiring, $varTest) {
- if (defined $varObj and ref $varObj eq 'WebGUI::Session::Var') {
- $varObj->end();
- }
- }
- $session->db->write("delete from userSession where sessionId=?",[$idToDelete]);
-}
diff --git a/t/Workflow/Activity/DeleteExpiredSessions.t b/t/Workflow/Activity/DeleteExpiredSessions.t
index 8355e426d..b9378c94b 100644
--- a/t/Workflow/Activity/DeleteExpiredSessions.t
+++ b/t/Workflow/Activity/DeleteExpiredSessions.t
@@ -93,7 +93,7 @@ is ($newSessionCount, $sessionCount+2, 'two of the sessions were deleted');
is ($newScratchCount, $scratchCount+2, 'scratch from both sessions cleaned up');
foreach my $testSession (@sessions) {
- $testSession->var->end;
+ $testSession->end;
$testSession->close;
}