settings: move backup settings
This commit is contained in:
@@ -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