authelia/test/unitary/routes/test_deny_not_logged.js

84 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-01-21 16:41:06 +00:00
var sinon = require('sinon');
var Promise = require('bluebird');
var assert = require('assert');
var denyNotLogged = require('../../../src/lib/routes/deny_not_logged');
describe('test not logged', function() {
2017-01-28 00:32:25 +00:00
it('should return status code 403 when auth_session has not been previously created', function() {
2017-01-21 16:41:06 +00:00
return test_auth_session_not_created();
});
2017-01-28 00:32:25 +00:00
it('should return status code 403 when auth_session has failed first factor', function() {
2017-01-21 16:41:06 +00:00
return test_auth_first_factor_not_validated();
});
it('should return status code 204 when auth_session has succeeded first factor stage', function() {
return test_auth_with_first_factor_validated();
});
});
function test_auth_session_not_created() {
return new Promise(function(resolve, reject) {
var send = sinon.spy(resolve);
var status = sinon.spy(function(code) {
2017-01-28 00:32:25 +00:00
assert.equal(403, code);
2017-01-21 16:41:06 +00:00
});
var req = {
session: {}
}
var res = {
send: send,
status: status
}
denyNotLogged(reject)(req, res);
});
}
function test_auth_first_factor_not_validated() {
return new Promise(function(resolve, reject) {
var send = sinon.spy(resolve);
var status = sinon.spy(function(code) {
2017-01-28 00:32:25 +00:00
assert.equal(403, code);
2017-01-21 16:41:06 +00:00
});
var req = {
session: {
auth_session: {
first_factor: false,
second_factor: false
}
}
}
var res = {
send: send,
status: status
}
denyNotLogged(reject)(req, res);
});
}
function test_auth_with_first_factor_validated() {
return new Promise(function(resolve, reject) {
var req = {
session: {
auth_session: {
first_factor: true,
second_factor: false
}
}
}
var res = {
send: sinon.spy(),
status: sinon.spy()
}
denyNotLogged(resolve)(req, res);
});
}