Make tests work
This commit is contained in:
@@ -59,7 +59,7 @@ function setup(done) {
|
||||
},
|
||||
|
||||
function createSettings(callback) {
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' }, callback);
|
||||
settings.setBackupConfig({ provider: 'filesystem', backupFolder: '/tmp', format: 'tgz' }, callback);
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function setup(done) {
|
||||
|
||||
server.start(function (error) {
|
||||
if (error) return done(error);
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' }, done);
|
||||
settings.setBackupConfig({ provider: 'filesystem', backupFolder: '/tmp', format: 'tgz' }, done);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -290,7 +290,6 @@ describe('Cloudron', function () {
|
||||
.query({ access_token: token_1 })
|
||||
.end(function (error, result) {
|
||||
expect(result.statusCode).to.equal(200);
|
||||
console.dir(result.body);
|
||||
|
||||
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(result.body.webServerOrigin).to.eql(null);
|
||||
|
||||
@@ -12,10 +12,17 @@ var appdb = require('../../appdb.js'),
|
||||
expect = require('expect.js'),
|
||||
hock = require('hock'),
|
||||
http = require('http'),
|
||||
MockS3 = require('mock-aws-s3'),
|
||||
nock = require('nock'),
|
||||
superagent = require('superagent'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
rimraf = require('rimraf'),
|
||||
s3 = require('../../storage/s3.js'),
|
||||
safe = require('safetydance'),
|
||||
server = require('../../server.js'),
|
||||
settings = require('../../settings.js'),
|
||||
settingsdb = require('../../settingsdb.js'),
|
||||
superagent = require('superagent'),
|
||||
url = require('url');
|
||||
|
||||
var SERVER_URL = 'http://localhost:' + config.get('port');
|
||||
@@ -53,12 +60,20 @@ function setup(done) {
|
||||
},
|
||||
|
||||
function createSettings(callback) {
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix', format: 'tgz' }, callback);
|
||||
MockS3.config.basePath = path.join(os.tmpdir(), 's3-sysadmin-test-buckets/');
|
||||
|
||||
s3._mockInject(MockS3);
|
||||
|
||||
safe.fs.mkdirSync('/tmp/box-sysadmin-test');
|
||||
settingsdb.set(settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'BACKUP_TOKEN', key: 'key', prefix: 'boxid', format: 'tgz'}), callback);
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
s3._mockRestore();
|
||||
rimraf.sync(MockS3.config.basePath);
|
||||
|
||||
database._clear(function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ var assert = require('assert'),
|
||||
safe = require('safetydance'),
|
||||
shell = require('../shell.js');
|
||||
|
||||
var BACKUP_USER = config.TEST ? process.env.USER : 'yellowtent';
|
||||
|
||||
// storage api
|
||||
function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
@@ -34,6 +32,9 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
||||
assert.strictEqual(typeof sourceStream, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// in test, upload() may or may not be called via sudo script
|
||||
const BACKUP_USER = config.TEST ? (process.env.SUDO_USER || process.env.USER) : 'yellowtent';
|
||||
|
||||
mkdirp(path.dirname(backupFilePath), function (error) {
|
||||
if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
|
||||
|
||||
+9
-7
@@ -71,8 +71,6 @@ function getBackupCredentials(apiConfig, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
assert(apiConfig.accessKeyId && apiConfig.secretAccessKey);
|
||||
|
||||
if (apiConfig.provider === 'caas') return getCaasCredentials(apiConfig, callback);
|
||||
|
||||
var credentials = {
|
||||
@@ -138,7 +136,6 @@ function download(apiConfig, backupFilePath, callback) {
|
||||
var multipartDownload = new S3BlockReadStream(s3, params, { blockSize: 64 * 1024 * 1024, logCallback: debug });
|
||||
|
||||
multipartDownload.on('error', function (error) {
|
||||
// TODO ENOENT for the mock, fix upstream!
|
||||
if (error.code === 'NoSuchKey' || error.code === 'ENOENT') {
|
||||
ps.emit('error', new BackupsError(BackupsError.NOT_FOUND));
|
||||
} else {
|
||||
@@ -308,12 +305,17 @@ function testConfig(apiConfig, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (typeof apiConfig.accessKeyId !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'accessKeyId must be a string'));
|
||||
if (typeof apiConfig.secretAccessKey !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'secretAccessKey must be a string'));
|
||||
if (apiConfig.provider === 'caas') {
|
||||
if (typeof apiConfig.token !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'token must be a string'));
|
||||
} else {
|
||||
if (typeof apiConfig.accessKeyId !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'accessKeyId must be a string'));
|
||||
if (typeof apiConfig.secretAccessKey !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'secretAccessKey must be a string'));
|
||||
}
|
||||
|
||||
if (typeof apiConfig.bucket !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'bucket must be a string'));
|
||||
if (typeof apiConfig.prefix !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'prefix must be a string'));
|
||||
if ('signatureVersion' in apiConfig && typeof apiConfig.prefix !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'signatureVersion must be a string'));
|
||||
if ('endpoint' in apiConfig && typeof apiConfig.prefix !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'endpoint must be a string'));
|
||||
if ('signatureVersion' in apiConfig && typeof apiConfig.signatureVersion !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'signatureVersion must be a string'));
|
||||
if ('endpoint' in apiConfig && typeof apiConfig.endpoint !== 'string') return callback(new BackupsError(BackupsError.BAD_FIELD, 'endpoint must be a string'));
|
||||
|
||||
// attempt to upload and delete a file with new credentials
|
||||
getBackupCredentials(apiConfig, function (error, credentials) {
|
||||
|
||||
@@ -25,7 +25,8 @@ describe('backups', function () {
|
||||
provider: 'filesystem',
|
||||
key: 'enckey',
|
||||
backupFolder: '/var/backups',
|
||||
retentionSecs: 1
|
||||
retentionSecs: 1,
|
||||
format: 'tgz'
|
||||
})
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -9,18 +9,29 @@ var async = require('async'),
|
||||
config = require('../config.js'),
|
||||
database = require('../database.js'),
|
||||
expect = require('expect.js'),
|
||||
MockS3 = require('mock-aws-s3'),
|
||||
nock = require('nock'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
rimraf = require('rimraf'),
|
||||
s3 = require('../storage/s3.js'),
|
||||
settings = require('../settings.js'),
|
||||
settingsdb = require('../settingsdb.js');
|
||||
|
||||
function setup(done) {
|
||||
config.set('provider', 'caas');
|
||||
nock.cleanAll();
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
settings.initialize,
|
||||
function (callback) {
|
||||
MockS3.config.basePath = path.join(os.tmpdir(), 's3-settings-test-buckets/');
|
||||
|
||||
s3._mockInject(MockS3);
|
||||
|
||||
// a cloudron must have a backup config to startup
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'foo', key: 'key'}, function (error) {
|
||||
settingsdb.set(settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'foo', key: 'key', format: 'tgz'}), function (error) {
|
||||
expect(error).to.be(null);
|
||||
callback();
|
||||
});
|
||||
@@ -29,6 +40,9 @@ function setup(done) {
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
s3._mockRestore();
|
||||
rimraf.sync(MockS3.config.basePath);
|
||||
|
||||
async.series([
|
||||
settings.uninitialize,
|
||||
database._clear
|
||||
@@ -129,7 +143,11 @@ describe('Settings', function () {
|
||||
});
|
||||
|
||||
it('can set backup config', function (done) {
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'TOKEN' }, function (error) {
|
||||
var scope2 = nock(config.apiServerOrigin())
|
||||
.post('/api/v1/boxes/' + config.fqdn() + '/awscredentials?token=TOKEN')
|
||||
.reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } });
|
||||
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'TOKEN', format: 'tgz', prefix: 'boxid', bucket: 'bucket' }, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
|
||||
+10
-10
@@ -6,20 +6,20 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
fs = require('fs'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
readdirp = require('readdirp'),
|
||||
MockS3 = require('mock-aws-s3'),
|
||||
rimraf = require('rimraf'),
|
||||
mkdirp = require('mkdirp'),
|
||||
backups = require('../backups.js'),
|
||||
BackupsError = require('../backups.js').BackupsError,
|
||||
config = require('../config.js'),
|
||||
database = require('../database.js'),
|
||||
s3 = require('../storage/s3.js'),
|
||||
filesystem = require('../storage/filesystem.js'),
|
||||
expect = require('expect.js'),
|
||||
filesystem = require('../storage/filesystem.js'),
|
||||
fs = require('fs'),
|
||||
mkdirp = require('mkdirp'),
|
||||
MockS3 = require('mock-aws-s3'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
readdirp = require('readdirp'),
|
||||
rimraf = require('rimraf'),
|
||||
s3 = require('../storage/s3.js'),
|
||||
settings = require('../settings.js'),
|
||||
SettingsError = settings.SettingsError;
|
||||
|
||||
@@ -31,7 +31,7 @@ function setup(done) {
|
||||
settings.initialize,
|
||||
function (callback) {
|
||||
// a cloudron must have a backup config to startup
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'foo', key: 'key'}, function (error) {
|
||||
settings.setBackupConfig({ provider: 'filesystem', format: 'tgz', backupFolder: '/tmp'}, function (error) {
|
||||
expect(error).to.be(null);
|
||||
callback();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user