diff --git a/tdrive/backend/node/config/custom-environment-variables.json b/tdrive/backend/node/config/custom-environment-variables.json index bb7df14f..7e7cca4d 100644 --- a/tdrive/backend/node/config/custom-environment-variables.json +++ b/tdrive/backend/node/config/custom-environment-variables.json @@ -46,6 +46,7 @@ "database": { "secret": "DB_SECRET", "type": "DB_DRIVER", + "encryption": "DB_ENCRYPTION_ALGORITHM", "mongodb": { "uri": "DB_MONGO_URI", "database": "DB_MONGO_DATABASE" diff --git a/tdrive/backend/node/config/default.json b/tdrive/backend/node/config/default.json index dbd53278..7ceafc9b 100644 --- a/tdrive/backend/node/config/default.json +++ b/tdrive/backend/node/config/default.json @@ -80,6 +80,7 @@ "database": { "secret": "", "type": "cassandra", + "encryption": "aes-256-cbc", "mongodb": { "uri": "mongodb://mongo:27017", "database": "tdrive" diff --git a/tdrive/backend/node/package.json b/tdrive/backend/node/package.json index 6af34bcc..5a247c91 100644 --- a/tdrive/backend/node/package.json +++ b/tdrive/backend/node/package.json @@ -25,7 +25,6 @@ "test": "jest --forceExit --coverage --detectOpenHandles --runInBand --verbose false | pino-pretty", "test:local": "jest --forceExit --detectOpenHandles --runInBand mock.spec.ts", "test:watch": "npm run test -- --watchAll --verbose false | pino-pretty", - "test:e2e": "node ./test/e2e/run-all.js", "test:unit": "jest test/unit --forceExit --coverage --detectOpenHandles --maxWorkers=1 --testTimeout=30000 --verbose false > coverage/coverage-report.txt", "test:unit:watch": "npm run test:unit -- --watchAll --verbose false | pino-pretty", "test:merge:json": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' json-summary", diff --git a/tdrive/backend/node/src/core/crypto/v1.ts b/tdrive/backend/node/src/core/crypto/v1.ts index 08f00ae5..d9f7bc6d 100644 --- a/tdrive/backend/node/src/core/crypto/v1.ts +++ b/tdrive/backend/node/src/core/crypto/v1.ts @@ -1,5 +1,8 @@ import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto"; import { CryptoResult } from "."; +import config from "config"; + +const algorithm = config.get("database.encryption"); export default { encrypt, @@ -14,7 +17,7 @@ function encrypt( const key = createHash("sha256").update(String(encryptionKey)).digest("base64").substr(0, 32); try { const iv = options.disableSalts ? "0000000000000000" : randomBytes(16); - const cipher = createCipheriv("aes-256-cbc", key, iv); + const cipher = createCipheriv(algorithm, key, iv); const encrypted = Buffer.concat([cipher.update(JSON.stringify(data)), cipher.final()]).toString( "hex", ); @@ -50,7 +53,7 @@ function decrypt(data: string, encryptionKey: any): CryptoResult { try { const encrypted = Buffer.from(encryptedArray[1], "hex"); - const decipher = createDecipheriv("aes-256-cbc", key, iv); + const decipher = createDecipheriv(algorithm, key, iv); const decrypt = JSON.parse( Buffer.concat([decipher.update(encrypted), decipher.final()]).toString(), ); diff --git a/tdrive/backend/node/test/e2e/run-all.js b/tdrive/backend/node/test/e2e/run-all.js deleted file mode 100644 index ba1c5b7b..00000000 --- a/tdrive/backend/node/test/e2e/run-all.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * To run all tests in local development mode: - * cd tdrive/; docker-compose -f docker-compose.dev.tests.mongo.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:e2e - * - * To run only specific tests: - * cd tdrive/; docker-compose -f docker-compose.dev.tests.mongo.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:e2e -- test/e2e/application/app-create-update.spec.ts test/e2e/application/application-events.spec.ts - */ - -const fs = require("fs"); -const path = require("path"); -const cp = require("child_process"); - -let localDevTests = process.argv.slice(2); - -//If we are in the CI tests we will run all the tests -if (process.env.CI || localDevTests.length === 0) { - localDevTests = false; -} - -if (localDevTests) { - console.log("Only this tests will be run:", localDevTests); -} else { - console.log("Will run all the tests."); -} - -function exec(command, args, debug = false) { - return new Promise(done => { - const cmd = cp.spawn(command, args, { - shell: true, - }); - - let data = ""; - let error = ""; - - cmd.stdout.on("data", function (data) { - if (debug) console.log(data.toString()); - data += data.toString() + "\n"; - }); - - cmd.stderr.on("data", function (data) { - if (debug) console.log(data.toString()); - error += data.toString() + "\n"; - }); - - cmd.on("exit", function (code) { - cmd.kill(9); - - //The delay is to make sure we get all the missing logs - setTimeout(() => done({ code, data, error }), code === 0 ? 1 : 5000); - }); - }); -} - -let srcFiles = []; -let srcPath = __dirname; -function throughDirectory(directory) { - fs.readdirSync(directory).forEach(file => { - const abs = path.join(directory, file); - if (fs.statSync(abs).isDirectory()) return throughDirectory(abs); - else return srcFiles.push(abs); - }); -} -throughDirectory(srcPath); - -srcFiles = srcFiles.filter(p => p.indexOf(".spec.ts") >= 0 || p.indexOf(".test.ts") >= 0); - -(async () => { - let failed = 0; - let passed = 0; - - let summary = ""; - - for (const path of localDevTests || srcFiles) { - const test = path.split("test/e2e/")[1]; - const testName = `test/e2e/${test}`; - const args = `${testName} --forceExit --detectOpenHandles --coverage --coverageDirectory=coverage/e2e/${test} --runInBand --testTimeout=60000 --verbose=true`; - - try { - //Show logs in the console if we are doing local dev tests - const out = await exec("jest", args.split(" "), !!localDevTests); - if (out.code !== 0) { - //To get all the logs, we run it again - console.log(`FAIL ${testName}`); - console.log(out.data); - console.log(out.error); - if (!localDevTests) await exec("jest", args.split(" "), true); - failed++; - summary += `FAIL ${testName}\n`; - } else { - passed++; - console.log(`PASS ${testName}`); - } - } catch (err) { - console.log(`ERROR ${testName}`); - console.log(`-- Error\n ${err}`); - failed++; - } - } - - console.log(`\nResults: ${passed} passed, ${failed} failed, total ${failed + passed}`); - console.log(summary); - - process.exit(failed > 0 ? 1 : 0); -})(); diff --git a/tdrive/frontend/scripts/envBuilding.js b/tdrive/frontend/scripts/envBuilding.js deleted file mode 100755 index c182e1c8..00000000 --- a/tdrive/frontend/scripts/envBuilding.js +++ /dev/null @@ -1,21 +0,0 @@ -var exec = require('child_process').exec; -const fs = require('fs'); - -var args = process.argv.slice(2); -const oldVersionDetails = args[0]; -const newVersionDetails = args[1]; -const newVersion = args[2]; - -const relativeEnvironment = './src/app/environment/version.ts'; -const relativeIndex = './public/index.html'; - -exec('cat ' + relativeEnvironment, (err, stdout, stderr) => { - stdout = stdout.replace("'" + oldVersionDetails + "'", "'" + newVersionDetails + "'"); - stdout = stdout.replace("'" + oldVersionDetails.substr(0, 3) + "'", "'" + newVersion + "'"); - fs.writeFileSync(relativeEnvironment, stdout); -}); - -exec('cat ' + relativeIndex, (err, stdout, stderr) => { - stdout = stdout.replace(oldVersionDetails, newVersionDetails); - fs.writeFileSync(relativeIndex, stdout); -});