Skip to content

Commit 2f63522

Browse files
committed
refactor: remove unused test connection configurations and update related tests
1 parent 95595f5 commit 2f63522

8 files changed

Lines changed: 25 additions & 71 deletions

backend/src/helpers/constants/constants.ts

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -164,32 +164,6 @@ export const Constants = {
164164
isTestConnection: true,
165165
},
166166

167-
TEST_CONNECTION_TO_MSSQL: {
168-
title: 'MSSQL',
169-
masterEncryption: false,
170-
type: ConnectionTypesEnum.mssql,
171-
host: appConfig.testDb.mssql.host,
172-
port: appConfig.testDb.mssql.port,
173-
password: appConfig.testDb.mssql.password,
174-
username: appConfig.testDb.mssql.username,
175-
database: appConfig.testDb.mssql.database,
176-
ssh: false,
177-
ssl: false,
178-
isTestConnection: true,
179-
},
180-
181-
TEST_CONNECTION_TO_ORACLE: {
182-
title: 'Oracle',
183-
type: ConnectionTypesEnum.oracledb,
184-
host: appConfig.testDb.oracle.host,
185-
port: appConfig.testDb.oracle.port,
186-
username: appConfig.testDb.oracle.username,
187-
password: appConfig.testDb.oracle.password,
188-
database: appConfig.testDb.oracle.database,
189-
sid: appConfig.testDb.oracle.sid,
190-
isTestConnection: true,
191-
},
192-
193167
TEST_SSH_CONNECTION_TO_MYSQL: {
194168
title: 'MySQL',
195169
type: ConnectionTypesEnum.mysql,
@@ -206,30 +180,6 @@ export const Constants = {
206180
privateSSHKey: appConfig.testDb.mysql.sshKey,
207181
},
208182

209-
TEST_CONNECTION_TO_MONGO: {
210-
title: 'MongoDB',
211-
type: ConnectionTypesEnum.mongodb,
212-
host: appConfig.testDb.mongo.host,
213-
port: appConfig.testDb.mongo.port,
214-
username: appConfig.testDb.mongo.username,
215-
password: appConfig.testDb.mongo.password,
216-
database: appConfig.testDb.mongo.database,
217-
authSource: appConfig.testDb.mongo.authSource,
218-
isTestConnection: true,
219-
},
220-
221-
TEST_CONNECTION_TO_IBMBD2: {
222-
title: 'IBM DB2',
223-
type: ConnectionTypesEnum.ibmdb2,
224-
host: appConfig.testDb.ibmdb2.host,
225-
port: appConfig.testDb.ibmdb2.port,
226-
username: appConfig.testDb.ibmdb2.username,
227-
password: appConfig.testDb.ibmdb2.password,
228-
database: appConfig.testDb.ibmdb2.database,
229-
schema: appConfig.testDb.ibmdb2.schema,
230-
isTestConnection: true,
231-
},
232-
233183
REMOVED_PASSWORD_VALUE: '***',
234184
REMOVED_SENSITIVE_FIELD_IF_CHANGED: '* * * sensitive data, no logs stored * * *',
235185
REMOVED_SENSITIVE_FIELD_IF_NOT_CHANGED: '',
@@ -242,19 +192,24 @@ export const Constants = {
242192
const testConnections: Array<CreateConnectionDto | null> = Constants.getTestConnectionsFromDSN() || [];
243193
if (!testConnections.length) {
244194
testConnections.push(
245-
Constants.TEST_CONNECTION_TO_ORACLE as CreateConnectionDto,
246195
Constants.TEST_CONNECTION_TO_POSTGRES as CreateConnectionDto,
247196
Constants.TEST_SSH_CONNECTION_TO_MYSQL as unknown as CreateConnectionDto,
248-
Constants.TEST_CONNECTION_TO_MSSQL as CreateConnectionDto,
249-
Constants.TEST_CONNECTION_TO_MONGO as CreateConnectionDto,
250-
Constants.TEST_CONNECTION_TO_IBMBD2 as CreateConnectionDto,
251197
);
252198
}
253199

200+
// Only MySQL and Postgres are provided as test connections for registered users.
201+
const allowedTestConnectionTypes: Array<ConnectionTypesEnum> = [
202+
ConnectionTypesEnum.mysql,
203+
ConnectionTypesEnum.postgres,
204+
];
205+
254206
return testConnections.filter((dto): dto is CreateConnectionDto => {
255207
if (!dto) {
256208
return false;
257209
}
210+
if (!allowedTestConnectionTypes.includes(dto.type)) {
211+
return false;
212+
}
258213
const values = Object.values(dto);
259214
const nullElementIndex = values.indexOf(null);
260215
return nullElementIndex < 0;

backend/test/ava-tests/saas-tests/company-info-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ test.serial(
11321132

11331133
const result = foundUserTestConnectionsInfo.body.connections;
11341134

1135-
t.is(result.length, 5);
1135+
t.is(result.length, 3);
11361136

11371137
// toggle to off
11381138
const toggleTestConnectionsResponse = await request(app.getHttpServer())
@@ -1171,7 +1171,7 @@ test.serial(
11711171
const resultAfterToggleOnRO = JSON.parse(resultAfterToggleOn.text);
11721172

11731173
t.is(resultAfterToggleOn.status, 200);
1174-
t.is(resultAfterToggleOnRO.connections.length, 5);
1174+
t.is(resultAfterToggleOnRO.connections.length, 3);
11751175
},
11761176
);
11771177

backend/test/ava-tests/saas-tests/connection-e2e.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test.serial(`${currentTest} should return all connections for this user`, async
8787
.set('Accept', 'application/json');
8888

8989
t.is(findAllConnectionsResponse.status, 200);
90-
t.is(findAllConnectionsResponse.body.connections.length, 4);
90+
t.is(findAllConnectionsResponse.body.connections.length, 2);
9191

9292
let createConnectionResult = await request(app.getHttpServer())
9393
.post('/connection')
@@ -117,13 +117,12 @@ test.serial(`${currentTest} should return all connections for this user`, async
117117

118118
const result = findAll.body.connections;
119119

120-
t.is(result.length, 6);
120+
t.is(result.length, 4);
121121
t.is(Object.hasOwn(result[0], 'connection'), true);
122122
t.is(Object.hasOwn(result[1], 'accessLevel'), true);
123123
t.is(result[2].accessLevel, AccessLevelEnum.edit);
124124

125125
t.is(Object.hasOwn(result[3], 'accessLevel'), true);
126-
t.is(Object.hasOwn(result[4].connection, 'host'), true);
127126
t.is(Object.hasOwn(result[3].connection, 'host'), true);
128127
t.is(typeof result[0].connection.port, 'number');
129128
t.is(Object.hasOwn(result[2].connection, 'username'), true);
@@ -132,9 +131,9 @@ test.serial(`${currentTest} should return all connections for this user`, async
132131
t.is(Object.hasOwn(result[1].connection, 'updatedAt'), true);
133132
t.is(Object.hasOwn(result[2].connection, 'password'), false);
134133
t.is(Object.hasOwn(result[3].connection, 'groups'), false);
135-
const oracleConnectionIndex = result.findIndex((e) => e.connection.type === ConnectionTypesEnum.oracledb);
134+
const mysqlConnectionIndex = result.findIndex((e) => e.connection.type === ConnectionTypesEnum.mysql);
136135
// eslint-disable-next-line security/detect-object-injection
137-
t.is(Object.hasOwn(result[oracleConnectionIndex].connection, 'sid'), true);
136+
t.is(Object.hasOwn(result[mysqlConnectionIndex].connection, 'host'), true);
138137
t.pass();
139138
});
140139

backend/test/ava-tests/saas-tests/user-admin-permissions-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
7676
t.is(findAll.status, 200);
7777

7878
const result = findAll.body.connections;
79-
t.is(result.length, 5);
79+
t.is(result.length, 3);
8080
t.is(Object.hasOwn(result[0], 'connection'), true);
8181
t.is(Object.hasOwn(result[0], 'accessLevel'), true);
8282
t.is(result[0].accessLevel, AccessLevelEnum.edit);
@@ -95,7 +95,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
9595
t.is(Object.hasOwn(result[0].connection, 'groups'), false);
9696
t.is(Object.hasOwn(result[0].connection, 'author'), false);
9797
const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length;
98-
t.is(testConnectionsCount, 4);
98+
t.is(testConnectionsCount, 2);
9999
} catch (error) {
100100
console.error(error);
101101
throw error;

backend/test/ava-tests/saas-tests/user-e2e.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ test.serial(`${currentTest} should toggle test connections display mode`, async
316316
const getUserConnectionsRO = JSON.parse(getUserConnectionsResult.text);
317317
t.is(getUserConnectionsResult.status, 200);
318318
t.is(Object.hasOwn(getUserConnectionsRO, 'connections'), true);
319-
t.is(getUserConnectionsRO.connections.length, 4);
319+
t.is(getUserConnectionsRO.connections.length, 2);
320320

321321
const toggleTestConnectionsDisplayModeResult = await request(app.getHttpServer())
322322
.put('/user/test/connections/display/?displayMode=off')
@@ -448,7 +448,7 @@ test.serial(`${currentTest} should register demo user`, async (t) => {
448448
const getUserConnectionsRO = JSON.parse(getUserConnectionsResult.text);
449449
t.is(getUserConnectionsResult.status, 200);
450450
t.is(Object.hasOwn(getUserConnectionsRO, 'connections'), true);
451-
t.is(getUserConnectionsRO.connections.length, 4);
451+
t.is(getUserConnectionsRO.connections.length, 2);
452452

453453
//check user can add connection and use it
454454

@@ -512,7 +512,7 @@ test.serial(`${currentTest} should register demo user`, async (t) => {
512512
t.is(getUserCompanyRO.show_test_connections, true);
513513
t.is(Object.hasOwn(getUserCompanyRO, 'connections'), true);
514514
t.true(Array.isArray(getUserCompanyRO.connections));
515-
t.is(getUserCompanyRO.connections.length, 5);
515+
t.is(getUserCompanyRO.connections.length, 3);
516516

517517
for (const connection of getUserCompanyRO.connections) {
518518
t.is(typeof connection.id, 'string');

backend/test/ava-tests/saas-tests/user-group-edit-permissions-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
9696
t.is(findAll.status, 200);
9797

9898
const result = findAll.body.connections;
99-
t.is(result.length, 5);
99+
t.is(result.length, 3);
100100
t.is(Object.hasOwn(result[0], 'connection'), true);
101101
t.is(Object.hasOwn(result[0], 'accessLevel'), true);
102102

@@ -114,7 +114,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
114114
t.is(Object.hasOwn(result[0].connection, 'groups'), false);
115115
t.is(Object.hasOwn(result[0].connection, 'author'), false);
116116
const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length;
117-
t.is(testConnectionsCount, 4);
117+
t.is(testConnectionsCount, 2);
118118
} catch (e) {
119119
console.error(e);
120120
}

backend/test/ava-tests/saas-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
9999

100100
const result = findAll.body.connections;
101101
const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId);
102-
t.is(result.length, 5);
102+
t.is(result.length, 3);
103103
t.is(Object.hasOwn(nonTestConnection, 'connection'), true);
104104
t.is(Object.hasOwn(nonTestConnection, 'accessLevel'), true);
105105
t.is(nonTestConnection.accessLevel, AccessLevelEnum.readonly);
@@ -117,7 +117,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
117117
t.is(Object.hasOwn(result[0].connection, 'groups'), false);
118118
t.is(Object.hasOwn(result[0].connection, 'author'), false);
119119
const testConnectionsCount = result.filter((el: any) => el.connection.isTestConnection).length;
120-
t.is(testConnectionsCount, 4);
120+
t.is(testConnectionsCount, 2);
121121
} catch (e) {
122122
console.error(e);
123123
throw e;

backend/test/ava-tests/saas-tests/user-with-table-only-permissions-e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test.serial(`${currentTest} should return connections, where second user have ac
9696
t.is(findAll.status, 200);
9797

9898
const result = findAll.body.connections;
99-
t.is(result.length, 5);
99+
t.is(result.length, 3);
100100
const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId);
101101
for (const key in nonTestConnection.connection) {
102102
t.is(Constants.CONNECTION_KEYS_NONE_PERMISSION.includes(key), true);

0 commit comments

Comments
 (0)