settings: move directory server config to it's own route
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
const common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
superagent = require('superagent');
|
||||
|
||||
describe('Directory Server API', function () {
|
||||
const { setup, cleanup, serverUrl, owner } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('user_directory_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
enabled: false,
|
||||
secret: '',
|
||||
allowlist: ''
|
||||
};
|
||||
|
||||
it('can get user_directory_config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('cannot set user_directory_config without enabled boolean', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.enabled;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set user_directory_config without secret', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.secret;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot enable user_directory_config with empty secret', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot enable user_directory_config with empty allowlist', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
tmp.secret = 'ldapsecret';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('can enable user_directory_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
tmp.secret = 'ldapsecret';
|
||||
tmp.allowlist = '1.2.3.4';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can get user_directory_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/directory_server/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql({ enabled: true, secret: 'ldapsecret', allowlist: '1.2.3.4' });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
const common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
superagent = require('superagent');
|
||||
|
||||
describe('External LDAP API', function () {
|
||||
const { setup, cleanup, serverUrl, owner } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('external_ldap', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = { provider: 'noop', autoCreate: false };
|
||||
|
||||
it('can get external_ldap (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/external_ldap/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('can set external_ldap to noop', async function () {
|
||||
const config = {
|
||||
provider: 'noop'
|
||||
};
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/external_ldap/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(config);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -79,96 +79,6 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('user_directory_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
enabled: false,
|
||||
secret: '',
|
||||
allowlist: ''
|
||||
};
|
||||
|
||||
it('can get user_directory_config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('cannot set user_directory_config without enabled boolean', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.enabled;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set user_directory_config without secret', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.secret;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot enable user_directory_config with empty secret', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot enable user_directory_config with empty allowlist', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
tmp.secret = 'ldapsecret';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('can enable user_directory_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
tmp.secret = 'ldapsecret';
|
||||
tmp.allowlist = '1.2.3.4';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can get user_directory_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/user_directory_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql({ enabled: true, secret: 'ldapsecret', allowlist: '1.2.3.4' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_policy', function () {
|
||||
const defaultPolicy = {
|
||||
retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
|
||||
Reference in New Issue
Block a user