mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(cloudcmd) authCheck
This commit is contained in:
parent
c5a4914103
commit
65cbc8455a
2 changed files with 50 additions and 1 deletions
|
|
@ -100,7 +100,7 @@ function getPrefix(prefix) {
|
|||
return prefix || '';
|
||||
}
|
||||
|
||||
|
||||
module.exports._authCheck = authCheck;
|
||||
function authCheck(socket, success) {
|
||||
if (!config('auth'))
|
||||
return success();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue