Skip to content

Commit

Permalink
Merge branch 'Item14281' into Release02x01
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Jan 23, 2017
2 parents cb254ff + e4519af commit e193019
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
Expand Up @@ -93,6 +93,11 @@ sub init {
if ( defined $Foswiki::cfg{ScriptUrlPaths} ) {
%{ $prefs{"SCRIPTURLPATHS"} } = %{ $Foswiki::cfg{ScriptUrlPaths} };
}

# add {Sessions}{CookieRealm}
if ( defined $Foswiki::cfg{Sessions}{CookieRealm} ) {
$prefs{"COOKIEREALM"} = $Foswiki::cfg{Sessions}{CookieRealm};
}
$prefs{"URLHOST"} = Foswiki::Func::getUrlHost();

my $text =
Expand Down
4 changes: 3 additions & 1 deletion PatternSkin/pub/System/JavascriptFiles/foswikiPref_src.js
Expand Up @@ -260,12 +260,14 @@ foswiki.Pref = {
var cookieString = (inValues != null)
? inValues.join(foswiki.Pref.COOKIE_PREF_SEPARATOR) : '';
var expiryDate = new Date ();
var cookieDomain = foswiki.getPreference('COOKIEREALM');
var cookieSecure = foswiki.getPreference('URLHOST').startsWith("https://");
// Correct for Mac date bug - call only once for given Date object!
foswiki.Pref._fixCookieDate (expiryDate);
expiryDate.setTime (expiryDate.getTime()
+ foswiki.Pref.COOKIE_EXPIRY_TIME);
foswiki.Pref.setCookie(foswiki.Pref.FOSWIKI_PREF_COOKIE_NAME,
cookieString, expiryDate, '/');
cookieString, expiryDate, '/', cookieDomain, cookieSecure);
},

/**
Expand Down
3 changes: 3 additions & 0 deletions UnitTestContrib/test/unit/RequestTests.pm
Expand Up @@ -12,6 +12,7 @@ sub set_up {
my $this = shift;
$this->SUPER::set_up(@_);
$Foswiki::cfg{ScriptUrlPath} = '/fatwilly/bin';
$Foswiki::cfg{Sessions}{CookieRealm} = 'weebles.wobble';
delete $Foswiki::cfg{ScriptUrlPaths};
}

Expand Down Expand Up @@ -522,11 +523,13 @@ sub test_cookies {
);
$result[1] = new CGI::Cookie(
-name => 'c3',
-domain => 'weebles.wobble',
-value => 'value3',
-path => '/test',
-expires => '1234',
-secure => 1
);

$this->assert_deep_equals( $result[0], $result[1],
'Wrong returned cookie' );
}
Expand Down
Expand Up @@ -16,7 +16,10 @@
delay: 1000, // number of seconds to delay contacting f.o.
timeout: 5000, // number of seconds a jsonp call is considered failure
cookieName: "FOSWIKI_UPDATESPLUGIN", // name of the cookie
cookieExpires: 7 // number of days the cookie takes to expire
cookieExpires: 7, // number of days the cookie takes to expire
cookieSecure: '0', // If secure cookies are needed (https)
cookieDomain: '' // Override domain if requested.

}, foswikiUpdates; // singleton

// class constructor
Expand Down Expand Up @@ -47,6 +50,9 @@
self.options.endpointUrl = foswiki.getScriptUrl("rest", "UpdatesPlugin", "check");
}

self.options.cookieDomain = foswiki.getPreference('COOKIEREALM'); // Allow domain override
self.options.cookieSecure = foswiki.getPreference('URLHOST').startsWith('https://');

// events
$(document).bind("refresh.foswikiUpdates", function() {
//console.log("BIND refresh.foswikiUpdates calling loadPluginInfo.");
Expand All @@ -55,7 +61,12 @@

$(document).bind("forceRefresh.foswikiUpdates", function() {
//console.log("BIND forceRefresh.foswikiUpdates calling loadPluginInfo.");
$.cookie(self.options.cookieName, null, {expires: -1, path:'/'});
$.cookie(self.options.cookieName, null, {
expires: -1,
path:'/',
domain:self.options.cookieDomain,
secure:self.options.cookieSecure
});
self.loadPluginInfo(1);
});

Expand All @@ -69,7 +80,9 @@
//console.log("BIND click entered ");
$.cookie(self.options.cookieName, 0, {
expires: self.options.cookieExpires,
path: "/"
path: "/",
domain:self.options.cookieDomain,
secure:self.options.cookieSecure
});
$(".foswikiUpdatesMessage").fadeOut();
return false;
Expand Down Expand Up @@ -100,7 +113,9 @@
// zero explicitly can either mean: everything up-to-date or ignore pending updates
$.cookie(self.options.cookieName, self.numberOutdatedPlugins, {
expires: self.options.cookieExpires,
path: "/"
path: "/",
domain:self.options.cookieDomain,
secure:self.options.cookieSecure
});

//console.log("Forced: " + forced);
Expand All @@ -113,7 +128,9 @@
// remember the error state
$.cookie(self.options.cookieName, -1, {
expires: self.options.cookieExpires,
path: "/"
path: "/",
domain:self.options.cookieDomain,
secure:self.options.cookieSecure
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion core/lib/Foswiki/Request.pm
Expand Up @@ -521,7 +521,8 @@ sub cookie {
-value => $value,
-path => $path || '/',
-secure => $secure || $this->secure,
-expires => $expires || abs( $Foswiki::cfg{Sessions}{ExpireAfter} )
-expires => $expires || abs( $Foswiki::cfg{Sessions}{ExpireAfter} ),
-domain => $Foswiki::cfg{Sessions}{CookieRealm} || '',
);
}

Expand Down
2 changes: 2 additions & 0 deletions core/lib/Foswiki/Validation.pm
Expand Up @@ -203,6 +203,8 @@ sub getCookie {
-value => $secret,
-path => '/',
-httponly => 0, # we *want* JS to be able to read it!
-domain => $Foswiki::cfg{Sessions}{CookieRealm} || '',
-secure => $Foswiki::Plugins::SESSION->{request}->secure,
);

return $cookie;
Expand Down

0 comments on commit e193019

Please sign in to comment.