From a44a82083e3dd3c8c30d6e2eee96e11364c247a0 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 5 Dec 2019 11:55:51 -0800 Subject: [PATCH] Add backups.testProviderConfig fields like format/retention won't be validated here since it's only testing the access credentials --- src/apps.js | 2 +- src/backups.js | 12 ++++++++++++ src/routes/apps.js | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/apps.js b/src/apps.js index b04559eb0..534c14700 100644 --- a/src/apps.js +++ b/src/apps.js @@ -1463,7 +1463,7 @@ function importApp(appId, data, auditSource, callback) { if (error) return callback(error); // TODO: make this smarter to do a read-only test and check if the file exists in the storage backend - const testBackupConfig = backupConfig ? backups.testConfig.bind(null, backupConfig) : (next) => next(); + const testBackupConfig = backupConfig ? backups.testProviderConfig.bind(null, backupConfig) : (next) => next(); testBackupConfig(function (error) { if (error) return callback(error); diff --git a/src/backups.js b/src/backups.js index af1dd1c1a..91a7f0c8a 100644 --- a/src/backups.js +++ b/src/backups.js @@ -2,6 +2,7 @@ exports = module.exports = { testConfig: testConfig, + testProviderConfig: testProviderConfig, getByStatePaged: getByStatePaged, getByAppIdPaged: getByAppIdPaged, @@ -118,6 +119,17 @@ function testConfig(backupConfig, callback) { api(backupConfig.provider).testConfig(backupConfig, callback); } + +function testProviderConfig(backupConfig, callback) { + assert.strictEqual(typeof backupConfig, 'object'); + assert.strictEqual(typeof callback, 'function'); + + var func = api(backupConfig.provider); + if (!func) return callback(new BoxError(BoxError.BAD_FIELD, 'unknown storage provider', { field: 'provider' })); + + api(backupConfig.provider).testConfig(backupConfig, callback); +} + function getByStatePaged(state, page, perPage, callback) { assert.strictEqual(typeof state, 'string'); assert(typeof page === 'number' && page > 0); diff --git a/src/routes/apps.js b/src/routes/apps.js index 2b4c16f98..c8c7eb597 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -406,7 +406,6 @@ function importApp(req, res, next) { if (req.body.backupConfig) { if (typeof backupConfig.provider !== 'string') return next(new HttpError(400, 'provider is required')); if ('key' in backupConfig && typeof backupConfig.key !== 'string') return next(new HttpError(400, 'key must be a string')); - if (typeof backupConfig.format !== 'string') return next(new HttpError(400, 'format must be a string')); if ('acceptSelfSignedCerts' in backupConfig && typeof backupConfig.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean')); // testing backup config can take sometime