Add backup_config settings API tests
This commit is contained in:
@@ -9,15 +9,20 @@ var async = require('async'),
|
||||
constants = require('../../constants.js'),
|
||||
database = require('../../database.js'),
|
||||
expect = require('expect.js'),
|
||||
mkdirp = require('mkdirp'),
|
||||
rimraf = require('rimraf'),
|
||||
server = require('../../server.js'),
|
||||
superagent = require('superagent');
|
||||
|
||||
var SERVER_URL = 'http://localhost:' + constants.PORT;
|
||||
|
||||
var USERNAME = 'superadmin', PASSWORD = 'Foobar?1337', EMAIL ='silly@me.com';
|
||||
var BACKUP_FOLDER = '/tmp/backup_test';
|
||||
|
||||
var token = null;
|
||||
|
||||
function setup(done) {
|
||||
mkdirp.sync(BACKUP_FOLDER);
|
||||
|
||||
async.series([
|
||||
server.start.bind(null),
|
||||
database._clear.bind(null),
|
||||
@@ -40,6 +45,8 @@ function setup(done) {
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
rimraf.sync(BACKUP_FOLDER);
|
||||
|
||||
database._clear(function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
|
||||
@@ -204,4 +211,246 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
provider: 'filesystem',
|
||||
backupFolder: '/var/backups',
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
retentionPolicy: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
intervalSecs: 24 * 60 * 60 // ~1 day
|
||||
};
|
||||
|
||||
it('can get backup_config (default)', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body).to.eql(defaultConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config without provider', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.provider;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid provider', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.provider = 'invalid provider';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config without intervalSecs', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.intervalSecs;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid intervalSecs', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.intervalSecs = 'not a number';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config without format', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.format;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid format', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'invalid format';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config without retentionPolicy', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.retentionPolicy;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid retentionPolicy', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = 'not an object';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with empty retentionPolicy', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = {};
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with retentionPolicy missing properties', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = { foo: 'bar' };
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with retentionPolicy with invalid keepWithinSecs', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = { keepWithinSecs: 'not a number' };
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid password', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.password = 1234;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.syncConcurrency = 'not a number';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid syncConcurrency', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.syncConcurrency = 0;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid acceptSelfSignedCerts', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.acceptSelfSignedCerts = 'not a boolean';
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set backup_config', function (done) {
|
||||
var tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.format = 'rsync';
|
||||
tmp.backupFolder = BACKUP_FOLDER;
|
||||
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.send(tmp)
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get backup_config', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/backup_config')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.format).to.equal('rsync');
|
||||
expect(res.body.backupFolder).to.equal(BACKUP_FOLDER);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user