Merge pull request #9017 from owncloud/maxheartbeatinterval

Added max heartbeat interval to prevent integer overflow
This commit is contained in:
Morris Jobke 2014-06-13 00:19:07 +02:00
commit aa8f17bc63
2 changed files with 28 additions and 1 deletions

View File

@ -968,6 +968,8 @@ function initCore() {
* time out * time out
*/ */
function initSessionHeartBeat(){ function initSessionHeartBeat(){
// max interval in seconds set to 24 hours
var maxInterval = 24 * 3600;
// interval in seconds // interval in seconds
var interval = 900; var interval = 900;
if (oc_config.session_lifetime) { if (oc_config.session_lifetime) {
@ -977,6 +979,9 @@ function initCore() {
if (interval < 60) { if (interval < 60) {
interval = 60; interval = 60;
} }
if (interval > maxInterval) {
interval = maxInterval;
}
var url = OC.generateUrl('/heartbeat'); var url = OC.generateUrl('/heartbeat');
setInterval(function(){ setInterval(function(){
$.post(url); $.post(url);

View File

@ -19,7 +19,6 @@
* *
*/ */
/* global OC */
describe('Core base tests', function() { describe('Core base tests', function() {
describe('Base values', function() { describe('Base values', function() {
it('Sets webroots', function() { it('Sets webroots', function() {
@ -235,10 +234,12 @@ describe('Core base tests', function() {
}); });
afterEach(function() { afterEach(function() {
clock.restore(); clock.restore();
/* jshint camelcase: false */
window.oc_config = oldConfig; window.oc_config = oldConfig;
routeStub.restore(); routeStub.restore();
}); });
it('sends heartbeat half the session lifetime when heartbeat enabled', function() { it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
/* jshint camelcase: false */
window.oc_config = { window.oc_config = {
session_keepalive: true, session_keepalive: true,
session_lifetime: 300 session_lifetime: 300
@ -265,6 +266,7 @@ describe('Core base tests', function() {
expect(counter).toEqual(2); expect(counter).toEqual(2);
}); });
it('does no send heartbeat when heartbeat disabled', function() { it('does no send heartbeat when heartbeat disabled', function() {
/* jshint camelcase: false */
window.oc_config = { window.oc_config = {
session_keepalive: false, session_keepalive: false,
session_lifetime: 300 session_lifetime: 300
@ -279,6 +281,26 @@ describe('Core base tests', function() {
// still nothing // still nothing
expect(counter).toEqual(0); expect(counter).toEqual(0);
}); });
it('limits the heartbeat between one minute and one day', function() {
/* jshint camelcase: false */
var setIntervalStub = sinon.stub(window, 'setInterval');
window.oc_config = {
session_keepalive: true,
session_lifetime: 5
};
window.initCore();
expect(setIntervalStub.getCall(0).args[1]).toEqual(60 * 1000);
setIntervalStub.reset();
window.oc_config = {
session_keepalive: true,
session_lifetime: 48 * 3600
};
window.initCore();
expect(setIntervalStub.getCall(0).args[1]).toEqual(24 * 3600 * 1000);
setIntervalStub.restore();
});
}); });
describe('Parse query string', function() { describe('Parse query string', function() {
it('Parses query string from full URL', function() { it('Parses query string from full URL', function() {