| | |
| | import fs from 'fs'; |
| | import path from 'path'; |
| | import type { Secrets } from '.'; |
| |
|
| | export const TEST_ACCOUNT_NAMES = [ |
| | 'defaultUser', |
| | 'atomicUser', |
| | 'eCommerceUser', |
| | 'simpleSiteFreePlanUser', |
| | 'simpleSitePersonalPlanUser', |
| | 'gutenbergSimpleSiteUser', |
| | 'gutenbergSimpleSiteEdgeUser', |
| | 'gutenbergSimpleSiteBlockUpgradeUser', |
| | 'gutenbergAtomicSiteUser', |
| | 'gutenbergAtomicSiteEdgeUser', |
| | 'gutenbergAtomicSiteEdgeNightliesUser', |
| | 'coBlocksSimpleSiteEdgeUser', |
| | 'coBlocksAtomicSiteEdgeUser', |
| | 'siteEditorSimpleSiteUser', |
| | 'siteEditorSimpleSiteEdgeUser', |
| | 'siteEditorAtomicSiteUser', |
| | 'siteEditorAtomicSiteEdgeUser', |
| | 'martechTosUser', |
| | 'calypsoPreReleaseUser', |
| | 'i18nUser', |
| | 'p2User', |
| | 'totpUser', |
| | 'smsUser', |
| | 'jetpackRemoteSiteUser', |
| | 'jetpackStagingUser', |
| | 'jetpackStagingFseUser', |
| | 'jetpackUserPREMIUM', |
| | 'jetpackUserJN', |
| | 'desktopAppUser', |
| | 'commentingUser', |
| | 'notificationsUser', |
| | 'googleLoginUser', |
| | 'appleLoginUser', |
| | 'gitHubLoginUser', |
| | 'jetpackAtomicDefaultUser', |
| | 'jetpackAtomicPhpOldUser', |
| | 'jetpackAtomicPhpNewUser', |
| | 'jetpackAtomicEcommPlanUser', |
| | 'jetpackAtomicPrivateUser', |
| | 'jetpackAtomicWpBetaUser', |
| | 'jetpackAtomicWpPreviousUser', |
| | 'automatticForAgenciesUser', |
| | ] as const; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export class SecretsManager { |
| | private static _secretsCache: Secrets; |
| |
|
| | |
| | |
| | |
| | public static get secrets(): Secrets { |
| | if ( ! this._secretsCache ) { |
| | this._secretsCache = this.initializeSecrets(); |
| | } |
| |
|
| | return this._secretsCache; |
| | } |
| |
|
| | |
| | |
| | |
| | private static initializeSecrets(): Secrets { |
| | const SECRETS_FILE_NAME = 'decrypted-secrets.json'; |
| | const parsedSecrets = this.parseSecretsFile( path.join( __dirname, SECRETS_FILE_NAME ) ); |
| | const fakeReferenceSecrets = this.createFakeSecretsForValidation(); |
| | this.validateSecrets( parsedSecrets, fakeReferenceSecrets ); |
| | return parsedSecrets as Secrets; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private static parseSecretsFile( filePath: string ): any { |
| | try { |
| | |
| | |
| | |
| | |
| | const secretsJson = fs.readFileSync( filePath, { |
| | encoding: 'utf-8', |
| | } ); |
| | return JSON.parse( secretsJson ); |
| | } catch ( err ) { |
| | const error: Error = err as Error; |
| | throw new Error( |
| | 'Failed to initialize the E2E secrets: Could not find and parse the secrets file.\n' + |
| | 'Have you decrypted the secrets file yet?\n' + |
| | 'Export the decryption key to E2E_SECRETS_KEY and run "yarn decrypt-secrets".\n' + |
| | 'Then, please build the package by running "yarn workspace @automattic/calypso-e2e build".\n' + |
| | `Original error message: ${ error.message }` |
| | ); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private static validateSecrets( parsedSecrets: any, fakeReferenceSecrets: Secrets ): void { |
| | const compareRecursive = ( target: any, reference: any, keyPath: string[] ) => { |
| | for ( const key in reference ) { |
| | if ( ! target?.[ key ] || typeof reference[ key ] !== typeof target[ key ] ) { |
| | const fullKeyPath = [ ...keyPath, key ].join( '.' ); |
| | throw new Error( |
| | 'Failed to initialize the E2E secrets: Invalid or missing key found in the decrypted secrets.\n' + |
| | 'Make sure you have decrypted the most recent version of the encrypted secrets.\n' + |
| | 'This also may mean the typings for the secrets are stale and need updating.\n\n' + |
| | 'Details:\n' + |
| | `\tInvalid or missing key: ${ fullKeyPath }\n` + |
| | `\tExpected type: ${ typeof reference[ key ] }, got ${ typeof target[ key ] }` |
| | ); |
| | } |
| |
|
| | if ( typeof reference[ key ] === 'object' ) { |
| | compareRecursive( target[ key ], reference[ key ], [ ...keyPath, key ] ); |
| | } |
| | } |
| | }; |
| |
|
| | compareRecursive( parsedSecrets, fakeReferenceSecrets, [] ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | private static createFakeSecretsForValidation(): Secrets { |
| | const fakeAccount = { |
| | username: 'FAKE_VALUE', |
| | password: 'FAKE_VALUE', |
| | }; |
| |
|
| | const fakeFullAccount = { |
| | ...fakeAccount, |
| | userID: 0, |
| | email: 'FAKE_VALUE', |
| | testSites: { primary: { id: 0, url: 'FAKE_VALUE' } }, |
| | }; |
| |
|
| | return { |
| | storeSandboxCookieValue: 'FAKE_VALUE', |
| | testCouponCode: 'FAKE_VALUE', |
| | wpccAuthPath: 'FAKE_VALUE', |
| | wooSignupPath: 'FAKE_VALUE', |
| | wooLoginPath: 'FAKE_VALUE', |
| | calypsoOauthApplication: { |
| | client_id: 'FAKE_VALUE', |
| | client_secret: 'FAKE_VALUE', |
| | }, |
| | martechTosUploadCredentials: { |
| | bearer_token: 'FAKE_VALUE', |
| | }, |
| | socialAccounts: { |
| | tumblr: { |
| | username: 'FAKE_VALUE', |
| | password: 'FAKE_VALUE', |
| | }, |
| | }, |
| | mailosaur: { |
| | apiKey: 'FAKE_VALUE', |
| | inviteInboxId: 'FAKE_VALUE', |
| | signupInboxId: 'FAKE_VALUE', |
| | domainsInboxId: 'FAKE_VALUE', |
| | defaultUserInboxId: 'FAKE_VALUE', |
| | totpUserInboxId: 'FAKE_VALUE', |
| | manualTesting: 'FAKE_VALUE', |
| | }, |
| | testAccounts: { |
| | defaultUser: { |
| | ...fakeFullAccount, |
| | }, |
| | atomicUser: { |
| | ...fakeFullAccount, |
| | }, |
| | eCommerceUser: { ...fakeAccount }, |
| | simpleSiteFreePlanUser: { ...fakeAccount }, |
| | simpleSitePersonalPlanUser: { ...fakeAccount }, |
| | gutenbergSimpleSiteUser: { ...fakeAccount }, |
| | gutenbergSimpleSiteEdgeUser: { ...fakeAccount }, |
| | gutenbergSimpleSiteBlockUpgradeUser: { ...fakeFullAccount }, |
| | gutenbergAtomicSiteUser: { ...fakeAccount }, |
| | gutenbergAtomicSiteEdgeUser: { ...fakeAccount }, |
| | gutenbergAtomicSiteEdgeNightliesUser: { ...fakeAccount }, |
| | coBlocksSimpleSiteEdgeUser: { ...fakeAccount }, |
| | coBlocksAtomicSiteEdgeUser: { ...fakeAccount }, |
| | siteEditorSimpleSiteUser: { ...fakeAccount }, |
| | siteEditorSimpleSiteEdgeUser: { ...fakeAccount }, |
| | siteEditorAtomicSiteUser: { ...fakeAccount }, |
| | siteEditorAtomicSiteEdgeUser: { ...fakeAccount }, |
| | martechTosUser: { ...fakeAccount }, |
| | calypsoPreReleaseUser: { ...fakeAccount }, |
| | i18nUser: { ...fakeAccount }, |
| | |
| | p2User: { ...fakeAccount, totpKey: 'FAKE_VALUE' }, |
| | totpUser: { ...fakeAccount, totpKey: 'FAKE_VALUE' }, |
| | |
| | smsUser: { ...fakeAccount, smsNumber: { code: 'FAKE_VALUE', number: 'FAKE_VALUE' } }, |
| | jetpackRemoteSiteUser: { |
| | ...fakeAccount, |
| | userID: 0, |
| | testSites: { primary: { id: 0, url: 'FAKE_VALUE', remotePassword: 'FAKE_VALUE' } }, |
| | }, |
| | jetpackStagingUser: { |
| | ...fakeAccount, |
| | userID: 0, |
| | testSites: { primary: { id: 0, url: 'FAKE_VALUE' } }, |
| | }, |
| | jetpackStagingFseUser: { |
| | ...fakeAccount, |
| | userID: 0, |
| | testSites: { primary: { id: 0, url: 'FAKE_VALUE' } }, |
| | }, |
| | jetpackUserPREMIUM: { ...fakeAccount }, |
| | jetpackUserJN: { ...fakeAccount }, |
| | desktopAppUser: { ...fakeAccount }, |
| | commentingUser: { ...fakeAccount }, |
| | notificationsUser: { ...fakeAccount }, |
| | googleLoginUser: { |
| | ...fakeAccount, |
| | smsNumber: { code: 'FAKE_VALUE', number: 'FAKE_VALUE' }, |
| | totpKey: 'FAKE_VALUE', |
| | }, |
| | appleLoginUser: { |
| | ...fakeAccount, |
| | }, |
| | gitHubLoginUser: { |
| | ...fakeAccount, |
| | }, |
| | jetpackAtomicDefaultUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicPhpOldUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicPhpNewUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicEcommPlanUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicPrivateUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicWpBetaUser: { |
| | ...fakeFullAccount, |
| | }, |
| | jetpackAtomicWpPreviousUser: { |
| | ...fakeFullAccount, |
| | }, |
| | automatticForAgenciesUser: { |
| | ...fakeFullAccount, |
| | }, |
| | }, |
| | otherTestSites: { |
| | notifications: 'FAKE_VALUE', |
| | }, |
| | }; |
| | } |
| | } |
| |
|