From 2f635224825c207f07f5e2a69801d64e3235ccaf Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Thu, 25 Jun 2026 08:53:45 +0000 Subject: [PATCH] refactor: remove unused test connection configurations and update related tests --- backend/src/helpers/constants/constants.ts | 63 +++---------------- .../saas-tests/company-info-e2e.test.ts | 4 +- .../saas-tests/connection-e2e.test.ts | 9 ++- .../user-admin-permissions-e2e.test.ts | 4 +- .../ava-tests/saas-tests/user-e2e.test.ts | 6 +- .../user-group-edit-permissions-e2e.test.ts | 4 +- ...onnection-readonly-permissions-e2e.test.ts | 4 +- ...er-with-table-only-permissions-e2e.test.ts | 2 +- 8 files changed, 25 insertions(+), 71 deletions(-) diff --git a/backend/src/helpers/constants/constants.ts b/backend/src/helpers/constants/constants.ts index 02c3cf5f4..7dd811ced 100644 --- a/backend/src/helpers/constants/constants.ts +++ b/backend/src/helpers/constants/constants.ts @@ -164,32 +164,6 @@ export const Constants = { isTestConnection: true, }, - TEST_CONNECTION_TO_MSSQL: { - title: 'MSSQL', - masterEncryption: false, - type: ConnectionTypesEnum.mssql, - host: appConfig.testDb.mssql.host, - port: appConfig.testDb.mssql.port, - password: appConfig.testDb.mssql.password, - username: appConfig.testDb.mssql.username, - database: appConfig.testDb.mssql.database, - ssh: false, - ssl: false, - isTestConnection: true, - }, - - TEST_CONNECTION_TO_ORACLE: { - title: 'Oracle', - type: ConnectionTypesEnum.oracledb, - host: appConfig.testDb.oracle.host, - port: appConfig.testDb.oracle.port, - username: appConfig.testDb.oracle.username, - password: appConfig.testDb.oracle.password, - database: appConfig.testDb.oracle.database, - sid: appConfig.testDb.oracle.sid, - isTestConnection: true, - }, - TEST_SSH_CONNECTION_TO_MYSQL: { title: 'MySQL', type: ConnectionTypesEnum.mysql, @@ -206,30 +180,6 @@ export const Constants = { privateSSHKey: appConfig.testDb.mysql.sshKey, }, - TEST_CONNECTION_TO_MONGO: { - title: 'MongoDB', - type: ConnectionTypesEnum.mongodb, - host: appConfig.testDb.mongo.host, - port: appConfig.testDb.mongo.port, - username: appConfig.testDb.mongo.username, - password: appConfig.testDb.mongo.password, - database: appConfig.testDb.mongo.database, - authSource: appConfig.testDb.mongo.authSource, - isTestConnection: true, - }, - - TEST_CONNECTION_TO_IBMBD2: { - title: 'IBM DB2', - type: ConnectionTypesEnum.ibmdb2, - host: appConfig.testDb.ibmdb2.host, - port: appConfig.testDb.ibmdb2.port, - username: appConfig.testDb.ibmdb2.username, - password: appConfig.testDb.ibmdb2.password, - database: appConfig.testDb.ibmdb2.database, - schema: appConfig.testDb.ibmdb2.schema, - isTestConnection: true, - }, - REMOVED_PASSWORD_VALUE: '***', REMOVED_SENSITIVE_FIELD_IF_CHANGED: '* * * sensitive data, no logs stored * * *', REMOVED_SENSITIVE_FIELD_IF_NOT_CHANGED: '', @@ -242,19 +192,24 @@ export const Constants = { const testConnections: Array = Constants.getTestConnectionsFromDSN() || []; if (!testConnections.length) { testConnections.push( - Constants.TEST_CONNECTION_TO_ORACLE as CreateConnectionDto, Constants.TEST_CONNECTION_TO_POSTGRES as CreateConnectionDto, Constants.TEST_SSH_CONNECTION_TO_MYSQL as unknown as CreateConnectionDto, - Constants.TEST_CONNECTION_TO_MSSQL as CreateConnectionDto, - Constants.TEST_CONNECTION_TO_MONGO as CreateConnectionDto, - Constants.TEST_CONNECTION_TO_IBMBD2 as CreateConnectionDto, ); } + // Only MySQL and Postgres are provided as test connections for registered users. + const allowedTestConnectionTypes: Array = [ + ConnectionTypesEnum.mysql, + ConnectionTypesEnum.postgres, + ]; + return testConnections.filter((dto): dto is CreateConnectionDto => { if (!dto) { return false; } + if (!allowedTestConnectionTypes.includes(dto.type)) { + return false; + } const values = Object.values(dto); const nullElementIndex = values.indexOf(null); return nullElementIndex < 0; diff --git a/backend/test/ava-tests/saas-tests/company-info-e2e.test.ts b/backend/test/ava-tests/saas-tests/company-info-e2e.test.ts index 764e3d96f..4f2ae07fc 100644 --- a/backend/test/ava-tests/saas-tests/company-info-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/company-info-e2e.test.ts @@ -1132,7 +1132,7 @@ test.serial( const result = foundUserTestConnectionsInfo.body.connections; - t.is(result.length, 5); + t.is(result.length, 3); // toggle to off const toggleTestConnectionsResponse = await request(app.getHttpServer()) @@ -1171,7 +1171,7 @@ test.serial( const resultAfterToggleOnRO = JSON.parse(resultAfterToggleOn.text); t.is(resultAfterToggleOn.status, 200); - t.is(resultAfterToggleOnRO.connections.length, 5); + t.is(resultAfterToggleOnRO.connections.length, 3); }, ); diff --git a/backend/test/ava-tests/saas-tests/connection-e2e.test.ts b/backend/test/ava-tests/saas-tests/connection-e2e.test.ts index 3fd9a756a..f4dc88b6a 100644 --- a/backend/test/ava-tests/saas-tests/connection-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/connection-e2e.test.ts @@ -87,7 +87,7 @@ test.serial(`${currentTest} should return all connections for this user`, async .set('Accept', 'application/json'); t.is(findAllConnectionsResponse.status, 200); - t.is(findAllConnectionsResponse.body.connections.length, 4); + t.is(findAllConnectionsResponse.body.connections.length, 2); let createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -117,13 +117,12 @@ test.serial(`${currentTest} should return all connections for this user`, async const result = findAll.body.connections; - t.is(result.length, 6); + t.is(result.length, 4); t.is(Object.hasOwn(result[0], 'connection'), true); t.is(Object.hasOwn(result[1], 'accessLevel'), true); t.is(result[2].accessLevel, AccessLevelEnum.edit); t.is(Object.hasOwn(result[3], 'accessLevel'), true); - t.is(Object.hasOwn(result[4].connection, 'host'), true); t.is(Object.hasOwn(result[3].connection, 'host'), true); t.is(typeof result[0].connection.port, 'number'); t.is(Object.hasOwn(result[2].connection, 'username'), true); @@ -132,9 +131,9 @@ test.serial(`${currentTest} should return all connections for this user`, async t.is(Object.hasOwn(result[1].connection, 'updatedAt'), true); t.is(Object.hasOwn(result[2].connection, 'password'), false); t.is(Object.hasOwn(result[3].connection, 'groups'), false); - const oracleConnectionIndex = result.findIndex((e) => e.connection.type === ConnectionTypesEnum.oracledb); + const mysqlConnectionIndex = result.findIndex((e) => e.connection.type === ConnectionTypesEnum.mysql); // eslint-disable-next-line security/detect-object-injection - t.is(Object.hasOwn(result[oracleConnectionIndex].connection, 'sid'), true); + t.is(Object.hasOwn(result[mysqlConnectionIndex].connection, 'host'), true); t.pass(); }); diff --git a/backend/test/ava-tests/saas-tests/user-admin-permissions-e2e.test.ts b/backend/test/ava-tests/saas-tests/user-admin-permissions-e2e.test.ts index 58803d7e1..2c29f3e77 100644 --- a/backend/test/ava-tests/saas-tests/user-admin-permissions-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/user-admin-permissions-e2e.test.ts @@ -76,7 +76,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 3); t.is(Object.hasOwn(result[0], 'connection'), true); t.is(Object.hasOwn(result[0], 'accessLevel'), true); t.is(result[0].accessLevel, AccessLevelEnum.edit); @@ -95,7 +95,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(Object.hasOwn(result[0].connection, 'groups'), false); t.is(Object.hasOwn(result[0].connection, 'author'), false); const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length; - t.is(testConnectionsCount, 4); + t.is(testConnectionsCount, 2); } catch (error) { console.error(error); throw error; diff --git a/backend/test/ava-tests/saas-tests/user-e2e.test.ts b/backend/test/ava-tests/saas-tests/user-e2e.test.ts index 4ca5089f8..1480a2fdc 100644 --- a/backend/test/ava-tests/saas-tests/user-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/user-e2e.test.ts @@ -316,7 +316,7 @@ test.serial(`${currentTest} should toggle test connections display mode`, async const getUserConnectionsRO = JSON.parse(getUserConnectionsResult.text); t.is(getUserConnectionsResult.status, 200); t.is(Object.hasOwn(getUserConnectionsRO, 'connections'), true); - t.is(getUserConnectionsRO.connections.length, 4); + t.is(getUserConnectionsRO.connections.length, 2); const toggleTestConnectionsDisplayModeResult = await request(app.getHttpServer()) .put('/user/test/connections/display/?displayMode=off') @@ -448,7 +448,7 @@ test.serial(`${currentTest} should register demo user`, async (t) => { const getUserConnectionsRO = JSON.parse(getUserConnectionsResult.text); t.is(getUserConnectionsResult.status, 200); t.is(Object.hasOwn(getUserConnectionsRO, 'connections'), true); - t.is(getUserConnectionsRO.connections.length, 4); + t.is(getUserConnectionsRO.connections.length, 2); //check user can add connection and use it @@ -512,7 +512,7 @@ test.serial(`${currentTest} should register demo user`, async (t) => { t.is(getUserCompanyRO.show_test_connections, true); t.is(Object.hasOwn(getUserCompanyRO, 'connections'), true); t.true(Array.isArray(getUserCompanyRO.connections)); - t.is(getUserCompanyRO.connections.length, 5); + t.is(getUserCompanyRO.connections.length, 3); for (const connection of getUserCompanyRO.connections) { t.is(typeof connection.id, 'string'); diff --git a/backend/test/ava-tests/saas-tests/user-group-edit-permissions-e2e.test.ts b/backend/test/ava-tests/saas-tests/user-group-edit-permissions-e2e.test.ts index 20ae03f9a..404deafea 100644 --- a/backend/test/ava-tests/saas-tests/user-group-edit-permissions-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/user-group-edit-permissions-e2e.test.ts @@ -96,7 +96,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 3); t.is(Object.hasOwn(result[0], 'connection'), true); t.is(Object.hasOwn(result[0], 'accessLevel'), true); @@ -114,7 +114,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(Object.hasOwn(result[0].connection, 'groups'), false); t.is(Object.hasOwn(result[0].connection, 'author'), false); const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length; - t.is(testConnectionsCount, 4); + t.is(testConnectionsCount, 2); } catch (e) { console.error(e); } diff --git a/backend/test/ava-tests/saas-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts b/backend/test/ava-tests/saas-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts index ccb1600c6..1e12b5856 100644 --- a/backend/test/ava-tests/saas-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts @@ -99,7 +99,7 @@ test.serial(`${currentTest} should return connections, where second user have ac const result = findAll.body.connections; const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId); - t.is(result.length, 5); + t.is(result.length, 3); t.is(Object.hasOwn(nonTestConnection, 'connection'), true); t.is(Object.hasOwn(nonTestConnection, 'accessLevel'), true); t.is(nonTestConnection.accessLevel, AccessLevelEnum.readonly); @@ -117,7 +117,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(Object.hasOwn(result[0].connection, 'groups'), false); t.is(Object.hasOwn(result[0].connection, 'author'), false); const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length; - t.is(testConnectionsCount, 4); + t.is(testConnectionsCount, 2); } catch (e) { console.error(e); throw e; diff --git a/backend/test/ava-tests/saas-tests/user-with-table-only-permissions-e2e.test.ts b/backend/test/ava-tests/saas-tests/user-with-table-only-permissions-e2e.test.ts index 986794d1f..52d1c5e01 100644 --- a/backend/test/ava-tests/saas-tests/user-with-table-only-permissions-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/user-with-table-only-permissions-e2e.test.ts @@ -96,7 +96,7 @@ test.serial(`${currentTest} should return connections, where second user have ac t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 3); const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId); for (const key in nonTestConnection.connection) { t.is(Constants.CONNECTION_KEYS_NONE_PERMISSION.includes(key), true);