Skip to content

Commit 33a5553

Browse files
committed
added tests for certificates
1 parent da974af commit 33a5553

File tree

4 files changed

+93
-16
lines changed

4 files changed

+93
-16
lines changed

tests/e2e/pageObjects/add-redis-database-page.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class AddRedisDatabasePage {
4848
buildFromSource = Selector('a').withExactText('Build from source');
4949
buildFromDocker = Selector('a').withExactText('Docker');
5050
buildFromHomebrew = Selector('a').withExactText('Homebrew');
51+
// DROPDOWNS
52+
caCertField = Selector('[data-testid=select-ca-cert]', {timeout: 500});
53+
clientCertField = Selector('[data-testid=select-cert]', {timeout: 500});
5154

5255
/**
5356
* Adding a new redis database
@@ -61,7 +64,7 @@ export class AddRedisDatabasePage {
6164
await t
6265
.typeText(this.hostInput, parameters.host, { replace: true, paste: true })
6366
.typeText(this.portInput, parameters.port, { replace: true, paste: true })
64-
.typeText(this.databaseAliasInput, parameters.databaseName, { replace: true, paste: true });
67+
.typeText(this.databaseAliasInput, parameters.databaseName!, { replace: true, paste: true });
6568
if (!!parameters.databaseUsername) {
6669
await t.typeText(this.usernameInput, parameters.databaseUsername, { replace: true, paste: true });
6770
}
@@ -82,7 +85,7 @@ export class AddRedisDatabasePage {
8285
await t
8386
.typeText(this.hostInput, parameters.host, { replace: true, paste: true })
8487
.typeText(this.portInput, parameters.port, { replace: true, paste: true })
85-
.typeText(this.databaseAliasInput, parameters.databaseName, { replace: true, paste: true });
88+
.typeText(this.databaseAliasInput, parameters.databaseName!, { replace: true, paste: true });
8689
if (!!parameters.databaseUsername) {
8790
await t.typeText(this.usernameInput, parameters.databaseUsername, { replace: true, paste: true });
8891
}
@@ -128,8 +131,8 @@ export class AddRedisDatabasePage {
128131
await t
129132
.typeText(this.hostInput, parameters.host, { replace: true, paste: true })
130133
.typeText(this.portInput, parameters.port, { replace: true, paste: true })
131-
.typeText(this.usernameInput, parameters.databaseUsername, { replace: true, paste: true })
132-
.typeText(this.passwordInput, parameters.databasePassword, { replace: true, paste: true });
134+
.typeText(this.usernameInput, parameters.databaseUsername!, { replace: true, paste: true })
135+
.typeText(this.passwordInput, parameters.databasePassword!, { replace: true, paste: true });
133136
}
134137

135138
/**

tests/e2e/pageObjects/my-redis-databases-page.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,53 @@ export class MyRedisDatabasePage {
199199
await t.expect(Selector("div").withAttribute("data-testid", /database-status-new-*/).visible)
200200
.notOk("Database status is still visible");
201201
}
202+
203+
/**
204+
* Filter array with database objects by result field and return names
205+
* @param listOfDb Actual databases list
206+
* @param result The expected import result
207+
*/
208+
filterDatabaseListByResult(listOfDb: DatabasesForImport, result: string) {
209+
return listOfDb.filter(element => element.result === result).map(item => item.name!);
210+
}
202211
}
212+
213+
/**
214+
* Database for import parameters
215+
* @param host Host of connection
216+
* @param port Port of connection
217+
* @param name The name of connection
218+
* @param result The expected result of connection import
219+
* @param username The username of connection
220+
* @param auth Password of connection
221+
* @param cluster Is the connection has cluster
222+
* @param indName The name of coonection with index
223+
* @param db The index of connection
224+
* @param ssh_port The ssh port of connection
225+
* @param timeout_connect The connect timeout of connection
226+
* @param timeout_execute The execute timeout of connection
227+
* @param other_field The test field
228+
* @param ssl_ca_cert_path The CA certificate of connection by path
229+
* @param ssl_local_cert_path The Client certificate of connection by path
230+
* @param ssl_private_key_path The Client key of connection by path
231+
* @param ssl Is the connection have ssl
232+
*/
233+
export type DatabasesForImport = {
234+
host?: string,
235+
port?: number | string,
236+
name?: string,
237+
result?: string,
238+
username?: string,
239+
auth?: string,
240+
cluster?: boolean | string,
241+
indName?: string,
242+
db?: number,
243+
ssh_port?: number,
244+
timeout_connect?: number,
245+
timeout_execute?: number,
246+
other_field?: string,
247+
ssl_ca_cert_path?: string,
248+
ssl_local_cert_path?: string,
249+
ssl_private_key_path?: string,
250+
ssl?: boolean
251+
}[];
File renamed without changes.

tests/e2e/tests/critical-path/database/import-databases.e2e.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const racompassInvalidJson = 'racompass-invalid.json';
1717
const rdmFullJson = 'rdm-full.json';
1818
const ardmValidAno = 'ardm-valid.ano';
1919
const listOfDB = JSON.parse(fs.readFileSync(path.join('test-data', 'import-databases', 'rdm-full.json'), 'utf-8'));
20-
const dbSuccessNames = listOfDB.filter(element => element.result === 'success').map(item => item.name);
21-
const dbPartialNames = listOfDB.filter(element => element.result === 'partial').map(item => item.name);
22-
const dbFailedNames = listOfDB.filter(element => element.result === 'failed').map(item => item.name);
20+
const dbSuccessNames = myRedisDatabasePage.filterDatabaseListByResult(listOfDB, 'success');
21+
const dbPartialNames = myRedisDatabasePage.filterDatabaseListByResult(listOfDB, 'partial');
22+
const dbFailedNames = myRedisDatabasePage.filterDatabaseListByResult(listOfDB, 'failed');
2323
const dbImportedNames = [...dbSuccessNames, ...dbPartialNames];
2424
const rdmData = {
2525
type: 'rdm',
@@ -50,18 +50,19 @@ const databases = [
5050
dbData[1].dbNames[1]
5151
];
5252
const databasesToDelete = [...dbImportedNames, ...databases];
53+
const findImportedDbNameInList = async(dbName: string) => dbImportedNames.find(item => item === dbName)!;
5354

5455
fixture `Import databases`
55-
.meta({ type: 'critical_path', rte: rte.standalone })
56+
.meta({ type: 'critical_path', rte: rte.none })
5657
.page(commonUrl)
57-
.beforeEach(async() => {
58+
.beforeEach(async () => {
5859
await acceptLicenseTerms();
5960
})
60-
.afterEach(async() => {
61+
.afterEach(async () => {
6162
// Delete databases
6263
deleteStandaloneDatabasesByNamesApi(databasesToDelete);
63-
});
64-
test('Connection import from JSON', async t => {
64+
})
65+
test('Connection import modal window', async t => {
6566
const tooltipText = 'Import Database Connections';
6667
const defaultText = 'Select or drag and drop a file';
6768
const parseFailedMsg = 'Failed to add database connections';
@@ -95,8 +96,9 @@ test('Connection import from JSON', async t => {
9596
await t.click(myRedisDatabasePage.removeImportedFileBtn);
9697
await t.expect(myRedisDatabasePage.importDbDialog.textContent).contains(defaultText, 'File not removed from import input');
9798

99+
});
100+
test('Connection import from JSON', async t => {
98101
// Verify that user can import database with mandatory/optional fields
99-
await t.click(myRedisDatabasePage.closeDialogBtn);
100102
await databasesActions.importDatabase(rdmData);
101103

102104
// Fully imported table
@@ -115,14 +117,37 @@ test('Connection import from JSON', async t => {
115117

116118
await clickOnEditDatabaseByName(dbImportedNames[1]);
117119
// Verify username imported
118-
await t.expect(addRedisDatabasePage.usernameInput.value).eql(listOfDB[1].username);
120+
await t.expect(addRedisDatabasePage.usernameInput.value).eql(listOfDB[1].username, 'Username import incorrect');
119121
// Verify password imported
120122
await t.click(addRedisDatabasePage.showPasswordBtn);
121-
await t.expect(addRedisDatabasePage.passwordInput.value).eql(listOfDB[1].auth);
123+
await t.expect(addRedisDatabasePage.passwordInput.value).eql(listOfDB[1].auth, 'Password import incorrect');
122124

123125
// Verify cluster connection type imported
124126
await clickOnEditDatabaseByName(dbImportedNames[2]);
125-
await t.expect(addRedisDatabasePage.connectionType.textContent).eql(rdmData.connectionType);
127+
await t.expect(addRedisDatabasePage.connectionType.textContent).eql(rdmData.connectionType, 'Connection type import incorrect');
128+
129+
// Verify that user can import database with CA certificate
130+
await clickOnEditDatabaseByName(await findImportedDbNameInList('rdmHost+Port+Name+CaCert'));
131+
await t.expect(addRedisDatabasePage.caCertField.textContent).eql('ca', 'CA certificate import incorrect');
132+
await t.expect(addRedisDatabasePage.clientCertField.exists).notOk('Client certificate was imported');
133+
134+
// Verify that user can import database with Client certificate, Client private key
135+
await clickOnEditDatabaseByName(await findImportedDbNameInList('rdmHost+Port+Name+clientCert+privateKey'));
136+
await t.expect(addRedisDatabasePage.caCertField.textContent).eql('No CA Certificate', 'CA certificate was imported');
137+
await t.expect(addRedisDatabasePage.clientCertField.textContent).eql('client', 'Client certificate import incorrect');
138+
139+
// Verify that user can import database with all certificates
140+
await clickOnEditDatabaseByName(await findImportedDbNameInList('rdmHost+Port+Name+CaCert+clientCert+privateKey'));
141+
await t.expect(addRedisDatabasePage.caCertField.textContent).eql('ca', 'CA certificate import incorrect');
142+
await t.expect(addRedisDatabasePage.clientCertField.textContent).eql('client', 'Client certificate import incorrect');
143+
144+
// Verify that certificate not imported when any certificate field has not been parsed
145+
await clickOnEditDatabaseByName(await findImportedDbNameInList('rdmCaCertInvalidBody'));
146+
await t.expect(addRedisDatabasePage.caCertField.textContent).eql('No CA Certificate', 'CA certificate was imported');
147+
await t.expect(addRedisDatabasePage.clientCertField.exists).notOk('Client certificate was imported');
148+
await clickOnEditDatabaseByName(await findImportedDbNameInList('rdmInvalidClientCert'));
149+
await t.expect(addRedisDatabasePage.caCertField.textContent).eql('No CA Certificate', 'CA certificate was imported');
150+
await t.expect(addRedisDatabasePage.clientCertField.exists).notOk('Client certificate was imported');
126151

127152
// Verify that user can import files from Racompass, ARDM, RDM
128153
for (const db of dbData) {

0 commit comments

Comments
 (0)