From 078bac8ca53eeb65db9e4886f40767f1e435820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Aarrestad?= Date: Thu, 4 Jul 2019 20:50:02 +0200 Subject: [PATCH 1/5] 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. --- lib/plugins/bridge.js | 10 +++++++++- tests/bridge.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/plugins/bridge.js b/lib/plugins/bridge.js index dc47f13aa9b..102ae9f025a 100644 --- a/lib/plugins/bridge.js +++ b/lib/plugins/bridge.js @@ -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 < 30000 || 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.4 minutes + } + return { login: config - , interval: env.extendedSettings.bridge.interval || 60000 * 2.5 + , interval: interval , fetch: fetch_config , nightscout: { } , maxFailures: env.extendedSettings.bridge.maxFailures || 3 diff --git a/tests/bridge.test.js b/tests/bridge.test.js index 99c1587fab4..7b2dd416405 100644 --- a/tests/bridge.test.js +++ b/tests/bridge.test.js @@ -10,6 +10,7 @@ describe('bridge', function ( ) { bridge: { userName: 'nightscout' , password: 'wearenotwaiting' + , interval: 60000 } } }; @@ -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) { @@ -39,4 +41,30 @@ describe('bridge', function ( ) { bridge.bridged(mockEntries)(null); }); + it('set too low bridge interval option from env', function () { + var tooLowInterval = { + extendedSettings: { + bridge: { interval: 10000 } + } + }; + + var opts = bridge.options(tooLowInterval); + should.exist(opts); + + opts.interval.should.equal(150000); + }); + + it('set too high bridge interval option from env', function () { + var tooLowInterval = { + extendedSettings: { + bridge: { interval: 500000 } + } + }; + + var opts = bridge.options(tooLowInterval); + should.exist(opts); + + opts.interval.should.equal(150000); + }); + }); From 81d15333c8d944c80678e9b0e1467dee86741b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Aarrestad?= Date: Thu, 4 Jul 2019 21:06:01 +0200 Subject: [PATCH 2/5] Added missin ';' --- lib/plugins/bridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/bridge.js b/lib/plugins/bridge.js index 102ae9f025a..d0d8696108c 100644 --- a/lib/plugins/bridge.js +++ b/lib/plugins/bridge.js @@ -46,7 +46,7 @@ function options (env) { , minutes: env.extendedSettings.bridge.minutes || 1440 }; - var interval = env.extendedSettings.bridge.interval || 60000 * 2.5 // Default: 2.5 minutes + var interval = env.extendedSettings.bridge.interval || 60000 * 2.5; // Default: 2.5 minutes if (interval < 30000 || interval > 300000) { // Invalid interval range. Revert to default From b8f6960cde32dab294dc22c1f33f64fe4ab2f8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Aarrestad?= Date: Thu, 4 Jul 2019 21:08:30 +0200 Subject: [PATCH 3/5] Fixed typoe in comment --- lib/plugins/bridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/bridge.js b/lib/plugins/bridge.js index d0d8696108c..9f780c66be6 100644 --- a/lib/plugins/bridge.js +++ b/lib/plugins/bridge.js @@ -51,7 +51,7 @@ function options (env) { if (interval < 30000 || 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.4 minutes + interval = 60000 * 2.5 // 2.5 minutes } return { From 88f6c9668e18794d9bc49aa165773807963dc5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Aarrestad?= Date: Thu, 4 Jul 2019 21:12:15 +0200 Subject: [PATCH 4/5] Added test for default interval (not set in config) --- tests/bridge.test.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/bridge.test.js b/tests/bridge.test.js index 7b2dd416405..2edfcadf68b 100644 --- a/tests/bridge.test.js +++ b/tests/bridge.test.js @@ -55,13 +55,26 @@ describe('bridge', function ( ) { }); it('set too high bridge interval option from env', function () { - var tooLowInterval = { + var tooHighInterval = { extendedSettings: { bridge: { interval: 500000 } } }; - var opts = bridge.options(tooLowInterval); + 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); From eb0f8ae7787a439de5d011108e42695339cebd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Aarrestad?= Date: Thu, 11 Jul 2019 22:16:52 +0200 Subject: [PATCH 5/5] Set lower limit to 1 second --- lib/plugins/bridge.js | 2 +- tests/bridge.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/bridge.js b/lib/plugins/bridge.js index 9f780c66be6..bf3c67e88da 100644 --- a/lib/plugins/bridge.js +++ b/lib/plugins/bridge.js @@ -48,7 +48,7 @@ function options (env) { var interval = env.extendedSettings.bridge.interval || 60000 * 2.5; // Default: 2.5 minutes - if (interval < 30000 || interval > 300000) { + 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 diff --git a/tests/bridge.test.js b/tests/bridge.test.js index 2edfcadf68b..66b69f64c3a 100644 --- a/tests/bridge.test.js +++ b/tests/bridge.test.js @@ -44,7 +44,7 @@ describe('bridge', function ( ) { it('set too low bridge interval option from env', function () { var tooLowInterval = { extendedSettings: { - bridge: { interval: 10000 } + bridge: { interval: 900 } } };