Logout users without 2FA when mandatory 2fa is enabled

Fixes #803
This commit is contained in:
Girish Ramakrishnan
2021-09-17 14:32:13 -07:00
parent e8aaad976b
commit 66a907ef48
5 changed files with 73 additions and 4 deletions

View File

@@ -7,10 +7,11 @@
const common = require('./common.js'),
expect = require('expect.js'),
settings = require('../settings.js');
settings = require('../settings.js'),
tokens = require('../tokens.js');
describe('Settings', function () {
const { setup, cleanup } = common;
const { setup, cleanup, admin } = common;
before(setup);
after(cleanup);
@@ -53,6 +54,22 @@ describe('Settings', function () {
expect(enabled).to.be(false);
});
it('can get default directory config', async function () {
const directoryConfig = await settings.getDirectoryConfig();
expect(directoryConfig.lockUserProfiles).to.be(false);
expect(directoryConfig.mandatory2FA).to.be(false);
});
it('can set default directory config', async function () {
await tokens.add({ name: 'token1', identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Number.MAX_SAFE_INTEGER, lastUsedTime: null, scope: 'unused' });
let result = await tokens.listByUserId(admin.id);
expect(result.length).to.be(1); // just confirm the token was really added!
await settings.setDirectoryConfig({ mandatory2FA: true, lockUserProfiles: true });
result = await tokens.listByUserId(admin.id);
expect(result.length).to.be(0); // should have been removed by mandatory 2fa setting change
});
it('can get all values', async function () {
const allSettings = await settings.list();
expect(allSettings[settings.TIME_ZONE_KEY]).to.be.a('string');