From 824bf1a69f2797479783867237efd3fef39c165d Mon Sep 17 00:00:00 2001 From: ddrechse Date: Wed, 10 Jan 2024 13:29:58 -0500 Subject: [PATCH 1/4] Add databaseAdapter support for tests, REDACT databaseAdapter info when logging --- spec/helper.js | 16 +++++++++------- src/cli/utils/runner.js | 7 +------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/spec/helper.js b/spec/helper.js index e4d93282fc..b20c19513e 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -35,6 +35,7 @@ process.noDeprecation = true; const cache = require('../lib/cache').default; const defaults = require('../lib/defaults').default; const ParseServer = require('../lib/index').ParseServer; +const loadAdapter = require('../lib/Adapters/AdapterLoader').loadAdapter; const path = require('path'); const TestUtils = require('../lib/TestUtils'); const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter') @@ -53,7 +54,10 @@ let databaseAdapter; let databaseURI; // need to bind for mocking mocha -if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { +if (process.env.PARSE_SERVER_DATABASE_ADAPTER) { + databaseAdapter = JSON.parse(process.env.PARSE_SERVER_DATABASE_ADAPTER); + databaseAdapter = loadAdapter(databaseAdapter); +} else if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { databaseURI = process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI; databaseAdapter = new PostgresStorageAdapter({ uri: databaseURI, @@ -433,8 +437,8 @@ try { // Fetch test exclusion list testExclusionList = require('./testExclusionList.json'); console.log(`Using test exclusion list with ${testExclusionList.length} entries`); -} catch(error) { - if(error.code !== 'MODULE_NOT_FOUND') { +} catch (error) { + if (error.code !== 'MODULE_NOT_FOUND') { throw error; } } @@ -444,10 +448,8 @@ global.it_id = (id, func) => { if (testExclusionList.includes(id)) { return xit; } else { - if(func === undefined) - return it; - else - return func; + if (func === undefined) return it; + else return func; } }; diff --git a/src/cli/utils/runner.js b/src/cli/utils/runner.js index 4869111d64..89a7c4cdf7 100644 --- a/src/cli/utils/runner.js +++ b/src/cli/utils/runner.js @@ -5,12 +5,7 @@ function logStartupOptions(options) { return; } // Keys that may include sensitive information that will be redacted in logs - const keysToRedact = [ - 'databaseURI', - 'masterKey', - 'maintenanceKey', - 'push', - ]; + const keysToRedact = ['databaseAdapter', 'databaseURI', 'masterKey', 'maintenanceKey', 'push']; for (const key in options) { let value = options[key]; if (keysToRedact.includes(key)) { From e60f41623fbe788af9163ca1210a5111069a0401 Mon Sep 17 00:00:00 2001 From: ddrechse Date: Wed, 17 Jan 2024 10:44:07 -0500 Subject: [PATCH 2/4] Simplify --- spec/helper.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/helper.js b/spec/helper.js index b20c19513e..e3650f1652 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -448,8 +448,7 @@ global.it_id = (id, func) => { if (testExclusionList.includes(id)) { return xit; } else { - if (func === undefined) return it; - else return func; + return func || it; } }; From 426510ca81a7455892bbadc64183b0e8b05f817e Mon Sep 17 00:00:00 2001 From: ddrechse Date: Tue, 14 May 2024 15:02:45 -0400 Subject: [PATCH 3/4] Add databaseAdapter test --- spec/AdapterLoader.spec.js | 19 +++++++++++++++++++ spec/support/MockDatabaseAdapter.js | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 spec/support/MockDatabaseAdapter.js diff --git a/spec/AdapterLoader.spec.js b/spec/AdapterLoader.spec.js index 72c6ef333c..9ec85b6fb7 100644 --- a/spec/AdapterLoader.spec.js +++ b/spec/AdapterLoader.spec.js @@ -142,6 +142,25 @@ describe('AdapterLoader', () => { }).not.toThrow(); }); + it('should load custom database adapter from config', done => { + const adapterPath = require('path').resolve('./spec/support/MockDatabaseAdapter'); + const options = { + databaseURI: 'oracledb://user:password@localhost:1521/freepdb1', + collectionPrefix: '', + }; + const databaseAdapterOptions = { + adapter: adapterPath, + options, + }; + expect(() => { + const databaseAdapter = loadAdapter(databaseAdapterOptions); + expect(databaseAdapter).not.toBe(undefined); + expect(databaseAdapter.options).toEqual(options); + expect(databaseAdapter.getDatabaseURI()).toEqual(options.databaseURI); + }).not.toThrow(); + done(); + }); + it('should load file adapter from direct passing', done => { spyOn(console, 'warn').and.callFake(() => {}); const mockFilesAdapter = new MockFilesAdapter('key', 'secret', 'bucket'); diff --git a/spec/support/MockDatabaseAdapter.js b/spec/support/MockDatabaseAdapter.js new file mode 100644 index 0000000000..136b4a086d --- /dev/null +++ b/spec/support/MockDatabaseAdapter.js @@ -0,0 +1,9 @@ +module.exports = function (options) { + return { + options: options, + send: function () {}, + getDatabaseURI: function () { + return options.databaseURI; + }, + }; +}; From f6f317bea5bae510fb4ad2da1c563b85a391c4d2 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Wed, 15 May 2024 00:16:05 +0200 Subject: [PATCH 4/4] refactor Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- src/cli/utils/runner.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cli/utils/runner.js b/src/cli/utils/runner.js index 89a7c4cdf7..ed66cdfef8 100644 --- a/src/cli/utils/runner.js +++ b/src/cli/utils/runner.js @@ -5,7 +5,13 @@ function logStartupOptions(options) { return; } // Keys that may include sensitive information that will be redacted in logs - const keysToRedact = ['databaseAdapter', 'databaseURI', 'masterKey', 'maintenanceKey', 'push']; + const keysToRedact = [ + 'databaseAdapter', + 'databaseURI', + 'masterKey', + 'maintenanceKey', + 'push', + ]; for (const key in options) { let value = options[key]; if (keysToRedact.includes(key)) {