diff --git a/js/client/modules/@arangodb/testsuites/dump.js b/js/client/modules/@arangodb/testsuites/dump.js index adddf37d89..20343cf978 100644 --- a/js/client/modules/@arangodb/testsuites/dump.js +++ b/js/client/modules/@arangodb/testsuites/dump.js @@ -26,13 +26,18 @@ // ////////////////////////////////////////////////////////////////////////////// const functionsDocumentation = { - 'dump': 'dump tests' + 'dump': 'dump tests', + 'dump_encrypted': 'encrypted dump tests', + 'dump_authentication': 'dump tests with authentication' }; const optionsDocumentation = [ + ' - `skipEncrypted` : if set to true the encryption tests are skipped' ]; const pu = require('@arangodb/process-utils'); const tu = require('@arangodb/test-utils'); +const fs = require('fs'); +const _ = require('lodash'); // const BLUE = require('internal').COLORS.COLOR_BLUE; const CYAN = require('internal').COLORS.COLOR_CYAN; @@ -42,112 +47,149 @@ const RESET = require('internal').COLORS.COLOR_RESET; // const YELLOW = require('internal').COLORS.COLOR_YELLOW; const testPaths = { - 'dump': 'js/server/tests/dump/' // we have to be fuzzy here... + 'dump': ['js/server/tests/dump/'], + 'dump_encrypted': ['js/server/tests/dump/'], + 'dump_authentication': ['js/server/tests/dump/'] }; + +function getClusterStrings(options) +{ + if (options.cluster) { + return { + cluster: '-cluster', + notCluster: '-singleserver' + }; + } else { + return { + cluster: '', + notCluster: '-cluster' + }; + } +} + // ////////////////////////////////////////////////////////////////////////////// // / @brief TEST: dump // ////////////////////////////////////////////////////////////////////////////// - -function dump (options) { +function dump_backend (options, serverAuthInfo, clientAuth, dumpOptions, which, tstFiles, afterServerStart) { let cluster; - let notCluster; + let notCluster = getClusterStrings(options).notCluster; + print(CYAN + which + ' tests...' + RESET); - if (options.cluster) { - cluster = '-cluster'; - notCluster = '-singleserver'; - } else { - cluster = ''; - notCluster = '-cluster'; - } - - const storageEngine = options.storageEngine; - - print(CYAN + 'dump tests...' + RESET); - - let instanceInfo = pu.startInstance('tcp', options, {}, 'dump'); + let instanceInfo = pu.startInstance('tcp', options, serverAuthInfo, which); if (instanceInfo === false) { - return { + let rc = { failed: 1, - dump: { - status: false, - message: 'failed to start server!' - } }; + rc[which] = { + status: false, + message: 'failed to start server!' + }; + return rc; } - + let fn = afterServerStart(instanceInfo); + print(CYAN + Date() + ': Setting up' + RESET); - + let results = { failed: 1 }; - results.setup = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-setup' + cluster + '.js')); + results.setup = tu.runInArangosh( + options, + instanceInfo, + tu.makePathUnix(fs.join(testPaths[which][0], tstFiles.dumpSetup)), + clientAuth); + results.setup.failed = 1; if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.setup.status === true)) { + (results.setup.status === true)) { results.setup.failed = 0; - print(CYAN + Date() + ': Dump and Restore - dump' + RESET); + print(CYAN + Date() + ': ' + which + ' and Restore - dump' + RESET); - results.dump = pu.run.arangoDumpRestore(options, instanceInfo, 'dump', + results.dump = pu.run.arangoDumpRestore( + dumpOptions, + instanceInfo, + 'dump', 'UnitTestsDumpSrc'); + results.dump.failed = 1; if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.dump.status === true)) { + (results.dump.status === true)) { results.dump.failed = 0; - print(CYAN + Date() + ': Dump and Restore - restore' + RESET); + print(CYAN + Date() + ': ' + which + ' and Restore - restore' + RESET); - results.restore = pu.run.arangoDumpRestore(options, instanceInfo, 'restore', + results.restore = pu.run.arangoDumpRestore( + dumpOptions, + instanceInfo, + 'restore', 'UnitTestsDumpDst'); + results.restore.failed = 1; if (pu.arangod.check.instanceAlive(instanceInfo, options) && (results.restore.status === true)) { results.restore.failed = 0; - print(CYAN + Date() + ': Dump and Restore - dump after restore' + RESET); + print(CYAN + Date() + ': ' + which + ' and Restore - dump after restore' + RESET); - results.test = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-' + storageEngine + cluster + '.js'), { - 'server.database': 'UnitTestsDumpDst' - }); + results.test = tu.runInArangosh( + options, + instanceInfo, + tu.makePathUnix( + fs.join(testPaths[which][0], + tstFiles.dumpAgain)), + { + 'server.database': 'UnitTestsDumpDst' + }); results.test.failed = 1; if (pu.arangod.check.instanceAlive(instanceInfo, options) && (results.test.status === true)) { results.test.failed = 0; - print(CYAN + Date() + ': Dump and Restore - teardown' + RESET); + print(CYAN + Date() + ': ' + which + ' and Restore - teardown' + RESET); - results.tearDown = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-teardown' + cluster + '.js')); + results.tearDown = tu.runInArangosh( + options, + instanceInfo, + tu.makePathUnix( + fs.join(testPaths[which][0], + tstFiles.dumpTearDown))); results.tearDown.failed = 1; if (pu.arangod.check.instanceAlive(instanceInfo, options) && (results.tearDown.status === true)) { results.tearDown.failed = 0; - print(CYAN + Date() + ': Dump and Restore - restoreOld' + RESET); - let restoreDir = tu.makePathUnix('js/server/tests/dump/dump' + notCluster); + if (tstFiles.dumpCheckGraph === false) { + results.failed = 0; + } else { + print(CYAN + Date() + ': Dump and Restore - restoreOld' + RESET); + let restoreDir = tu.makePathUnix('js/server/tests/dump/dump' + notCluster); - results.restoreOld = pu.run.arangoDumpRestore(options, - instanceInfo, - 'restore', - '_system', - pu.TOP_DIR, - restoreDir); - results.restoreOld.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.restoreOld.status === true)) { - results.restoreOld.failed = 0; + results.restoreOld = pu.run.arangoDumpRestore( + options, + instanceInfo, + 'restore', + '_system', + pu.TOP_DIR, + restoreDir); + results.restoreOld.failed = 1; + if (pu.arangod.check.instanceAlive(instanceInfo, options) && + (results.restoreOld.status === true)) { + results.restoreOld.failed = 0; - results.testRestoreOld = tu.runInArangosh(options, - instanceInfo, - tu.makePathUnix('js/server/tests/dump/check-graph.js')); - results.testRestoreOld.failed = 1; + results.testRestoreOld = tu.runInArangosh( + options, + instanceInfo, + fs.join(testPaths[which][0], + tstFiles.dumpCheckGraph)); - if (results.testRestoreOld.status) { - results.testRestoreOld.failed = 10; - results.failed = 0; + results.testRestoreOld.failed = 1; + + if (results.testRestoreOld.status) { + results.testRestoreOld.failed = 10; + results.failed = 0; + } } } } @@ -155,6 +197,9 @@ function dump (options) { } } } + if (fn !== undefined) { + fs.remove(fn); + } print(CYAN + 'Shutting down...' + RESET); pu.shutdownInstance(instanceInfo, options); print(CYAN + 'done.' + RESET); @@ -164,10 +209,102 @@ function dump (options) { return results; } +// ///////////////////////////////////////////////////////////////////////////// + +function dump (options) { + let c = getClusterStrings(options); + let tstFiles = { + dumpSetup: 'dump-setup' + c.cluster + '.js', + dumpAgain: 'dump-' + options.storageEngine + c.cluster + '.js', + dumpTearDown: 'dump-teardown' + c.cluster + '.js', + dumpCheckGraph: 'check-graph.js' + }; + + return dump_backend(options, {}, {}, options, 'dump', tstFiles, function(){}); +} + +function dumpAuthentication (options) { + if (options.cluster) { + if (options.extremeVerbosity) { + print(CYAN + 'Skipped because of cluster.' + RESET); + } + + return { + 'dump_authentication': { + 'status': true, + 'message': 'skipped because of cluster', + 'skipped': true + } + }; + } + + const clientAuth = { + 'server.authentication': 'true' + }; + + const serverAuthInfo = { + 'server.authentication': 'true', + 'server.jwt-secret': 'haxxmann' + }; + + let dumpAuthOpts = { + username: 'foobaruser', + password: 'foobarpasswd' + }; + + _.defaults(dumpAuthOpts, options); + let tstFiles = { + dumpSetup: 'dump-authentication-setup.js', + dumpAgain: 'dump-authentication.js', + dumpTearDown: 'dump-teardown.js', + dumpCheckGraph: false + }; + + return dump_backend(options, serverAuthInfo, clientAuth, dumpAuthOpts, 'dump_authentication', tstFiles, function(){}); + +} + +function dumpEncrypted (options) { + let c = getClusterStrings(options); + + let afterServerStart = function(instanceInfo) { + let keyFile = fs.join(instanceInfo.rootDir, 'secret-key'); + fs.write(keyFile, 'DER-HUND-der-hund-der-hund-der-h'); // must be exactly 32 chars long + return keyFile; + }; + + let dumpOptions = _.clone(options); + dumpOptions.encrypted = true; + + let tstFiles = { + dumpSetup: 'dump-setup' + c.cluster + '.js', + dumpAgain: 'dump-' + options.storageEngine + c.cluster + '.js', + dumpTearDown: 'dump-teardown' + c.cluster + '.js', + dumpCheckGraph: false + }; + + return dump_backend(options, {}, {}, dumpOptions, 'dump_encrypted', tstFiles, afterServerStart); +} + +// ///////////////////////////////////////////////////////////////////////////// exports.setup = function (testFns, defaultFns, opts, fnDocs, optionsDoc, allTestPaths) { Object.assign(allTestPaths, testPaths); testFns['dump'] = dump; defaultFns.push('dump'); + + // only register the encryption tests in the enterprise version + let version = {}; + if (global.ARANGODB_CLIENT_VERSION) { + version = global.ARANGODB_CLIENT_VERSION(true); + if (version.hasOwnProperty('enterprise-version')) { + testFns['dump_encrypted'] = dumpEncrypted; + defaultFns.push('dump_encrypted'); + } + } + + testFns['dump_authentication'] = dumpAuthentication; + defaultFns.push('dump_authentication'); + for (var attrname in functionsDocumentation) { fnDocs[attrname] = functionsDocumentation[attrname]; } for (var i = 0; i < optionsDocumentation.length; i++) { optionsDoc.push(optionsDocumentation[i]); } }; diff --git a/js/client/modules/@arangodb/testsuites/dump_authentication.js b/js/client/modules/@arangodb/testsuites/dump_authentication.js deleted file mode 100644 index 45215e13a4..0000000000 --- a/js/client/modules/@arangodb/testsuites/dump_authentication.js +++ /dev/null @@ -1,188 +0,0 @@ -/* jshint strict: false, sub: true */ -/* global print */ -'use strict'; - -// ////////////////////////////////////////////////////////////////////////////// -// / DISCLAIMER -// / -// / Copyright 2016 ArangoDB GmbH, Cologne, Germany -// / Copyright 2014 triagens GmbH, Cologne, Germany -// / -// / Licensed under the Apache License, Version 2.0 (the "License") -// / you may not use this file except in compliance with the License. -// / You may obtain a copy of the License at -// / -// / http://www.apache.org/licenses/LICENSE-2.0 -// / -// / Unless required by applicable law or agreed to in writing, software -// / distributed under the License is distributed on an "AS IS" BASIS, -// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// / See the License for the specific language governing permissions and -// / limitations under the License. -// / -// / Copyright holder is ArangoDB GmbH, Cologne, Germany -// / -// / @author Max Neunhoeffer -// ////////////////////////////////////////////////////////////////////////////// - -const fs = require('fs'); - -const functionsDocumentation = { - 'dump_authentication': 'dump tests with authentication' -}; -const optionsDocumentation = [ -]; - -const _ = require('lodash'); -const pu = require('@arangodb/process-utils'); -const tu = require('@arangodb/test-utils'); - -// const BLUE = require('internal').COLORS.COLOR_BLUE; -const CYAN = require('internal').COLORS.COLOR_CYAN; -// const GREEN = require('internal').COLORS.COLOR_GREEN; -// const RED = require('internal').COLORS.COLOR_RED; -const RESET = require('internal').COLORS.COLOR_RESET; -// const YELLOW = require('internal').COLORS.COLOR_YELLOW; - -const testPaths = { - 'dump_authentication': ['js/server/tests/dump/'] -}; - -// ////////////////////////////////////////////////////////////////////////////// -// / @brief TEST: dump_authentication -// ////////////////////////////////////////////////////////////////////////////// - -function dumpAuthentication (options) { - if (options.cluster) { - if (options.extremeVerbosity) { - print(CYAN + 'Skipped because of cluster.' + RESET); - } - - return { - 'dump_authentication': { - 'status': true, - 'message': 'skipped because of cluster', - 'skipped': true - } - }; - } - - print(CYAN + 'dump_authentication tests...' + RESET); - - const auth2 = { - 'server.authentication': 'true' - }; - - let instanceInfo = pu.startInstance('tcp', - options, { - 'server.authentication': 'true', - 'server.jwt-secret': 'haxxmann' - }, - 'dump_authentication'); - - if (instanceInfo === false) { - return { - failed: 1, - 'dump_authentication': { - status: false, - message: 'failed to start server!' - } - }; - } - - print(CYAN + Date() + ': Setting up' + RESET); - - let results = { failed: 1 }; - results.setup = tu.runInArangosh( - options, - instanceInfo, - tu.makePathUnix( - fs.join(testPaths.dump_authentication[0], - "dump-authentication-setup.js") - ), - auth2); - - results.setup.failed = 1; - - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.setup.status === true)) { - results.setup.failed = 0; - - print(CYAN + Date() + ': Dump and Restore - dump' + RESET); - - let authOpts = { - username: 'foobaruser', - password: 'foobarpasswd' - }; - - _.defaults(authOpts, options); - - results.dump = pu.run.arangoDumpRestore(authOpts, instanceInfo, 'dump', - 'UnitTestsDumpSrc'); - results.dump.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.dump.status === true)) { - results.dump.failed = 0; - - print(CYAN + Date() + ': Dump and Restore - restore' + RESET); - - results.restore = pu.run.arangoDumpRestore(authOpts, instanceInfo, 'restore', - 'UnitTestsDumpDst'); - results.restore.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.restore.status === true)) { - results.restore.failed = 0; - - print(CYAN + Date() + ': Dump and Restore - dump after restore' + RESET); - - results.test = tu.runInArangosh( - authOpts, - instanceInfo, - tu.makePathUnix(fs.join(testPaths.dump_authentication[0], - 'dump-authentication.js')), - { - 'server.database': 'UnitTestsDumpDst' - }); - - results.test.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.test.status === true)) { - results.test.failed = 0; - - print(CYAN + Date() + ': Dump and Restore - teardown' + RESET); - - results.tearDown = tu.runInArangosh( - options, - instanceInfo, - tu.makePathUnix(fs.join(testPaths.dump_authentication[0], - 'dump-teardown.js') - ), - auth2); - - results.tearDown.failed = 1; - if (results.tearDown.status) { - results.tearDown.failed = 0; - results.failed = 0; - } - } - } - } - } - - print(CYAN + 'Shutting down...' + RESET); - pu.shutdownInstance(instanceInfo, options); - print(CYAN + 'done.' + RESET); - - print(); - - return results; -} - -exports.setup = function (testFns, defaultFns, opts, fnDocs, optionsDoc, allTestPaths) { - Object.assign(allTestPaths, testPaths); - testFns['dump_authentication'] = dumpAuthentication; - defaultFns.push('dump_authentication'); - - for (var attrname in functionsDocumentation) { fnDocs[attrname] = functionsDocumentation[attrname]; } - for (var i = 0; i < optionsDocumentation.length; i++) { optionsDoc.push(optionsDocumentation[i]); } -}; diff --git a/js/client/modules/@arangodb/testsuites/dump_encrypted.js b/js/client/modules/@arangodb/testsuites/dump_encrypted.js deleted file mode 100644 index 7951e1dc22..0000000000 --- a/js/client/modules/@arangodb/testsuites/dump_encrypted.js +++ /dev/null @@ -1,167 +0,0 @@ -/* jshint strict: false, sub: true */ -/* global print */ -'use strict'; - -// ////////////////////////////////////////////////////////////////////////////// -// / DISCLAIMER -// / -// / Copyright 2016 ArangoDB GmbH, Cologne, Germany -// / Copyright 2014 triagens GmbH, Cologne, Germany -// / -// / Licensed under the Apache License, Version 2.0 (the "License") -// / you may not use this file except in compliance with the License. -// / You may obtain a copy of the License at -// / -// / http://www.apache.org/licenses/LICENSE-2.0 -// / -// / Unless required by applicable law or agreed to in writing, software -// / distributed under the License is distributed on an "AS IS" BASIS, -// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// / See the License for the specific language governing permissions and -// / limitations under the License. -// / -// / Copyright holder is ArangoDB GmbH, Cologne, Germany -// / -// / @author Jan Steemann -// ////////////////////////////////////////////////////////////////////////////// - -const functionsDocumentation = { - 'dump_encrypted': 'encrypted dump tests' -}; -const optionsDocumentation = [ - ' - `skipEncrypted` : if set to true the encryption tests are skipped' -]; - -const pu = require('@arangodb/process-utils'); -const tu = require('@arangodb/test-utils'); -const fs = require('fs'); -const _ = require('lodash'); - -const CYAN = require('internal').COLORS.COLOR_CYAN; -const RESET = require('internal').COLORS.COLOR_RESET; - -const testPaths = { - 'dump_encrypted': ['js/server/tests/dump/'] // we have to be fuzzy here... -}; - -function dumpEncrypted (options) { - let cluster; - - if (options.cluster) { - cluster = '-cluster'; - } else { - cluster = ''; - } - - if (options.skipEncrypted === true) { - print('skipping encryption tests!'); - return { - failed: 0, - dump_encrypted: { - failed: 0, - status: true, - skipped: true - } - }; - } // if - - const storageEngine = options.storageEngine; - - print(CYAN + 'Encrypted dump tests...' + RESET); - - let instanceInfo = pu.startInstance('tcp', options, {}, 'dump_encrypted'); - - if (instanceInfo === false) { - return { - failed: 1, - dump: { - status: false, - message: 'failed to start server!' - } - }; - } - - print(CYAN + Date() + ': Setting up' + RESET); - - let results = { failed: 1 }; - results.setup = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-setup' + cluster + '.js')); - results.setup.failed = 1; - - let keyFile = fs.join(instanceInfo.rootDir, 'secret-key'); - fs.write(keyFile, 'DER-HUND-der-hund-der-hund-der-h'); // must be exactly 32 chars long - - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.setup.status === true)) { - results.setup.failed = 0; - - print(CYAN + Date() + ': Encrypted Dump and Restore - dump' + RESET); - - let dumpOptions = _.clone(options); - dumpOptions.encrypted = true; - results.dump = pu.run.arangoDumpRestore(dumpOptions, instanceInfo, 'dump', - 'UnitTestsDumpSrc'); - results.dump.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.dump.status === true)) { - results.dump.failed = 0; - - print(CYAN + Date() + ': Encrypted Dump and Restore - restore' + RESET); - - results.restore = pu.run.arangoDumpRestore(dumpOptions, instanceInfo, 'restore', - 'UnitTestsDumpDst'); - results.restore.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.restore.status === true)) { - results.restore.failed = 0; - - print(CYAN + Date() + ': Encrypted Dump and Restore - dump after restore' + RESET); - - results.test = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-' + storageEngine + cluster + '.js'), { - 'server.database': 'UnitTestsDumpDst' - }); - results.test.failed = 1; - if (pu.arangod.check.instanceAlive(instanceInfo, options) && - (results.test.status === true)) { - results.test.failed = 0; - - print(CYAN + Date() + ': Encrypted Dump and Restore - teardown' + RESET); - - results.tearDown = tu.runInArangosh(options, instanceInfo, - tu.makePathUnix('js/server/tests/dump/dump-teardown' + cluster + '.js')); - results.tearDown.failed = 1; - if (results.tearDown.status) { - results.tearDown.failed = 0; - results.failed = 0; - } - } - } - } - } - - print(CYAN + 'Shutting down...' + RESET); - pu.shutdownInstance(instanceInfo, options); - print(CYAN + 'done.' + RESET); - - print(); - - return results; -} - -exports.setup = function (testFns, defaultFns, opts, fnDocs, optionsDoc, allTestPaths) { - Object.assign(allTestPaths, testPaths); - // turn off encryption tests by default. only enable them in enterprise version - opts['skipEncrypted'] = true; - let version = {}; - if (global.ARANGODB_CLIENT_VERSION) { - version = global.ARANGODB_CLIENT_VERSION(true); - if (version['enterprise-version']) { - opts['skipEncrypted'] = false; - } - } - testFns['dump_encrypted'] = dumpEncrypted; - defaultFns.push('dump_encrypted'); - for (var attrname in functionsDocumentation) { fnDocs[attrname] = functionsDocumentation[attrname]; } - for (var i = 0; i < optionsDocumentation.length; i++) { optionsDoc.push(optionsDocumentation[i]); } -};