diff --git a/tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts b/tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts index d66b9241533..1f844e6a5d2 100644 --- a/tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts @@ -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; } = { /** @@ -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 */ diff --git a/tests/e2e/pageobjects/dashboard/UserPreferences.ts b/tests/e2e/pageobjects/dashboard/UserPreferences.ts index bf1f0eee077..5ae19516391 100644 --- a/tests/e2e/pageobjects/dashboard/UserPreferences.ts +++ b/tests/e2e/pageobjects/dashboard/UserPreferences.ts @@ -136,10 +136,10 @@ export class UserPreferences { await this.driverHelper.waitVisibility(UserPreferences.ADD_NEW_SSH_KEY_BUTTON); } - async addSshKeys(privateSshKeyPath: string, publicSshKeyPath: string): Promise { + async addSshKeysFromFiles(privateSshKeyPath: string, publicSshKeyPath: string): Promise { 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); @@ -148,6 +148,33 @@ export class UserPreferences { Logger.info('SSH keys have been added'); } + async addSshKeysFromStrings(privateSshKey: string, publicSshKey: string): Promise { + 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 { Logger.debug(); const privateSshKey: string = Buffer.from(fs.readFileSync(path.resolve(privateSshKeyPath), 'utf-8'), 'base64').toString('utf-8'); diff --git a/tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts b/tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts index 5b901956a88..f5ad0b16f58 100644 --- a/tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts +++ b/tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts @@ -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://git@bitbucket-ssh.apps.ds-airgap2-v15.crw-qe.com/~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; @@ -57,7 +59,14 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM test('Add SSH keys', async function (): Promise { 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 { await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl);