From a653c7e624c0b2a01166f8899bf80f58f5e6ab50 Mon Sep 17 00:00:00 2001 From: Aaron Dufour Date: Fri, 12 Sep 2014 16:08:20 -0400 Subject: [PATCH 1/2] default opt to {} where appropriate --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f2727d2..de0d91f 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,8 @@ var hotp = {}; * */ hotp.gen = function(key, opt) { - var key = key || ''; + key = key || ''; + opt = opt || {}; var counter = opt.counter || 0; var p = 6; @@ -77,6 +78,7 @@ hotp.gen = function(key, opt) { * */ hotp.verify = function(token, key, opt) { + opt = opt || {}; var window = opt.window || 50; var counter = opt.counter || 0; @@ -115,6 +117,7 @@ var totp = {}; * */ totp.gen = function(key, opt) { + opt = opt || {}; var time = opt.time || 30; var _t = new Date().getTime();; @@ -165,6 +168,7 @@ totp.gen = function(key, opt) { * */ totp.verify = function(token, key, opt) { + opt = opt || {}; var time = opt.time || 30; var _t = new Date().getTime(); From 1556427b3922b01b369fd0e6c4a8c26516157673 Mon Sep 17 00:00:00 2001 From: Aaron Dufour Date: Fri, 12 Sep 2014 16:11:30 -0400 Subject: [PATCH 2/2] tests for not passing opt we just want those to not throw an error, which is why there's no assertions --- test/notp.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/notp.js b/test/notp.js index ef04f61..cfef9dd 100644 --- a/test/notp.js +++ b/test/notp.js @@ -50,6 +50,9 @@ exports.testHOTP = function() { }; var HOTP = ['755224', '287082','359152', '969429', '338314', '254676', '287922', '162583', '399871', '520489']; + // make sure we can not pass in opt + notp.hotp.verify('WILL NOT PASS', key); + // counterheck for failure opt.counter = 0; assert.ok(!notp.hotp.verify('WILL NOT PASS', key, opt), 'Should not pass'); @@ -76,6 +79,9 @@ exports.testTOTtoken = function() { window : 0, }; + // make sure we can not pass in opt + notp.totp.verify(token, key); + // counterheck for failure opt.time = 0; var token = 'windowILLNOTtokenASS'; @@ -172,6 +178,9 @@ exports.hotp_gen = function() { var HOTP = ['755224', '287082','359152', '969429', '338314', '254676', '287922', '162583', '399871', '520489']; + // make sure we can not pass in opt + notp.hotp.gen(key); + // counterheck for passes for(i=0;i