Skip to content

Commit 83f7499

Browse files
authored
[Test] Support SSH keys from environment variables in SshUrlNoOauthPatFactory E2E test (#23634)
1 parent 0363983 commit 83f7499

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const FACTORY_TEST_CONSTANTS: {
2727
TS_SELENIUM_FACTORY_GIT_REPO_BRANCH: string;
2828
TS_SELENIUM_SSH_PRIVATE_KEY_PATH: string;
2929
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: string;
30+
TS_SELENIUM_SSH_PRIVATE_KEY: string;
31+
TS_SELENIUM_SSH_PUBLIC_KEY: string;
3032
TS_SELENIUM_FACTORY_URL(): string;
3133
} = {
3234
/**
@@ -69,6 +71,16 @@ export const FACTORY_TEST_CONSTANTS: {
6971
*/
7072
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: process.env.TS_SELENIUM_SSH_PUBLIC_KEY_PATH || 'resources/factory/pub-k.txt',
7173

74+
/**
75+
* sSH private key as string (from environment variable)
76+
*/
77+
TS_SELENIUM_SSH_PRIVATE_KEY: process.env.TS_SELENIUM_SSH_PRIVATE_KEY || '',
78+
79+
/**
80+
* sSH public key as string (from environment variable)
81+
*/
82+
TS_SELENIUM_SSH_PUBLIC_KEY: process.env.TS_SELENIUM_SSH_PUBLIC_KEY || '',
83+
7284
/**
7385
* full factory URL
7486
*/

tests/e2e/pageobjects/dashboard/UserPreferences.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ export class UserPreferences {
136136
await this.driverHelper.waitVisibility(UserPreferences.ADD_NEW_SSH_KEY_BUTTON);
137137
}
138138

139-
async addSshKeys(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
139+
async addSshKeysFromFiles(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
140140
Logger.debug();
141141

142-
Logger.info('Adding new SSH keys');
142+
Logger.info('Adding new SSH keys from files');
143143
await this.driverHelper.waitAndClick(UserPreferences.ADD_NEW_SSH_KEY_BUTTON);
144144
await this.driverHelper.waitVisibility(UserPreferences.ADD_SSH_KEYS_POPUP);
145145
await this.uploadSshKeys(privateSshKeyPath, publicSshKeyPath);
@@ -148,6 +148,33 @@ export class UserPreferences {
148148
Logger.info('SSH keys have been added');
149149
}
150150

151+
async addSshKeysFromStrings(privateSshKey: string, publicSshKey: string): Promise<void> {
152+
Logger.debug();
153+
154+
if (!privateSshKey || privateSshKey === '') {
155+
throw new Error('Private SSH key is empty or not provided');
156+
}
157+
if (!publicSshKey || publicSshKey === '') {
158+
throw new Error('Public SSH key is empty or not provided');
159+
}
160+
161+
Logger.info('Adding new SSH keys from strings');
162+
await this.driverHelper.waitAndClick(UserPreferences.ADD_NEW_SSH_KEY_BUTTON);
163+
await this.driverHelper.waitVisibility(UserPreferences.ADD_SSH_KEYS_POPUP);
164+
165+
Logger.info('Pasting private SSH key');
166+
await this.driverHelper.waitAndClick(UserPreferences.PASTE_PRIVATE_SSH_KEY_FIELD);
167+
await this.driverHelper.getAction().sendKeys(privateSshKey).perform();
168+
169+
Logger.info('Pasting public SSH key');
170+
await this.driverHelper.waitAndClick(UserPreferences.PASTE_PUBLIC_SSH_KEY_FIELD);
171+
await this.driverHelper.getAction().sendKeys(publicSshKey).perform();
172+
173+
await this.driverHelper.waitAndClick(UserPreferences.ADD_SSH_KEYS_BUTTON);
174+
await this.driverHelper.waitVisibility(UserPreferences.GIT_SSH_KEY_NAME);
175+
Logger.info('SSH keys have been added');
176+
}
177+
151178
async uploadSshKeys(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
152179
Logger.debug();
153180
const privateSshKey: string = Buffer.from(fs.readFileSync(path.resolve(privateSshKeyPath), 'utf-8'), 'base64').toString('utf-8');

tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
3636
const factoryUrl: string =
3737
FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL ||
3838
'ssh://[email protected]/~admin/private-bb-repo.git';
39+
const privateSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY;
40+
const publicSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY;
3941
const privateSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY_PATH;
4042
const publicSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY_PATH;
4143
let projectSection: ViewSection;
@@ -57,7 +59,14 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
5759
test('Add SSH keys', async function (): Promise<void> {
5860
await userPreferences.openUserPreferencesPage();
5961
await userPreferences.openSshKeyTab();
60-
await userPreferences.addSshKeys(privateSshKeyPath, publicSshKeyPath);
62+
// use environment variables if available, otherwise fall back to file paths
63+
if (privateSshKey && publicSshKey) {
64+
Logger.info('Using SSH keys from environment variables');
65+
await userPreferences.addSshKeysFromStrings(privateSshKey, publicSshKey);
66+
} else {
67+
Logger.info('Using SSH keys from file paths');
68+
await userPreferences.addSshKeysFromFiles(privateSshKeyPath, publicSshKeyPath);
69+
}
6170
});
6271
test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> {
6372
await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl);

0 commit comments

Comments
 (0)