♻️Removed unused files and move unused encryption algorithm to co configuration (#513)

This commit is contained in:
Anton Shepilov
2024-05-07 18:24:53 +02:00
committed by GitHub
parent 24da0c8cfb
commit ac950f0e87
6 changed files with 7 additions and 128 deletions
@@ -46,6 +46,7 @@
"database": { "database": {
"secret": "DB_SECRET", "secret": "DB_SECRET",
"type": "DB_DRIVER", "type": "DB_DRIVER",
"encryption": "DB_ENCRYPTION_ALGORITHM",
"mongodb": { "mongodb": {
"uri": "DB_MONGO_URI", "uri": "DB_MONGO_URI",
"database": "DB_MONGO_DATABASE" "database": "DB_MONGO_DATABASE"
+1
View File
@@ -80,6 +80,7 @@
"database": { "database": {
"secret": "", "secret": "",
"type": "cassandra", "type": "cassandra",
"encryption": "aes-256-cbc",
"mongodb": { "mongodb": {
"uri": "mongodb://mongo:27017", "uri": "mongodb://mongo:27017",
"database": "tdrive" "database": "tdrive"
-1
View File
@@ -25,7 +25,6 @@
"test": "jest --forceExit --coverage --detectOpenHandles --runInBand --verbose false | pino-pretty", "test": "jest --forceExit --coverage --detectOpenHandles --runInBand --verbose false | pino-pretty",
"test:local": "jest --forceExit --detectOpenHandles --runInBand mock.spec.ts", "test:local": "jest --forceExit --detectOpenHandles --runInBand mock.spec.ts",
"test:watch": "npm run test -- --watchAll --verbose false | pino-pretty", "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": "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: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", "test:merge:json": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' json-summary",
+5 -2
View File
@@ -1,5 +1,8 @@
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto"; import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto";
import { CryptoResult } from "."; import { CryptoResult } from ".";
import config from "config";
const algorithm = config.get<string>("database.encryption");
export default { export default {
encrypt, encrypt,
@@ -14,7 +17,7 @@ function encrypt(
const key = createHash("sha256").update(String(encryptionKey)).digest("base64").substr(0, 32); const key = createHash("sha256").update(String(encryptionKey)).digest("base64").substr(0, 32);
try { try {
const iv = options.disableSalts ? "0000000000000000" : randomBytes(16); 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( const encrypted = Buffer.concat([cipher.update(JSON.stringify(data)), cipher.final()]).toString(
"hex", "hex",
); );
@@ -50,7 +53,7 @@ function decrypt(data: string, encryptionKey: any): CryptoResult {
try { try {
const encrypted = Buffer.from(encryptedArray[1], "hex"); 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( const decrypt = JSON.parse(
Buffer.concat([decipher.update(encrypted), decipher.final()]).toString(), Buffer.concat([decipher.update(encrypted), decipher.final()]).toString(),
); );
-104
View File
@@ -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);
})();
-21
View File
@@ -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);
});