Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const FACTORY_TEST_CONSTANTS: {
TS_SELENIUM_FACTORY_GIT_REPO_BRANCH: string;
TS_SELENIUM_SSH_PRIVATE_KEY_PATH: string;
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: string;
TS_SELENIUM_SSH_PRIVATE_KEY: string;
TS_SELENIUM_SSH_PUBLIC_KEY: string;
TS_SELENIUM_FACTORY_URL(): string;
} = {
/**
Expand Down Expand Up @@ -69,6 +71,16 @@ export const FACTORY_TEST_CONSTANTS: {
*/
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: process.env.TS_SELENIUM_SSH_PUBLIC_KEY_PATH || 'resources/factory/pub-k.txt',

/**
* sSH private key as string (from environment variable)
*/
TS_SELENIUM_SSH_PRIVATE_KEY: process.env.TS_SELENIUM_SSH_PRIVATE_KEY || '',

/**
* sSH public key as string (from environment variable)
*/
TS_SELENIUM_SSH_PUBLIC_KEY: process.env.TS_SELENIUM_SSH_PUBLIC_KEY || '',

/**
* full factory URL
*/
Expand Down
31 changes: 29 additions & 2 deletions tests/e2e/pageobjects/dashboard/UserPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export class UserPreferences {
await this.driverHelper.waitVisibility(UserPreferences.ADD_NEW_SSH_KEY_BUTTON);
}

async addSshKeys(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
async addSshKeysFromFiles(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
Logger.debug();

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

async addSshKeysFromStrings(privateSshKey: string, publicSshKey: string): Promise<void> {
Logger.debug();

if (!privateSshKey || privateSshKey === '') {
throw new Error('Private SSH key is empty or not provided');
}
if (!publicSshKey || publicSshKey === '') {
throw new Error('Public SSH key is empty or not provided');
}

Logger.info('Adding new SSH keys from strings');
await this.driverHelper.waitAndClick(UserPreferences.ADD_NEW_SSH_KEY_BUTTON);
await this.driverHelper.waitVisibility(UserPreferences.ADD_SSH_KEYS_POPUP);

Logger.info('Pasting private SSH key');
await this.driverHelper.waitAndClick(UserPreferences.PASTE_PRIVATE_SSH_KEY_FIELD);
await this.driverHelper.getAction().sendKeys(privateSshKey).perform();

Logger.info('Pasting public SSH key');
await this.driverHelper.waitAndClick(UserPreferences.PASTE_PUBLIC_SSH_KEY_FIELD);
await this.driverHelper.getAction().sendKeys(publicSshKey).perform();

await this.driverHelper.waitAndClick(UserPreferences.ADD_SSH_KEYS_BUTTON);
await this.driverHelper.waitVisibility(UserPreferences.GIT_SSH_KEY_NAME);
Logger.info('SSH keys have been added');
}

async uploadSshKeys(privateSshKeyPath: string, publicSshKeyPath: string): Promise<void> {
Logger.debug();
const privateSshKey: string = Buffer.from(fs.readFileSync(path.resolve(privateSshKeyPath), 'utf-8'), 'base64').toString('utf-8');
Expand Down
11 changes: 10 additions & 1 deletion tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
const factoryUrl: string =
FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL ||
'ssh://[email protected]/~admin/private-bb-repo.git';
const privateSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY;
const publicSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY;
const privateSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY_PATH;
const publicSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY_PATH;
let projectSection: ViewSection;
Expand All @@ -57,7 +59,14 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
test('Add SSH keys', async function (): Promise<void> {
await userPreferences.openUserPreferencesPage();
await userPreferences.openSshKeyTab();
await userPreferences.addSshKeys(privateSshKeyPath, publicSshKeyPath);
// use environment variables if available, otherwise fall back to file paths
if (privateSshKey && publicSshKey) {
Logger.info('Using SSH keys from environment variables');
await userPreferences.addSshKeysFromStrings(privateSshKey, publicSshKey);
} else {
Logger.info('Using SSH keys from file paths');
await userPreferences.addSshKeysFromFiles(privateSshKeyPath, publicSshKeyPath);
}
});
test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl);
Expand Down