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, {}));
|
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) {
|
async function getDynamicDnsConfig(req, res, next) {
|
||||||
const [error, enabled] = await safe(settings.getDynamicDnsConfig());
|
const [error, enabled] = await safe(settings.getDynamicDnsConfig());
|
||||||
if (error) return next(BoxError.toHttpError(error));
|
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.DYNAMIC_DNS_KEY: return getDynamicDnsConfig(req, res, next);
|
||||||
case settings.BACKUP_CONFIG_KEY: return getBackupConfig(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.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.UNSTABLE_APPS_KEY: return getUnstableAppsConfig(req, res, next);
|
||||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||||
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(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) {
|
switch (req.params.setting) {
|
||||||
case settings.DYNAMIC_DNS_KEY: return setDynamicDnsConfig(req, res, next);
|
case settings.DYNAMIC_DNS_KEY: return setDynamicDnsConfig(req, res, next);
|
||||||
case settings.EXTERNAL_LDAP_KEY: return setExternalLdapConfig(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.UNSTABLE_APPS_KEY: return setUnstableAppsConfig(req, res, next);
|
||||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||||
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(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 () {
|
describe('backup_config', function () {
|
||||||
// keep in sync with defaults in settings.js
|
// keep in sync with defaults in settings.js
|
||||||
let defaultConfig = {
|
let defaultConfig = {
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ exports = module.exports = {
|
|||||||
getExternalLdapConfig,
|
getExternalLdapConfig,
|
||||||
setExternalLdapConfig,
|
setExternalLdapConfig,
|
||||||
|
|
||||||
|
getExposedLdapConfig,
|
||||||
|
setExposedLdapConfig,
|
||||||
|
|
||||||
getRegistryConfig,
|
getRegistryConfig,
|
||||||
setRegistryConfig,
|
setRegistryConfig,
|
||||||
|
|
||||||
@@ -93,6 +96,7 @@ exports = module.exports = {
|
|||||||
BACKUP_CONFIG_KEY: 'backup_config',
|
BACKUP_CONFIG_KEY: 'backup_config',
|
||||||
SERVICES_CONFIG_KEY: 'services_config',
|
SERVICES_CONFIG_KEY: 'services_config',
|
||||||
EXTERNAL_LDAP_KEY: 'external_ldap_config',
|
EXTERNAL_LDAP_KEY: 'external_ldap_config',
|
||||||
|
EXPOSED_LDAP_KEY: 'exposed_ldap_config',
|
||||||
REGISTRY_CONFIG_KEY: 'registry_config',
|
REGISTRY_CONFIG_KEY: 'registry_config',
|
||||||
SYSINFO_CONFIG_KEY: 'sysinfo_config',
|
SYSINFO_CONFIG_KEY: 'sysinfo_config',
|
||||||
APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config',
|
APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config',
|
||||||
@@ -180,6 +184,9 @@ const gDefaults = (function () {
|
|||||||
provider: 'noop',
|
provider: 'noop',
|
||||||
autoCreate: false
|
autoCreate: false
|
||||||
};
|
};
|
||||||
|
result[exports.EXPOSED_LDAP_KEY] = {
|
||||||
|
enabled: false
|
||||||
|
};
|
||||||
result[exports.REGISTRY_CONFIG_KEY] = {
|
result[exports.REGISTRY_CONFIG_KEY] = {
|
||||||
provider: 'noop'
|
provider: 'noop'
|
||||||
};
|
};
|
||||||
@@ -490,6 +497,26 @@ async function setExternalLdapConfig(externalLdapConfig) {
|
|||||||
notifyChange(exports.EXTERNAL_LDAP_KEY, externalLdapConfig);
|
notifyChange(exports.EXTERNAL_LDAP_KEY, externalLdapConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getExposedLdapConfig() {
|
||||||
|
const value = await get(exports.EXPOSED_LDAP_KEY);
|
||||||
|
if (value === null) return gDefaults[exports.EXPOSED_LDAP_KEY];
|
||||||
|
return JSON.parse(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setExposedLdapConfig(exposedLdapConfig) {
|
||||||
|
assert.strictEqual(typeof exposedLdapConfig, 'object');
|
||||||
|
|
||||||
|
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
enabled: exposedLdapConfig.enabled
|
||||||
|
};
|
||||||
|
|
||||||
|
await set(exports.EXPOSED_LDAP_KEY, JSON.stringify(config));
|
||||||
|
|
||||||
|
notifyChange(exports.EXPOSED_LDAP_KEY, config);
|
||||||
|
}
|
||||||
|
|
||||||
async function getRegistryConfig() {
|
async function getRegistryConfig() {
|
||||||
const value = await get(exports.REGISTRY_CONFIG_KEY);
|
const value = await get(exports.REGISTRY_CONFIG_KEY);
|
||||||
if (value === null) return gDefaults[exports.REGISTRY_CONFIG_KEY];
|
if (value === null) return gDefaults[exports.REGISTRY_CONFIG_KEY];
|
||||||
|
|||||||
Reference in New Issue
Block a user