settings: move backup settings
This commit is contained in:
+81
-1
@@ -6,7 +6,12 @@ exports = module.exports = {
|
||||
create,
|
||||
cleanup,
|
||||
remount,
|
||||
getMountStatus
|
||||
getMountStatus,
|
||||
|
||||
getConfig,
|
||||
setConfig,
|
||||
getPolicy,
|
||||
setPolicy
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -70,3 +75,78 @@ async function getMountStatus(req, res, next) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
next(new HttpSuccess(200, mountStatus));
|
||||
}
|
||||
|
||||
async function getConfig(req, res, next) {
|
||||
const [error, backupConfig] = await safe(backups.getConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
|
||||
}
|
||||
|
||||
async function setConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
||||
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be a string'));
|
||||
if ('encryptedFilenames' in req.body && typeof req.body.encryptedFilenames !== 'boolean') return next(new HttpError(400, 'encryptedFilenames must be a boolean'));
|
||||
|
||||
if (req.body.limits) {
|
||||
if (typeof req.body.limits !== 'object') return next(new HttpError(400, 'limits must be an object'));
|
||||
const limits = req.body;
|
||||
|
||||
if ('syncConcurrency' in limits) {
|
||||
if (typeof limits.syncConcurrency !== 'number') return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
||||
if (limits.syncConcurrency < 1) return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('copyConcurrency' in limits) {
|
||||
if (typeof limits.copyConcurrency !== 'number') return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
||||
if (limits.copyConcurrency < 1) return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('downloadConcurrency' in limits) {
|
||||
if (typeof limits.downloadConcurrency !== 'number') return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
||||
if (limits.downloadConcurrency < 1) return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('deleteConcurrency' in limits) {
|
||||
if (typeof limits.deleteConcurrency !== 'number') return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
||||
if (limits.deleteConcurrency < 1) return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('uploadPartSize' in limits) {
|
||||
if (typeof limits.uploadPartSize !== 'number') return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
||||
if (limits.uploadPartSize < 1) return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
||||
}
|
||||
|
||||
if ('memoryLimit' in limits && typeof limits.memoryLimit !== 'number') return next(new HttpError(400, 'memoryLimit must be a positive integer'));
|
||||
}
|
||||
|
||||
if (typeof req.body.format !== 'string') return next(new HttpError(400, 'format must be a string'));
|
||||
if ('acceptSelfSignedCerts' in req.body && typeof req.body.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean'));
|
||||
|
||||
if ('mountOptions' in req.body && typeof req.body.mountOptions !== 'object') return next(new HttpError(400, 'mountOptions must be a object'));
|
||||
|
||||
// testing the backup using put/del takes a bit of time at times
|
||||
req.clearTimeout();
|
||||
|
||||
const [error] = await safe(backups.setConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getPolicy(req, res, next) {
|
||||
const [error, policy] = await safe(backups.getPolicy());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { policy }));
|
||||
}
|
||||
|
||||
async function setPolicy(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.schedule !== 'string') return next(new HttpError(400, 'schedule is required'));
|
||||
if (!req.body.retention || typeof req.body.retention !== 'object') return next(new HttpError(400, 'retention is required'));
|
||||
|
||||
const [error] = await safe(backups.setPolicy(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ exports = module.exports = {
|
||||
set,
|
||||
get,
|
||||
|
||||
// owner only settings
|
||||
setBackupConfig,
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
backups = require('../backups.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
docker = require('../docker.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
@@ -17,81 +14,6 @@ const assert = require('assert'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js');
|
||||
|
||||
async function getBackupConfig(req, res, next) {
|
||||
const [error, backupConfig] = await safe(settings.getBackupConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
|
||||
}
|
||||
|
||||
async function setBackupConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
||||
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be a string'));
|
||||
if ('encryptedFilenames' in req.body && typeof req.body.encryptedFilenames !== 'boolean') return next(new HttpError(400, 'encryptedFilenames must be a boolean'));
|
||||
|
||||
if (req.body.limits) {
|
||||
if (typeof req.body.limits !== 'object') return next(new HttpError(400, 'limits must be an object'));
|
||||
const limits = req.body;
|
||||
|
||||
if ('syncConcurrency' in limits) {
|
||||
if (typeof limits.syncConcurrency !== 'number') return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
||||
if (limits.syncConcurrency < 1) return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('copyConcurrency' in limits) {
|
||||
if (typeof limits.copyConcurrency !== 'number') return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
||||
if (limits.copyConcurrency < 1) return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('downloadConcurrency' in limits) {
|
||||
if (typeof limits.downloadConcurrency !== 'number') return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
||||
if (limits.downloadConcurrency < 1) return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('deleteConcurrency' in limits) {
|
||||
if (typeof limits.deleteConcurrency !== 'number') return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
||||
if (limits.deleteConcurrency < 1) return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
||||
}
|
||||
if ('uploadPartSize' in limits) {
|
||||
if (typeof limits.uploadPartSize !== 'number') return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
||||
if (limits.uploadPartSize < 1) return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
||||
}
|
||||
|
||||
if ('memoryLimit' in limits && typeof limits.memoryLimit !== 'number') return next(new HttpError(400, 'memoryLimit must be a positive integer'));
|
||||
}
|
||||
|
||||
if (typeof req.body.format !== 'string') return next(new HttpError(400, 'format must be a string'));
|
||||
if ('acceptSelfSignedCerts' in req.body && typeof req.body.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean'));
|
||||
|
||||
if ('mountOptions' in req.body && typeof req.body.mountOptions !== 'object') return next(new HttpError(400, 'mountOptions must be a object'));
|
||||
|
||||
// testing the backup using put/del takes a bit of time at times
|
||||
req.clearTimeout();
|
||||
|
||||
const [error] = await safe(settings.setBackupConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getBackupPolicy(req, res, next) {
|
||||
const [error, policy] = await safe(settings.getBackupPolicy());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { policy }));
|
||||
}
|
||||
|
||||
async function setBackupPolicy(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.schedule !== 'string') return next(new HttpError(400, 'schedule is required'));
|
||||
if (!req.body.retention || typeof req.body.retention !== 'object') return next(new HttpError(400, 'retention is required'));
|
||||
|
||||
const [error] = await safe(settings.setBackupPolicy(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getRegistryConfig(req, res, next) {
|
||||
const [error, registryConfig] = await safe(settings.getRegistryConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
@@ -120,8 +42,6 @@ function get(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.setting, 'string');
|
||||
|
||||
switch (req.params.setting) {
|
||||
case settings.BACKUP_POLICY_KEY: return getBackupPolicy(req, res, next);
|
||||
case settings.BACKUP_CONFIG_KEY: return getBackupConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||
|
||||
default: return next(new HttpError(404, 'No such setting'));
|
||||
@@ -132,7 +52,6 @@ function set(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
switch (req.params.setting) {
|
||||
case settings.BACKUP_POLICY_KEY: return setBackupPolicy(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||
|
||||
default: return next(new HttpError(404, 'No such setting'));
|
||||
|
||||
@@ -5,20 +5,249 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('./common.js'),
|
||||
const backups = require('../../backups.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
settings = require('../../settings.js'),
|
||||
superagent = require('superagent');
|
||||
|
||||
const BACKUP_FOLDER = '/tmp/backup_test';
|
||||
|
||||
describe('Backups API', function () {
|
||||
const { setup, cleanup, waitForTask, serverUrl, owner } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('backup_policy', function () {
|
||||
const defaultPolicy = {
|
||||
retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
schedule: '00 00 23 * * *' // every day at 11pm
|
||||
};
|
||||
|
||||
it('cannot set backup_policy without schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.schedule;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.schedule = 'not a pattern';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy without retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.retention;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = 'not an object';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with empty retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = {};
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention missing properties', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { foo: 'bar' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention with invalid keepWithinSecs', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { keepWithinSecs: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
provider: 'filesystem',
|
||||
backupFolder: '/var/backups',
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
};
|
||||
|
||||
it('can get backup_config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without provider', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.provider;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid provider', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.provider = 'invalid provider';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without format', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.format;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid format', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'invalid format';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid password', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.password = 1234;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.limits = { syncConcurrency: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.limits = { syncConcurrency: 0 };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid acceptSelfSignedCerts', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.acceptSelfSignedCerts = 'not a boolean';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('can set backup_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'rsync';
|
||||
tmp.backupFolder = BACKUP_FOLDER;
|
||||
tmp.limits = { copyConcurrency: 34 };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can get backup_config', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/backups/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body.format).to.equal('rsync');
|
||||
expect(response.body.backupFolder).to.equal(BACKUP_FOLDER);
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', function () {
|
||||
before(async function () {
|
||||
await settings.setBackupConfig({
|
||||
await backups.setConfig({
|
||||
provider: 'filesystem',
|
||||
backupFolder: '/tmp/backups',
|
||||
format: 'tgz',
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
'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');
|
||||
|
||||
const BACKUP_FOLDER = '/tmp/backup_test';
|
||||
|
||||
describe('Settings API', function () {
|
||||
const { setup, cleanup, serverUrl, owner } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('backup_policy', function () {
|
||||
const defaultPolicy = {
|
||||
retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
schedule: '00 00 23 * * *' // every day at 11pm
|
||||
};
|
||||
|
||||
it('cannot set backup_policy without schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.schedule;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.schedule = 'not a pattern';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy without retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.retention;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = 'not an object';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with empty retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = {};
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention missing properties', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { foo: 'bar' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention with invalid keepWithinSecs', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { keepWithinSecs: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
provider: 'filesystem',
|
||||
backupFolder: '/var/backups',
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
};
|
||||
|
||||
it('can get backup_config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql(defaultConfig);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without provider', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.provider;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid provider', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.provider = 'invalid provider';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without format', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.format;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid format', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'invalid format';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid password', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.password = 1234;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.limits = { syncConcurrency: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.limits = { syncConcurrency: 0 };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid acceptSelfSignedCerts', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.acceptSelfSignedCerts = 'not a boolean';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('can set backup_config', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'rsync';
|
||||
tmp.backupFolder = BACKUP_FOLDER;
|
||||
tmp.limits = { copyConcurrency: 34 };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can get backup_config', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body.format).to.equal('rsync');
|
||||
expect(response.body.backupFolder).to.equal(BACKUP_FOLDER);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user