Skip to content

Commit

Permalink
Added sanity check for the bridge interval value (#4717)
Browse files Browse the repository at this point in the history
* Added sanity check for the bridge interval value, setting minimum allowed value to 30 seconds and maximum to 5 minutes. This is to avoid input of very low values which might overload the dexcom servers.

* Added missin ';'

* Fixed typoe in comment

* Added test for default interval (not set in config)

* Set lower limit to 1 second
  • Loading branch information
ahaarrestad authored and sulkaharo committed Dec 6, 2019
1 parent 7f21e5a commit 6abd6be
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/plugins/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ function options (env) {
, minutes: env.extendedSettings.bridge.minutes || 1440
};

var interval = env.extendedSettings.bridge.interval || 60000 * 2.5; // Default: 2.5 minutes

if (interval < 1000 || interval > 300000) {
// Invalid interval range. Revert to default
console.error("Invalid interval set: [" + interval + "ms]. Defaulting to 2.5 minutes.")
interval = 60000 * 2.5 // 2.5 minutes
}

return {
login: config
, interval: env.extendedSettings.bridge.interval || 60000 * 2.5
, interval: interval
, fetch: fetch_config
, nightscout: { }
, maxFailures: env.extendedSettings.bridge.maxFailures || 3
Expand Down
41 changes: 41 additions & 0 deletions tests/bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('bridge', function ( ) {
bridge: {
userName: 'nightscout'
, password: 'wearenotwaiting'
, interval: 60000
}
}
};
Expand All @@ -27,6 +28,7 @@ describe('bridge', function ( ) {

opts.login.accountName.should.equal('nightscout');
opts.login.password.should.equal('wearenotwaiting');
opts.interval.should.equal(60000);
});

it('store entries from share', function (done) {
Expand All @@ -39,4 +41,43 @@ describe('bridge', function ( ) {
bridge.bridged(mockEntries)(null);
});

it('set too low bridge interval option from env', function () {
var tooLowInterval = {
extendedSettings: {
bridge: { interval: 900 }
}
};

var opts = bridge.options(tooLowInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

it('set too high bridge interval option from env', function () {
var tooHighInterval = {
extendedSettings: {
bridge: { interval: 500000 }
}
};

var opts = bridge.options(tooHighInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

it('set no bridge interval option from env', function () {
var noInterval = {
extendedSettings: {
bridge: { }
}
};

var opts = bridge.options(noInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

});

0 comments on commit 6abd6be

Please sign in to comment.