Add crud for exposed ldap settings
This commit is contained in:
@@ -137,6 +137,24 @@ async function setExternalLdapConfig(req, res, next) {
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getExposedLdapConfig(req, res, next) {
|
||||
const [error, config] = await safe(settings.getExposedLdapConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, config));
|
||||
}
|
||||
|
||||
async function setExposedLdapConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled must be a boolean'));
|
||||
|
||||
const [error] = await safe(settings.setExposedLdapConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getDynamicDnsConfig(req, res, next) {
|
||||
const [error, enabled] = await safe(settings.getDynamicDnsConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
@@ -259,6 +277,7 @@ function get(req, res, next) {
|
||||
case settings.DYNAMIC_DNS_KEY: return getDynamicDnsConfig(req, res, next);
|
||||
case settings.BACKUP_CONFIG_KEY: return getBackupConfig(req, res, next);
|
||||
case settings.EXTERNAL_LDAP_KEY: return getExternalLdapConfig(req, res, next);
|
||||
case settings.EXPOSED_LDAP_KEY: return getExposedLdapConfig(req, res, next);
|
||||
case settings.UNSTABLE_APPS_KEY: return getUnstableAppsConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(req, res, next);
|
||||
@@ -280,6 +299,7 @@ function set(req, res, next) {
|
||||
switch (req.params.setting) {
|
||||
case settings.DYNAMIC_DNS_KEY: return setDynamicDnsConfig(req, res, next);
|
||||
case settings.EXTERNAL_LDAP_KEY: return setExternalLdapConfig(req, res, next);
|
||||
case settings.EXPOSED_LDAP_KEY: return setExposedLdapConfig(req, res, next);
|
||||
case settings.UNSTABLE_APPS_KEY: return setUnstableAppsConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(req, res, next);
|
||||
|
||||
@@ -79,6 +79,55 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('exposed_ldap_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
enabled: false
|
||||
};
|
||||
|
||||
it('can get exposed_ldap_config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/exposed_ldap_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('cannot set exposed_ldap_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/exposed_ldap_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('can set exposed_ldap_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/exposed_ldap_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can get exposed_ldap_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.enabled = true;
|
||||
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/exposed_ldap_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql({ enabled: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
|
||||
Reference in New Issue
Block a user