From 65cbc8455ab0b594e5d8212413d31153f4d3ef61 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 9 Nov 2017 15:49:48 +0200 Subject: [PATCH] test(cloudcmd) authCheck --- server/cloudcmd.js | 2 +- test/server/cloudcmd.js | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/server/cloudcmd.js b/server/cloudcmd.js index 636998a5..98cf65e1 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -100,7 +100,7 @@ function getPrefix(prefix) { return prefix || ''; } - +module.exports._authCheck = authCheck; function authCheck(socket, success) { if (!config('auth')) return success(); diff --git a/test/server/cloudcmd.js b/test/server/cloudcmd.js index 71c49cf5..640de30f 100644 --- a/test/server/cloudcmd.js +++ b/test/server/cloudcmd.js @@ -11,6 +11,7 @@ const config = require(DIR + 'config'); const { _authenticate, _getPrefix, + _authCheck, } = cloudcmd; test('cloudcmd: args: no', (t) => { @@ -61,6 +62,54 @@ test('cloudcmd: getPrefix', (t) => { t.end(); }); +test('cloudcmd: authCheck: success', (t) => { + const auth = config('auth'); + const success = sinon.stub(); + const on = sinon.stub; + const socket = { + on, + }; + + config('auth', true); + _authCheck(socket, success); + config('auth', auth); + + t.notOk(success.called, 'should not call success'); + t.end(); +}); + +test('cloudcmd: authCheck: socket', (t) => { + const auth = config('auth'); + const success = sinon.stub(); + const on = sinon.stub(); + const socket = { + on, + }; + + config('auth', true); + _authCheck(socket, success); + config('auth', auth); + + t.ok(on.calledWith('auth'), 'should call socket.on'); + t.end(); +}); + +test('cloudcmd: authCheck: success', (t) => { + const success = sinon.stub(); + const auth = config('auth'); + const on = sinon.stub(); + const socket = { + on, + }; + + config('auth', true); + _authCheck(socket, success); + config('auth', auth); + + t.notOk(success.called, 'should not call success'); + t.end(); +}); + test('cloudcmd: authenticate: reject', (t) => { const success = sinon.stub(); const emit = sinon.stub();