split routes and model code into user-directory.js

This commit is contained in:
Girish Ramakrishnan
2024-06-12 10:27:59 +02:00
parent e1f87161a8
commit b4e7e394c3
10 changed files with 121 additions and 80 deletions

View File

@@ -0,0 +1,36 @@
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const common = require('./common.js'),
expect = require('expect.js'),
tokens = require('../tokens.js'),
userDirectory = require('../user-directory.js');
describe('User Directory', function () {
const { setup, cleanup, admin } = common;
before(setup);
after(cleanup);
describe('profile config', function () {
it('can get default profile config', async function () {
const profileConfig = await userDirectory.getProfileConfig();
expect(profileConfig.lockUserProfiles).to.be(false);
expect(profileConfig.mandatory2FA).to.be(false);
});
it('can set default profile config', async function () {
await tokens.add({ name: 'token1', identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Number.MAX_SAFE_INTEGER, lastUsedTime: null });
let result = await tokens.listByUserId(admin.id);
expect(result.length).to.be(1); // just confirm the token was really added!
await userDirectory.setProfileConfig({ 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
});
});
});

View File

@@ -10,7 +10,6 @@ const BoxError = require('../boxerror.js'),
expect = require('expect.js'),
safe = require('safetydance'),
speakeasy = require('speakeasy'),
tokens = require('../tokens.js'),
users = require('../users.js'),
_ = require('underscore');
@@ -199,7 +198,7 @@ describe('User', function () {
});
it('can listPaged (search)', async function () {
let results = await users.listPaged(admin.email.slice(0, 8), null, 1, 1);
const results = await users.listPaged(admin.email.slice(0, 8), null, 1, 1);
expect(results.length).to.be(1);
checkUser(results[0], admin);
});
@@ -632,24 +631,6 @@ describe('User', function () {
it('can re-create user after user was removed', createOwner);
});
describe('profile config', function () {
it('can get default profile config', async function () {
const profileConfig = await users.getProfileConfig();
expect(profileConfig.lockUserProfiles).to.be(false);
expect(profileConfig.mandatory2FA).to.be(false);
});
it('can set default profile config', async function () {
await tokens.add({ name: 'token1', identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Number.MAX_SAFE_INTEGER, lastUsedTime: null });
let result = await tokens.listByUserId(admin.id);
expect(result.length).to.be(1); // just confirm the token was really added!
await users.setProfileConfig({ 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
});
});
describe('parseDisplayName', function () {
it('parses names', function () {
const names = [