test(cloudcmd) authCheck

This commit is contained in:
coderaiser 2017-11-09 15:49:48 +02:00
parent c5a4914103
commit 65cbc8455a
2 changed files with 50 additions and 1 deletions

View file

@ -100,7 +100,7 @@ function getPrefix(prefix) {
return prefix || '';
}
module.exports._authCheck = authCheck;
function authCheck(socket, success) {
if (!config('auth'))
return success();

View file

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