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();