diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 008fad0c89f..f6e48465774 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -11,8 +11,30 @@ execution_time_limit: hours: 1 blocks: - - name: Mock UI Tests + - name: Build dependencies: [] + execution_time_limit: + minutes: 20 + task: + env_vars: + - &flowcrypt_git_dir + name: SEMAPHORE_GIT_DIR + value: /home/semaphore/git/flowcrypt-browser + jobs: + - name: Build extension and tests + commands: + - mkdir ~/git && checkout + - cd ~/git/flowcrypt-browser + - cache restore flowcrypt-browser-npm-$(checksum package-lock.json) || true + - cache restore flowcrypt-browser-puppeteer-ubuntu2404-$(uname -m)-$(checksum package-lock.json) || true + # postinstall builds the extension variants and compiles the tests. + - npm ci --cache ~/.npm --prefer-offline + - cache store flowcrypt-browser-npm-$(checksum package-lock.json) ~/.npm || true + - cache store flowcrypt-browser-puppeteer-ubuntu2404-$(uname -m)-$(checksum package-lock.json) ~/.cache/puppeteer || true + - cache store flowcrypt-browser-build-$SEMAPHORE_PIPELINE_ID build || true + + - name: Mock UI Tests + dependencies: [Build] execution_time_limit: minutes: 45 task: @@ -20,16 +42,20 @@ blocks: - &flowcrypt_ci_secrets name: flowcrypt-browser-ci-secrets env_vars: - - &flowcrypt_git_dir - name: SEMAPHORE_GIT_DIR - value: /home/semaphore/git/flowcrypt-browser + - *flowcrypt_git_dir prologue: commands: &flowcrypt_ci_prologue - mkdir ~/git && checkout && mv ~/test-secrets.json ~/git/flowcrypt-browser/test/test-secrets.json - cd ~/git/flowcrypt-browser - cache restore flowcrypt-browser-npm-$(checksum package-lock.json) || true - - npm ci --cache ~/.npm --prefer-offline - - cache store flowcrypt-browser-npm-$(checksum package-lock.json) ~/.npm || true + - cache restore flowcrypt-browser-puppeteer-ubuntu2404-$(uname -m)-$(checksum package-lock.json) || true + # Install dependencies without rebuilding the extension in postinstall. + - npm ci --ignore-scripts --cache ~/.npm --prefer-offline + - npm rebuild puppeteer + - npm run symlink-core + - cache restore flowcrypt-browser-build-$SEMAPHORE_PIPELINE_ID || true + # Cache misses (including fork PRs and job reruns) must still run a full build. + - 'if [[ ! -f build/test/test/source/test.js ]]; then npm run pretest; fi' - 'echo "NODE=$(node --version), NPM=$(npm --version), TSC=$( ./node_modules/typescript/bin/tsc --version)"' jobs: - name: consumer mock - standard test group @@ -63,7 +89,7 @@ blocks: done - name: Live UI Gmail tests - dependencies: [] + dependencies: [Build] run: when: branch = 'master' OR branch =~ 'live-test' OR branch =~ 'gmail-test' execution_time_limit: @@ -84,7 +110,7 @@ blocks: on_fail: *flowcrypt_ci_epilogue_on_fail - name: Other tests - dependencies: [] + dependencies: [Build] execution_time_limit: minutes: 20 task: @@ -124,4 +150,5 @@ after_pipeline: jobs: - name: Publish Results commands: + - cache delete flowcrypt-browser-build-$SEMAPHORE_PIPELINE_ID || true - test-results gen-pipeline-report diff --git a/extension/js/common/settings.ts b/extension/js/common/settings.ts index 5e726211bae..48110ea5e80 100644 --- a/extension/js/common/settings.ts +++ b/extension/js/common/settings.ts @@ -598,7 +598,13 @@ export class Settings { private static async fetchAcctAliasesFromGmail(acctEmail: string): Promise> { const response = await new Gmail(acctEmail).fetchAcctAliases(); - const namesRes = await Google.getNames(acctEmail); + const namesRes = await Google.getNames(acctEmail).catch((e: unknown) => { + if (!ApiErr.isRateLimit(e)) { + throw e; + } + // Profile names are optional: keep Gmail's display name if the People API quota is exhausted. + return undefined; + }); const validAliases = response.sendAs.filter(alias => alias.isPrimary || alias.verificationStatus === 'accepted'); const result: Dict = {}; for (const a of validAliases) { @@ -610,7 +616,7 @@ export class Settings { footer: a.signature, }; if (sendAsEmail === acctEmail.toLowerCase()) { - result[sendAsEmail].name = namesRes.names.find(name => name.metadata.primary ?? false)?.displayName; + result[sendAsEmail].name = namesRes?.names.find(name => name.metadata.primary ?? false)?.displayName ?? a.displayName; } } return result; diff --git a/package-lock.json b/package-lock.json index 805feb41fa0..f7de833a6da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3978,9 +3978,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.11.33", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.33.tgz", - "integrity": "sha512-yiVKDX+qCMRKBE084lXvq9EcwFUhKZ2nU8TK1EQQuOgPNR/lmbGxXOeDdlGUqC2Zz11Cs9rk1d/8NfgBmlkt0w==", + "version": "2.11.34", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.34.tgz", + "integrity": "sha512-Aqr8mA1kIvyJ3UY5YAY7ib8LSo1DmDMbMnVqGPtsKW1LxaFQFwn9Eb3yvq2fUKJsRvaXjnAV7R5osqETapzNiA==", "dev": true, "license": "Apache-2.0", "peer": true, @@ -5271,9 +5271,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.465", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.465.tgz", - "integrity": "sha512-zg4iUpbeGw7YNZsswc2xKr2uiBex2d8dELAXo92Icw3but1ULbrvK8USe6wVLaWjgJnKBARv0pchx9Owktx6wQ==", + "version": "1.5.467", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.467.tgz", + "integrity": "sha512-Nw9X371rtZmYcBSnEijnCDONILjs93biCZO34juC7MBOmK8E+GFnyD4T/WvyrlJkppul7oxg6TwvtKst9SODTw==", "dev": true, "license": "ISC", "peer": true diff --git a/test/source/browser/browser-handle.ts b/test/source/browser/browser-handle.ts index 2b6ccfc7c6e..50d3512fc28 100644 --- a/test/source/browser/browser-handle.ts +++ b/test/source/browser/browser-handle.ts @@ -5,7 +5,7 @@ import { Util } from '../util'; import { ControllablePage } from './controllable'; import { Semaphore } from './browser-pool'; import { TIMEOUT_ELEMENT_APPEAR } from '.'; -import { AvaContext } from '../tests/tooling'; +import { AvaContext, newTimeoutPromise } from '../tests/tooling'; export class BrowserHandle { public pages: ControllablePage[] = []; @@ -117,6 +117,8 @@ export class BrowserHandle { }; public debugPagesHtml = async (t: AvaContext, alsoLogToConsole: boolean) => { + // Capture extension frames before collecting console messages, which can take several seconds per page. + const composeFramesHtmls = await Promise.all(this.pages.map(async cPage => (cPage.page.isClosed() ? '' : await this.debugComposeFramesHtml(cPage.page)))); let html = ''; for (let i = 0; i < this.pages.length; i++) { const cPage = this.pages[i]; @@ -127,6 +129,7 @@ export class BrowserHandle { .join('\n'); html += '
'; html += `
Page ${i} (${cPage.page.isClosed() ? 'closed' : 'active'}) ${Util.htmlEscape(url)}
`; + html += composeFramesHtmls[i] ?? ''; html += `
${consoleMsgs || '(no console messages)'}
`; html += `
${alerts || '(no alerts)'}
`; if (url !== 'about:blank' && !cPage.page.isClosed()) { @@ -148,6 +151,25 @@ export class BrowserHandle { return html; }; + private debugComposeFramesHtml = async (page: Page): Promise => { + const framesHtml = await Promise.all( + page + .frames() + .filter(frame => frame.url().includes('/chrome/elements/compose.htm')) + .map(async frame => { + let html = `
${Util.htmlEscape(frame.url())} (detached: ${frame.detached})
`; + try { + const frameHtml = await Promise.race([frame.content(), newTimeoutPromise('compose frame diagnostics', 5)]); + html += `
${Util.htmlEscape(frameHtml)}
`; + } catch (e) { + html += `
${Util.htmlEscape(String(e))}
`; + } + return html; + }) + ); + return framesHtml.join(''); + }; + private doAwaitTriggeredPage = (triggeringAction: () => Promise): Promise => { return new Promise((resolve, reject) => { setTimeout(() => reject(new Error('Action did not trigger a new page within timeout period')), TIMEOUT_ELEMENT_APPEAR * 1000); diff --git a/test/source/browser/browser-pool.ts b/test/source/browser/browser-pool.ts index 1367e0679bd..2e930d58918 100644 --- a/test/source/browser/browser-pool.ts +++ b/test/source/browser/browser-pool.ts @@ -51,6 +51,9 @@ export class BrowserPool { if (this.isMock) { args.push('--ignore-certificate-errors'); args.push('--allow-insecure-localhost'); + } else { + // Google SAML confirmation failed over both QUIC and HTTP/2. + args.push('--disable-quic', '--disable-http2'); } const slowMo = this.isMock ? 60 : 60; const browser = await launch({ diff --git a/test/source/browser/controllable.ts b/test/source/browser/controllable.ts index 7a9871689a7..c19fc6363db 100644 --- a/test/source/browser/controllable.ts +++ b/test/source/browser/controllable.ts @@ -673,7 +673,7 @@ abstract class ControllableBase { } } } catch (e) { - if (e instanceof Error && !e.message.includes('Cannot find context with specified id undefined')) { + if (!Util.isTransientPageError(e)) { throw e; } } diff --git a/test/source/buf.ts b/test/source/buf.ts index 507e925d4ee..cc7d569b18e 100644 --- a/test/source/buf.ts +++ b/test/source/buf.ts @@ -5,57 +5,55 @@ import test from 'ava'; import { Buf } from '../../extension/js/common/core/buf.js'; import { equals } from './tests/unit-node.js'; -const lousyRandomBytes = (len = 30): Uint8Array => { - const a = new Uint8Array(len); - for (let i = 0; i < len; i++) { - a[i] = Math.floor(Math.random() * 256); - } - return a; -}; - -const withThousandRandomInputs = (cb: (data: Uint8Array) => void) => { - for (let i = 0; i < 1000; i++) { - const input = lousyRandomBytes(); - cb(input); - } -}; +const BYTE_INPUTS = [ + new Uint8Array(), + new Uint8Array([255]), + new Uint8Array([251, 255]), + new Uint8Array([251, 255, 255]), + // Exercise every padding length, all byte values, and raw-string chunk boundaries. + ...[4, 5, 6, 7, 8, 9, 29, 30, 31, 255, 256, 257, 32767, 32768, 32769].map(length => Uint8Array.from({ length }, (_, i) => (i * 73 + 251) % 256)), +]; const UTF8 = `გამარჯობა.\nこんにちは。\nЗдравствуй.\nChào bạn.\nDobrý deň!\n여보세요?\n你好。\r\n\t。 `; const UTF8_AS_BYTES = Buffer.from(UTF8); const UTF8_AS_RAW_STRING = Buffer.from(UTF8).toString('binary'); -test(`1000x Buf.fromUint8(data).toBase64Str() = Buffer.from(data).toString('base64')`, async t => { - withThousandRandomInputs(data => { - equals(Buf.fromUint8(data).toBase64Str(), Buffer.from(data).toString('base64')); - }); - t.pass(); +test(`Buf.fromUint8(data).toBase64Str() = Buffer.from(data).toString('base64')`, t => { + for (const data of BYTE_INPUTS) { + t.is(Buf.fromUint8(data).toBase64Str(), Buffer.from(data).toString('base64'), `length ${data.length}`); + } }); -test(`1000x Buf.fromUint8(data).toRawBytesStr() = Buffer.from(data).toString('binary')`, async t => { - withThousandRandomInputs(data => { - equals(Buf.fromUint8(data).toRawBytesStr(), Buffer.from(data).toString('binary')); - }); - t.pass(); +test(`Buf.fromUint8(data).toRawBytesStr() = Buffer.from(data).toString('binary')`, t => { + for (const data of BYTE_INPUTS) { + t.is(Buf.fromUint8(data).toRawBytesStr(), Buffer.from(data).toString('binary'), `length ${data.length}`); + } }); -test('1000x Buf.fromBase64UrlStr(Buf.fromUint8(data).toBase64UrlStr()) = data', async t => { - withThousandRandomInputs(data => { - equals(Buf.fromBase64UrlStr(Buf.fromUint8(data).toBase64UrlStr()), data); - }); +test(`Buf.fromUint8(data).toBase64UrlStr() = Buffer.from(data).toString('base64url')`, t => { + for (const data of BYTE_INPUTS) { + t.is(Buf.fromUint8(data).toBase64UrlStr(), Buffer.from(data).toString('base64url'), `length ${data.length}`); + } +}); + +test(`Buf.fromBase64UrlStr(Buffer.from(data).toString('base64url')) = data`, t => { + for (const data of BYTE_INPUTS) { + equals(Buf.fromBase64UrlStr(Buffer.from(data).toString('base64url')), data); + } t.pass(); }); -test('1000x Buf.fromRawBytesStr(Buf.fromUint8(data).toRawBytesStr()) = data', async t => { - withThousandRandomInputs(data => { - equals(Buf.fromRawBytesStr(Buf.fromUint8(data).toRawBytesStr()), data); - }); +test(`Buf.fromRawBytesStr(Buffer.from(data).toString('binary')) = data`, t => { + for (const data of BYTE_INPUTS) { + equals(Buf.fromRawBytesStr(Buffer.from(data).toString('binary')), data); + } t.pass(); }); -test('1000x Buf.fromBase64Str(Buf.fromUint8(data).toBase64Str()) = data', async t => { - withThousandRandomInputs(data => { - equals(Buf.fromBase64Str(Buf.fromUint8(data).toBase64Str()), data); - }); +test(`Buf.fromBase64Str(Buffer.from(data).toString('base64')) = data`, t => { + for (const data of BYTE_INPUTS) { + equals(Buf.fromBase64Str(Buffer.from(data).toString('base64')), data); + } t.pass(); }); diff --git a/test/source/mock/google/strategies/send-message-strategy.ts b/test/source/mock/google/strategies/send-message-strategy.ts index 2c80c1d497d..30c3de54741 100644 --- a/test/source/mock/google/strategies/send-message-strategy.ts +++ b/test/source/mock/google/strategies/send-message-strategy.ts @@ -112,11 +112,13 @@ class PwdAndPubkeyEncryptedMessagesWithFlowCryptComApiTestStrategy implements IT }; } class PwdEncryptedMessageWithFlowCryptComApiTestStrategy implements ITestMsgStrategy { + public constructor(private expectedSenderEmail: string) {} + public test = async (parseResult: ParseMsgResult) => { await check7bitEncodedPgpMimeParts(parseResult, ['flowcrypt.compatibility.1pp1', 'ci.tests.gmail'], true); const mimeMsg = parseResult.mimeMsg; - const senderEmail = Str.parseEmail(mimeMsg.from!.text).email; - if (!mimeMsg.text?.includes(`${senderEmail} has sent you a password-encrypted email`)) { + expect(Str.parseEmail(mimeMsg.from!.text).email).to.equal(this.expectedSenderEmail); + if (!mimeMsg.text?.includes(`${this.expectedSenderEmail} has sent you a password-encrypted email`)) { throw new HttpClientErr(`Error checking sent text in:\n\n${mimeMsg.text}`); } checkPwdEncryptedMessage(mimeMsg.text); @@ -318,7 +320,6 @@ class PlainTextMessageTestStrategy implements ITestMsgStrategy { }; } - class NoopTestStrategy implements ITestMsgStrategy { // eslint-disable-next-line @typescript-eslint/no-empty-function public test = async () => {}; @@ -468,7 +469,8 @@ export class TestBySubjectStrategyContext { } else if (subject.includes('Test Footer (Mock Test)')) { this.strategy = new MessageWithFooterTestStrategy(); } else if (subject.includes('PWD encrypted message with flowcrypt.com/shared-tenant-fes')) { - this.strategy = new PwdEncryptedMessageWithFlowCryptComApiTestStrategy(); + // The attachment test uses the original subject and the primary compatibility address. + this.strategy = new PwdEncryptedMessageWithFlowCryptComApiTestStrategy(/ - from: (.+)$/.exec(subject)?.[1] ?? 'flowcrypt.compatibility@gmail.com'); } else if (subject.includes('PWD and pubkey encrypted messages with flowcrypt.com/shared-tenant-fes')) { this.strategy = new PwdAndPubkeyEncryptedMessagesWithFlowCryptComApiTestStrategy(); } else if (subject.includes('PWD encrypted message with FES - ID TOKEN')) { diff --git a/test/source/mock/wkd/wkd-constants.ts b/test/source/mock/wkd/wkd-constants.ts index 2250cbe9d95..df276f68259 100644 --- a/test/source/mock/wkd/wkd-constants.ts +++ b/test/source/mock/wkd/wkd-constants.ts @@ -36,34 +36,6 @@ AwMwBxWpyLaH6xjb =mswb -----END PGP PUBLIC KEY BLOCK-----`; -export const johnDoeDirectKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- - -xsBNBF+Jz04BCACYEg0Fkg4NLnTxzuyF3gnz2pMfp+BelG/IHvIg9mls4U8OJcjGyq3bVpPDKDDQ -4ZuhRtrMy5K0ZnyiGsmzMKXvVS3FUPQ5EJD2Laveo5ohtM6t49jlloQvv7aMUBVpjTskaY06lJuV -2f1CCCDteh3G8qNpKvziUc4a8PzeIItktHTCa0MNdDRxq19DUs2eQGGXqBDm/mQjVMZ1Zgt55Ymu -BpPLytJXOjRoDYsTj+OdOv+aQ4Td7JnicTDVQR4Uc9x02lMPsBF3K0N0cnITyiKCV/QdgdSQkL8N -zFVgvt5QPGhlGA0sAl1wiBFeNZrrd+VXg4FmuGrWd9YLS01AyRSJABEBAAHNEmpvaG4uZG9lQDEy -Ny4wLjAuMcLAiQQTAQgAMxYhBGWfN6kiReeNpwCbUy2oGOH1OKOdBQJfic9SAhsDBQsJCAcCBhUI -CQoLAgUWAgMBAAAKCRAtqBjh9TijnU1JB/wPcImnOmo42gu8YBKe18d9HyCQNs4q4pw/bYXshLe7 -aMjx+XgUvWHBcoTtz+4g2QjmhmL3ROkGs/vBriZZqhZz4636s7RAlyU0yyzcH4rvNq/ByNm+Ol7x -Bwo3EbaRh46Q4mbctslfQ/jd42cUzwEOnY2HSPH+tgfTjd8xciBL5tH0+YinCuqSi/sAOkBoNAkv -kgiA+cRH4scVsW2KwWuZPOJINO8nJVu0at64sZib8/UJ4Zku5w7i1dnmWu6C9aqz+Ddu/xcDUW8j -2GFXECJX0deXZmhEZ8wLt5P+ke3Wt1gttGCigVzPvpXHkpZpC7zlykcMeE2ywRBqypauZUjPzsBN -BF+Jz1IBCACjRVxKy2aU49H95g8LM1Dsqmc+KCSOl9/kC1pyzKl4xUEYQ+ok5OKHt9tf42a1z9SM -oUicFkSOwBMtjOhWjrghxVBHIc4NtDewFXY6IifG6BvewOiNat2mYzfLF852idBbhnN82p4NWd2g -oUwDcqOvZ3Z5qg4eKiH2l+UzlHuFXmSfFP3g7Pm3UTaYhOWRBwOO/u7JN9rMHBcLxfp7T745C8dT -UmrZEpfTEGgwhmYfBFyMZFxzgtZwt4UUTnyLFtqhROPx6ji4ecSDNAD7yVjd9uJSNbxIRV4SUPCG -/vR39Lm8dXiFEek47DYGPaPyid/zfFkfhLndQ70W2GkhGdLnABEBAAHCwHYEGAEIACAWIQRlnzep -IkXnjacAm1MtqBjh9TijnQUCX4nPVwIbDAAKCRAtqBjh9Tijna+wB/4tsj016eBsQGb3xGs/BBa6 -06VLL9tjrTV9TdZj3DfpE9xSPiNC+Jah09uW//VNRzNTDYctGXEGIYm2tx2q8QAX/rWBC/UYi16l -4lHnvlHa4NNA+O22uQpMlwmbTVSPTs4kVUSpNyuOtE6SXY6UyzcyvwTpffXiQkfICW7BXmykUXHx -HZ8Ddq/syp3eBitlmNZHGwRWKD5ihd96o5dCw/Dgpz/p6dxka1627j013wov65p1NbXiV1kM7G7s -ZccLrjYxOL/1Rc1ac9TdfXX7lVeZtbpSVhSl9Z1YMhth+oWVJ79iQQ8OPKEvt471Qwk1LH7k4a9O -nT5+WNnpAkcxrjMd -=fISM ------END PGP PUBLIC KEY BLOCK----- -`; - export const jackAdvancedKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBF+J56IBCADSvEei1mAEQCEXHxaOKzsxvM8Qvgjj0vr+zHE+hUFg1znRAyjQ9XSDGwJ4+dut diff --git a/test/source/mock/wkd/wkd-endpoints.ts b/test/source/mock/wkd/wkd-endpoints.ts index 2f8fc9641b0..47584396f05 100644 --- a/test/source/mock/wkd/wkd-endpoints.ts +++ b/test/source/mock/wkd/wkd-endpoints.ts @@ -54,6 +54,9 @@ export const getMockWkdEndpoints = (config: WkdConfig | undefined): HandlersDefi '/.well-known/openpgpkey/localhost/policy': async () => { return ''; // allow advanced for localhost }, + '/.well-known/openpgpkey/example.com/policy': async () => { + throw new HttpClientErr('Advanced policy not found', Status.NOT_FOUND); // exercise direct fallback + }, '/.well-known/openpgpkey/policy': async () => { return ''; // allow direct for all }, diff --git a/test/source/tests/browser-unit-tests/unit-Wkd.js b/test/source/tests/browser-unit-tests/unit-Wkd.js index 444fa8c6cd3..079804033e6 100644 --- a/test/source/tests/browser-unit-tests/unit-Wkd.js +++ b/test/source/tests/browser-unit-tests/unit-Wkd.js @@ -20,17 +20,14 @@ * Do not put any code whatsoever outside of the async functions. */ -BROWSER_UNIT_TEST_NAME(`Wkd direct method`); +BROWSER_UNIT_TEST_NAME(`Wkd direct method when advanced policy is absent`); (async () => { const wkd = new Wkd(); - let email; - email = 'john.doe@localhost'; - if (!(await wkd.lookupEmail(email)).pubkeys.length) { - throw Error(`Wkd for ${email} didn't return a pubkey`); - } - email = 'John.Doe@localhost'; - if (!(await wkd.lookupEmail(email)).pubkeys.length) { - throw Error(`Wkd for ${email} didn't return a pubkey`); + for (const email of ['john.doe@example.com', 'John.Doe@example.com', 'John.Doe@EXAMPLE.com']) { + const { pubkeys } = await wkd.lookupEmail(email); + if (pubkeys.length !== 1 || (await KeyUtil.parse(pubkeys[0])).id.toUpperCase() !== '094C3CBA696FA009F6015C473B635D858A1DB5E0') { + throw Error(`Wkd for ${email} didn't return the expected direct pubkey`); + } } return 'pass'; })(); @@ -38,14 +35,11 @@ BROWSER_UNIT_TEST_NAME(`Wkd direct method`); BROWSER_UNIT_TEST_NAME(`Wkd advanced method`); (async () => { const wkd = new Wkd(); - let email; - email = 'john.doe@localhost'; - if (!(await wkd.lookupEmail(email)).pubkeys.length) { - throw Error(`Wkd for ${email} didn't return a pubkey`); - } - email = 'John.Doe@localHOST'; - if (!(await wkd.lookupEmail(email)).pubkeys.length) { - throw Error(`Wkd for ${email} didn't return a pubkey`); + for (const email of ['john.doe@localhost', 'John.Doe@localhost', 'John.Doe@localHOST']) { + const { pubkeys } = await wkd.lookupEmail(email); + if (pubkeys.length !== 1 || (await KeyUtil.parse(pubkeys[0])).id.toUpperCase() !== 'CB1B7A41BA7C1CBAA08A6166B902CB65C694D6B4') { + throw Error(`Wkd for ${email} didn't return the expected advanced pubkey`); + } } return 'pass'; })(); diff --git a/test/source/tests/compose.ts b/test/source/tests/compose.ts index a2b2302121c..b52d9eb44b4 100644 --- a/test/source/tests/compose.ts +++ b/test/source/tests/compose.ts @@ -145,39 +145,26 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te }) ); - test( - 'compose - check for sender [flowcrypt.compatibility@gmail.com] from a password-protected email', - testWithBrowser(async (t, browser) => { - const senderEmail = 'flowcrypt.compatibility@gmail.com'; - await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility', { - google: { acctAliases: flowcryptCompatibilityAliasList }, - }); - const msgPwd = 'super hard password for the message'; - const subject = 'PWD encrypted message with flowcrypt.com/shared-tenant-fes'; - const composePage = await ComposePageRecipe.openStandalone(t, browser, 'compatibility'); - await ComposePageRecipe.selectFromOption(composePage, senderEmail); - await ComposePageRecipe.fillMsg(composePage, { to: 'test@email.com' }, subject); - await ComposePageRecipe.sendAndClose(composePage, { password: msgPwd }); - // this test is using PwdEncryptedMessageWithFlowCryptComApiTestStrategy to check sent result based on subject "PWD encrypted message with flowcrypt.com/shared-tenant-fes" - }) - ); - - test( - 'compose - check for sender [flowcryptcompatibility@gmail.com] (alias) from a password-protected email', - testWithBrowser(async (t, browser) => { - const senderEmail = 'flowcrypt.compatibility@gmail.com'; - await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility', { - google: { acctAliases: flowcryptCompatibilityAliasList }, - }); - const msgPwd = 'super hard password for the message'; - const subject = 'PWD encrypted message with flowcrypt.com/shared-tenant-fes'; - const composePage = await ComposePageRecipe.openStandalone(t, browser, 'compatibility'); - await ComposePageRecipe.selectFromOption(composePage, senderEmail); - await ComposePageRecipe.fillMsg(composePage, { to: 'test@email.com' }, subject); - await ComposePageRecipe.sendAndClose(composePage, { password: msgPwd }); - // this test is using PwdEncryptedMessageWithFlowCryptComApiTestStrategy to check sent result based on subject "PWD encrypted message with flowcrypt.com/shared-tenant-fes" - }) - ); + for (const { senderEmail, aliasLabel } of [ + { senderEmail: 'flowcrypt.compatibility@gmail.com', aliasLabel: '' }, + { senderEmail: 'flowcryptcompatibility@gmail.com', aliasLabel: ' (alias)' }, + ]) { + test( + `compose - check for sender [${senderEmail}]${aliasLabel} from a password-protected email`, + testWithBrowser(async (t, browser) => { + await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility', { + google: { acctAliases: flowcryptCompatibilityAliasList }, + }); + const msgPwd = 'super hard password for the message'; + const subject = `PWD encrypted message with flowcrypt.com/shared-tenant-fes - from: ${senderEmail}`; + const composePage = await ComposePageRecipe.openStandalone(t, browser, 'compatibility'); + await ComposePageRecipe.selectFromOption(composePage, senderEmail); + await ComposePageRecipe.fillMsg(composePage, { to: 'test@email.com' }, subject); + await ComposePageRecipe.sendAndClose(composePage, { password: msgPwd }); + // PwdEncryptedMessageWithFlowCryptComApiTestStrategy checks the sender specified in the subject. + }) + ); + } test( 'compose - check for sender [ci.tests.gmail@flowcrypt.test] from a password-protected email', @@ -185,7 +172,7 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te const senderEmail = 'ci.tests.gmail@flowcrypt.test'; await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'ci.tests.gmail'); const msgPwd = 'super hard password for the message'; - const subject = 'PWD encrypted message with flowcrypt.com/shared-tenant-fes'; + const subject = `PWD encrypted message with flowcrypt.com/shared-tenant-fes - from: ${senderEmail}`; const composePage = await ComposePageRecipe.openStandalone(t, browser, senderEmail); await ComposePageRecipe.fillMsg(composePage, { to: 'test@email.com' }, subject); await ComposePageRecipe.sendAndClose(composePage, { password: msgPwd }); diff --git a/test/source/tests/decrypt.ts b/test/source/tests/decrypt.ts index b02586a8fb3..f04704a548f 100644 --- a/test/source/tests/decrypt.ts +++ b/test/source/tests/decrypt.ts @@ -2,12 +2,12 @@ import test from 'ava'; -import { Config, TestVariant, Util } from './../util'; +import { Config, TestMessage, TestVariant, Util } from './../util'; import { testConstants } from './tooling/consts'; import { BrowserRecipe } from './tooling/browser-recipe'; import { InboxPageRecipe } from './page-recipe/inbox-page-recipe'; import { SettingsPageRecipe } from './page-recipe/settings-page-recipe'; -import { TestWithBrowser } from './../test'; +import { CommonAcct, TestWithBrowser } from './../test'; import { expect } from 'chai'; import { PageRecipe } from './page-recipe/abstract-page-recipe'; import { @@ -430,385 +430,328 @@ export const defineDecryptTests = (testVariant: TestVariant, testWithBrowser: Te }) ); - test( - `decrypt - without a subject`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1600f39127880eed', - { - content: ['This is a compatibility test email'], - unexpectedContent: ['Encrypted Subject:', '(no subject)'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted iso-2022-jp pgp/mime`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16f66f1da9d50d05', - { - content: ['ゾし逸現飲'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted iso-2022-jp, plain text`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16f431a0b9056562', - { - content: ['ゾし逸現飲'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - iso-2022-jp, signed plain text`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '18024d53a24b19ff', - { - content: ['テストです\nテスト'], - encryption: 'not encrypted', - signature: 'could not verify signature: missing pubkey 73A5534E5887BBAA', - }, - authHdr - ); - }) - ); - - test( - `decrypt - quoted part parsing will not crash browser`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16b7fce1c1589c0a', - { - content: ['point to them directly', 'free cert through', 'will honestly soon', 'dropped significantly'], - encryption: 'encrypted', - signature: 'not signed', - quoted: true, - }, - authHdr - ); - }) - ); - - test( - `decrypt - [flowcrypt] signed message inline`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7f5e966792203', - { - content: ['Standard message', 'signed inline', 'should easily verify', 'This is email footer'], - encryption: 'not encrypted', - signature: 'could not verify signature: missing pubkey 06CA553EC2455D70', - }, - authHdr - ); - }) - ); - - test( - `decrypt - cleartext signed message detected in an attachment`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'ci.tests.gmail'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1885ded59a2b5a8d', - { - content: ['Standard message', 'signed inline', 'should easily verify', 'This is email footer'], - encryption: 'not encrypted', - signature: 'could not verify signature: missing pubkey 06CA553EC2455D70', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [gpgmail] signed message will get parsed and rendered (though verification fails, enigmail does the same)`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f81b5e6ed91b20', - { - content: ['Hi this is a signed message.'], - encryption: 'not encrypted', - signature: 'could not verify signature: missing pubkey 21FC55064B1DDC75', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [gpg] signed fully armored message`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1707b9c96c5d7893', - { - content: ['this was encrypted with gpg', 'gpg --sign --armor -r flowcrypt.compatibility@gmail.com ./text.txt'], - encryption: 'not encrypted', - signature: 'could not verify signature: signed by flowcrypt.compatibility@gmail.com but message is from sender@domain.com', - quoted: false, - }, - authHdr - ); - }) - ); - - test( - `decrypt - [flowcrypt] encrypted utf8`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7f5f098d6bc36', - { - content: ['გამარჯობა.', 'こんにちは。', 'Здравствуй.', 'Chào bạn.', 'Dobrý deň!', '여보세요?', '你好。'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [flowcrypt] encrypted thai utf8`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1645e37647db32f8', - { - content: ['ทดสอบ', 'นี้เป็นการทดสอบ', 'ภาษาไทย'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [facebook] encrypted utf8`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16180866d0ae26c3', - { - content: ['Сергій Ткаченко'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey 6859679E2F20BEF4', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [gpgmail] encrypted utf8`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - const gmailPage = await browser.newPage(t, `${t.context.urls?.mockGmailUrl()}/161b2ac5a73d4097`, undefined, authHdr); - await gmailPage.waitAll('iframe'); - const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']); - await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { - content: ['Prozent => %', 'Scharf-S => ß', 'Ue => Ü', 'Ae => Ä'], + const decryptCases: { name: string; acct?: CommonAcct; msgId: string; expected: TestMessage }[] = [ + { + name: `decrypt - without a subject`, + msgId: '1600f39127880eed', + expected: { + content: ['This is a compatibility test email'], + unexpectedContent: ['Encrypted Subject:', '(no subject)'], encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey 9BBE40BC1E8CE4A3', - }); - await gmailPage.waitForContent('.message_inner_body', '1io | Sales & Marketing'); - await gmailPage.waitForContent('.message_inner_body', '1io GmbH'); - await gmailPage.close(); - }) - ); - - test( - `decrypt - [enigmail] encrypted utf8`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1639b8ceb6c44a4c', - { - content: ['TEST, ПРОВЕРКА', 'C увaжeниeм, Пaвлoвcкий Poмaн Oлeгoвич.'], - encryption: 'encrypted', - signature: 'not signed', - quoted: true, - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted pgp/mime`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7fcace2d72246', - { - content: ['This is an encrypted message.', 'Not much going on here.'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted inline`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7fcb7fabc7511', - { - content: ['This is inline-encrypted message from Enigmail.', 'Yay.'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted+signed inline`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7fd2fd072cff2', - { - content: ['This message is both encrypted + signed.'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted+signed pgp/mime`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7fd3ba3f37cf3', - { - content: ['Message encrypted and signed using PGP/MIME.'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] encrypted+signed+file pgp/mime + load from gmail`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7fd7fe45fc026', - { - content: ['Message encrypted and signed as a whole using PGP/MIME.', 'cape-town-central.jpg', '185.69 kB'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', - }, - authHdr - ); - }) - ); - - test( - `decrypt - encrypted missing checksum`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '15f7ffbebc6ba296', - { - content: ['400 library systems in 177 countries worldwide'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); + signature: 'not signed', + }, + }, + { + name: `decrypt - [enigmail] encrypted iso-2022-jp pgp/mime`, + msgId: '16f66f1da9d50d05', + expected: { + content: ['ゾし逸現飲'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [enigmail] encrypted iso-2022-jp, plain text`, + msgId: '16f431a0b9056562', + expected: { + content: ['ゾし逸現飲'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - iso-2022-jp, signed plain text`, + msgId: '18024d53a24b19ff', + expected: { + content: ['テストです\nテスト'], + encryption: 'not encrypted', + signature: 'could not verify signature: missing pubkey 73A5534E5887BBAA', + }, + }, + { + name: `decrypt - quoted part parsing will not crash browser`, + msgId: '16b7fce1c1589c0a', + expected: { + content: ['point to them directly', 'free cert through', 'will honestly soon', 'dropped significantly'], + encryption: 'encrypted', + signature: 'not signed', + quoted: true, + }, + }, + { + name: `decrypt - [flowcrypt] signed message inline`, + msgId: '15f7f5e966792203', + expected: { + content: ['Standard message', 'signed inline', 'should easily verify', 'This is email footer'], + encryption: 'not encrypted', + signature: 'could not verify signature: missing pubkey 06CA553EC2455D70', + }, + }, + { + name: `decrypt - cleartext signed message detected in an attachment`, + acct: 'ci.tests.gmail', + msgId: '1885ded59a2b5a8d', + expected: { + content: ['Standard message', 'signed inline', 'should easily verify', 'This is email footer'], + encryption: 'not encrypted', + signature: 'could not verify signature: missing pubkey 06CA553EC2455D70', + }, + }, + { + name: `decrypt - [gpgmail] signed message will get parsed and rendered (though verification fails, enigmail does the same)`, + msgId: '15f81b5e6ed91b20', + expected: { + content: ['Hi this is a signed message.'], + encryption: 'not encrypted', + signature: 'could not verify signature: missing pubkey 21FC55064B1DDC75', + }, + }, + { + name: `decrypt - [gpg] signed fully armored message`, + msgId: '1707b9c96c5d7893', + expected: { + content: ['this was encrypted with gpg', 'gpg --sign --armor -r flowcrypt.compatibility@gmail.com ./text.txt'], + encryption: 'not encrypted', + signature: 'could not verify signature: signed by flowcrypt.compatibility@gmail.com but message is from sender@domain.com', + quoted: false, + }, + }, + { + name: `decrypt - [flowcrypt] encrypted utf8`, + msgId: '15f7f5f098d6bc36', + expected: { + content: ['გამარჯობა.', 'こんにちは。', 'Здравствуй.', 'Chào bạn.', 'Dobrý deň!', '여보세요?', '你好。'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [flowcrypt] encrypted thai utf8`, + msgId: '1645e37647db32f8', + expected: { + content: ['ทดสอบ', 'นี้เป็นการทดสอบ', 'ภาษาไทย'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [facebook] encrypted utf8`, + msgId: '16180866d0ae26c3', + expected: { + content: ['Сергій Ткаченко'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey 6859679E2F20BEF4', + }, + }, + { + name: `decrypt - [enigmail] encrypted utf8`, + msgId: '1639b8ceb6c44a4c', + expected: { + content: ['TEST, ПРОВЕРКА', 'C увaжeниeм, Пaвлoвcкий Poмaн Oлeгoвич.'], + encryption: 'encrypted', + signature: 'not signed', + quoted: true, + }, + }, + { + name: `decrypt - [enigmail] encrypted pgp/mime`, + msgId: '15f7fcace2d72246', + expected: { + content: ['This is an encrypted message.', 'Not much going on here.'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [enigmail] encrypted inline`, + msgId: '15f7fcb7fabc7511', + expected: { + content: ['This is inline-encrypted message from Enigmail.', 'Yay.'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [enigmail] encrypted+signed inline`, + msgId: '15f7fd2fd072cff2', + expected: { + content: ['This message is both encrypted + signed.'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', + }, + }, + { + name: `decrypt - [enigmail] encrypted+signed pgp/mime`, + msgId: '15f7fd3ba3f37cf3', + expected: { + content: ['Message encrypted and signed using PGP/MIME.'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', + }, + }, + { + name: `decrypt - [enigmail] encrypted+signed+file pgp/mime + load from gmail`, + msgId: '15f7fd7fe45fc026', + expected: { + content: ['Message encrypted and signed as a whole using PGP/MIME.', 'cape-town-central.jpg', '185.69 kB'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey CBD1C3466E9C437F', + }, + }, + { + name: `decrypt - encrypted missing checksum`, + msgId: '15f7ffbebc6ba296', + expected: { + content: ['400 library systems in 177 countries worldwide'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - pgp/mime with large attachment - mismatch`, + msgId: '162275c819bcbf9b', + expected: { + content: ['No decryption key packets found'], + error: 'decrypt error', + expectPercentageProgress: true, + }, + }, + { + name: `decrypt - pgp/mime with large attachment as message.asc`, + msgId: '1622eaa286f90737', + expected: { + content: ['This will will have a larger attachment below', 'image-large.jpg'], + encryption: 'encrypted', + signature: 'not signed', + expectPercentageProgress: true, + }, + }, + { + name: `decrypt - pgp/mime with small attachments as message.asc`, + msgId: '16224f57d26e038e', + expected: { + content: ['Can you confirm this works.', 'Senior Consultant, Security'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey 6FC39F2CDD104B3C', + }, + }, + { + name: `decrypt - [flowcrypt] escape and keep tags in plain text`, + msgId: '1663ac8b70e22517', + expected: { + content: ['thispasswordhasainit'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [symantec] base64 german umlauts`, + msgId: '166117c082a73905', + expected: { + content: ['verspätet die gewünschte', 'Grüße', 'ä, ü, ö or ß'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [gnupg v2] thai text`, + msgId: '166147ea9bb6669d', + expected: { + content: ['still can read your message ยังคงอ่านได้อยู่', "This is time I can't read ครั้งนี้อ่านไม่ได้แล้ว"], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [gnupg v2] thai text in html`, + msgId: '16613ff9c3735102', + expected: { + content: ['เทสไทย', 'Vulnerability Assessment'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [enigmail] basic html`, + msgId: '1663a65bbd73ce1a', + expected: { + content: ['The following text is bold: this is bold'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey D97859FF68EA0F04', + }, + }, + { + name: `decrypt - [thunderbird] unicode chinese`, + msgId: '164563dc9e3a8549', + expected: { + content: ['這封信是用 Thunderbird 做加密與簽章所寄出。', '第四屆董事會成員、認證委員會委員'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey 0B38948F4CD565B5', + quoted: true, + }, + }, + { + name: `decrypt - [security] mdc - missing - error`, + msgId: '163df1bf12034b9d', + expected: { + error: 'decrypt error', + content: ['Security threat!', 'MDC', 'Display the message at your own risk.'], + unexpectedContent: ['As stated in subject', 'Shall not decrypt automatically', 'Has to show a warning'], + }, + }, + { + name: `decrypt - [security] mdc - modification detected - error`, + msgId: '163dee87a4bfed45', + expected: { + error: 'decrypt error', + content: ['Security threat - opening this message is dangerous because it was modified in transit.'], + }, + }, + { + name: `decrypt - [everdesk] message encrypted for sub but claims encryptedFor:primary,sub`, + msgId: '16d558cb71e8d510', + expected: { + content: ['this is a sample for FlowCrypt compatibility'], + encryption: 'encrypted', + signature: 'not signed', + }, + }, + { + name: `decrypt - [pep] pgp/mime message with text encoded as inline attachment`, + msgId: '16ff09b1baca2051', + expected: { + content: ['Subject: Re: Test from Tom iOS', 'test again', 'A message', 'Testing'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey A4556258EFD7EE07', + quoted: true, + }, + }, + ]; + for (const { name, acct = 'compatibility', msgId, expected } of decryptCases) { + test( + name, + testWithBrowser(async (t, browser) => { + const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, acct); + await BrowserRecipe.pgpBlockVerifyDecryptedContent(t, browser, msgId, expected, authHdr); + }) + ); + } test( - `decrypt - pgp/mime with large attachment - mismatch`, + `decrypt - [gpgmail] encrypted utf8`, testWithBrowser(async (t, browser) => { const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '162275c819bcbf9b', - { - content: ['No decryption key packets found'], - error: 'decrypt error', - expectPercentageProgress: true, - }, - authHdr - ); + const gmailPage = await browser.newPage(t, `${t.context.urls?.mockGmailUrl()}/161b2ac5a73d4097`, undefined, authHdr); + await gmailPage.waitAll('iframe'); + const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']); + await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { + content: ['Prozent => %', 'Scharf-S => ß', 'Ue => Ü', 'Ae => Ä'], + encryption: 'encrypted', + signature: 'could not verify signature: missing pubkey 9BBE40BC1E8CE4A3', + }); + await gmailPage.waitForContent('.message_inner_body', '1io | Sales & Marketing'); + await gmailPage.waitForContent('.message_inner_body', '1io GmbH'); + await gmailPage.close(); }) ); @@ -830,187 +773,6 @@ export const defineDecryptTests = (testVariant: TestVariant, testWithBrowser: Te }) ); - test( - `decrypt - pgp/mime with large attachment as message.asc`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1622eaa286f90737', - { - content: ['This will will have a larger attachment below', 'image-large.jpg'], - encryption: 'encrypted', - signature: 'not signed', - expectPercentageProgress: true, - }, - authHdr - ); - }) - ); - - test( - `decrypt - pgp/mime with small attachments as message.asc`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16224f57d26e038e', - { - content: ['Can you confirm this works.', 'Senior Consultant, Security'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey 6FC39F2CDD104B3C', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [flowcrypt] escape and keep tags in plain text`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1663ac8b70e22517', - { - content: ['thispasswordhasainit'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [symantec] base64 german umlauts`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '166117c082a73905', - { - content: ['verspätet die gewünschte', 'Grüße', 'ä, ü, ö or ß'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [gnupg v2] thai text`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '166147ea9bb6669d', - { - content: ['still can read your message ยังคงอ่านได้อยู่', "This is time I can't read ครั้งนี้อ่านไม่ได้แล้ว"], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [gnupg v2] thai text in html`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16613ff9c3735102', - { - content: ['เทสไทย', 'Vulnerability Assessment'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [enigmail] basic html`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '1663a65bbd73ce1a', - { - content: ['The following text is bold: this is bold'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey D97859FF68EA0F04', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [thunderbird] unicode chinese`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '164563dc9e3a8549', - { - content: ['這封信是用 Thunderbird 做加密與簽章所寄出。', '第四屆董事會成員、認證委員會委員'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey 0B38948F4CD565B5', - quoted: true, - }, - authHdr - ); - }) - ); - - test( - `decrypt - [security] mdc - missing - error`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '163df1bf12034b9d', - { - error: 'decrypt error', - content: ['Security threat!', 'MDC', 'Display the message at your own risk.'], - unexpectedContent: ['As stated in subject', 'Shall not decrypt automatically', 'Has to show a warning'], - }, - authHdr - ); - }) - ); - - test( - `decrypt - [security] mdc - modification detected - error`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '163dee87a4bfed45', - { - error: 'decrypt error', - content: ['Security threat - opening this message is dangerous because it was modified in transit.'], - }, - authHdr - ); - }) - ); - test( `decrypt - [security] signed message - maliciously modified - should not pass`, testWithBrowser(async (t, browser) => { @@ -1093,43 +855,6 @@ XZ8r4OC6sguP/yozWlkG+7dDxsgKQVBENeG6Lw== }) ); - test( - `decrypt - [everdesk] message encrypted for sub but claims encryptedFor:primary,sub`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16d558cb71e8d510', - { - content: ['this is a sample for FlowCrypt compatibility'], - encryption: 'encrypted', - signature: 'not signed', - }, - authHdr - ); - }) - ); - - test( - `decrypt - [pep] pgp/mime message with text encoded as inline attachment`, - testWithBrowser(async (t, browser) => { - const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility'); - await BrowserRecipe.pgpBlockVerifyDecryptedContent( - t, - browser, - '16ff09b1baca2051', - { - content: ['Subject: Re: Test from Tom iOS', 'test again', 'A message', 'Testing'], - encryption: 'encrypted', - signature: 'could not verify signature: missing pubkey A4556258EFD7EE07', - quoted: true, - }, - authHdr - ); - }) - ); - test( `compose - #5125 test passphrase anti brute force protection`, testWithBrowser(async (t, browser) => { diff --git a/test/source/tests/gmail.ts b/test/source/tests/gmail.ts index 01eaa2530f8..e4a382f435b 100644 --- a/test/source/tests/gmail.ts +++ b/test/source/tests/gmail.ts @@ -2,10 +2,11 @@ import test from 'ava'; +import { TimeoutError, connect } from 'puppeteer'; import { expect } from 'chai'; import { BrowserHandle } from './../browser/browser-handle'; -import { Controllable, ControllablePage } from './../browser/controllable'; -import { TIMEOUT_PAGE_LOAD } from './../browser'; +import { Controllable, ControllableFrame, ControllablePage } from './../browser/controllable'; +import { TIMEOUT_ELEMENT_APPEAR, TIMEOUT_PAGE_LOAD } from './../browser'; import { TestUrls } from './../browser/test-urls'; import { TestWithBrowser } from './../test'; import { TestVariant, Util } from './../util'; @@ -34,16 +35,18 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test composeFrameIndex, // Total compose frame count composeFrameCount, + replyFrame, }: { isReplyPromptAccepted?: boolean; composeFrameIndex?: number; composeFrameCount?: number; + replyFrame?: ControllableFrame; } = {} ) => { const urls = await gmailPage.getFramesUrls(['/chrome/elements/compose.htm'], { sleep: 0 }); expect(urls.length).to.equal(composeFrameCount ?? 1); if (typeof isReplyPromptAccepted !== 'undefined') { - const replyBox = await gmailPage.getFrame([urls[composeFrameIndex ?? 0]]); + const replyBox = replyFrame ?? (await gmailPage.getFrame([urls[composeFrameIndex ?? 0]])); if (isReplyPromptAccepted) { await replyBox.waitAll('@action-send'); await replyBox.notPresent('@action-accept-reply-prompt'); @@ -61,6 +64,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test content: string, params: { offline: boolean } = { offline: false } ) => { + await GmailPageRecipe.dismissMobileNotificationsPrompt(gmailPage); let composeBox: Controllable | undefined; if (params.offline) { // TODO(@limonte): for some reason iframe is able to save the draft to the cloud even @@ -86,10 +90,15 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test const pageHasSecureDraft = async (gmailPage: ControllablePage, expectedContent?: string) => { const secureDraftFrame = await gmailPage.getFrame(['/chrome/elements/compose.htm', '&draftId='], { sleep: 2 }); await Util.sleep(3); - // Wait for the iframe content to load - @input-body must exist first - await secureDraftFrame.waitAll('@input-body'); - if (expectedContent) { - await secureDraftFrame.waitForContent('@input-body', expectedContent); + try { + // Wait for the iframe content to load - @input-body must exist first + await secureDraftFrame.waitAll('@input-body'); + if (expectedContent) { + await secureDraftFrame.waitForContent('@input-body', expectedContent); + } + } catch (e) { + gmailPage.t.log(`Selected draft frame at failure: ${secureDraftFrame.frame.url()} (detached: ${secureDraftFrame.frame.detached})`); + throw e; } return secureDraftFrame; }; @@ -99,18 +108,59 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test expect(urls.length).to.equal(0); }; - const openGmailPage = async (t: AvaContext, browser: BrowserHandle, path?: string): Promise => { - let url = TestUrls.gmail(0); - if (path) { - url = TestUrls.gmail(0, path, 'inbox'); + const gotoGmailPage = async ( + gmailPage: ControllablePage, + { path = '', category = 'inbox', subject }: { path?: string; category?: GmailCategory; subject?: string } = {} + ) => { + await gmailPage.page.goto(TestUrls.gmail(0, path, category), { waitUntil: 'domcontentloaded', timeout: TIMEOUT_PAGE_LOAD * 1000 }); + if (subject !== undefined) { + await gmailPage.waitForContent('h2.hP', subject, TIMEOUT_PAGE_LOAD); + } else { + await gmailPage.waitAll(path ? 'h2.hP' : '[role="main"]', { timeout: TIMEOUT_PAGE_LOAD }); } - return await browser.newPage(t, url); + await gmailPage.waitAll('@action-secure-compose', { timeout: TIMEOUT_PAGE_LOAD }); + await GmailPageRecipe.dismissMobileNotificationsPrompt(gmailPage); + return gmailPage; }; - const gotoGmailPage = async (gmailPage: ControllablePage, path: string, category: GmailCategory = 'inbox') => { - const url = TestUrls.gmail(0, path, category); - await Util.sleep(1); - await gmailPage.goto(url); + const plainConversation = { path: '/FMfcgzGkbDRNgcQxLmkhBCKVSFwkfdvV', subject: '[ci.test] plain email' }; + const replyAllConversation = { + path: '/FMfcgzGtwgfMhWTlgRwwKWzRhqNZzwXz', + subject: 'Encrypted message with 2 recipients for reply-all test', + }; + + const withReattachedGmailPage = async (browser: BrowserHandle, gmailPage: ControllablePage, action: (page: ControllablePage) => Promise) => { + // Attach after the extension iframe is present so Puppeteer can see its execution context. + const attachedBrowser = await connect({ + browserWSEndpoint: browser.browser.wsEndpoint(), + defaultViewport: gmailPage.page.viewport(), + protocolTimeout: TIMEOUT_PAGE_LOAD * 1000, + }); + try { + const attachedPage = (await attachedBrowser.pages()).find(page => page.url() === gmailPage.page.url()); + if (!attachedPage) { + throw new Error('Could not reattach to the Gmail tab'); + } + await action(new ControllablePage(gmailPage.t, attachedPage)); + } finally { + await attachedBrowser.disconnect(); + } + }; + + const replyIframe = 'iframe.reply_message[src*="/chrome/elements/compose.htm"]'; + const getEditableGmailReply = async (gmailPage: ControllablePage) => { + const skipPrompt = '&skipClickPrompt=___cu_true___'; + await gmailPage.waitAll(`${replyIframe}[src*="${skipPrompt}"]`); + return await gmailPage.getFrame(['/chrome/elements/compose.htm', skipPrompt], { sleep: 0 }); + }; + + const messageMenu = '[aria-label="More message options"]'; + const clickGmailControl = async (gmailPage: ControllablePage, selector: string) => { + await gmailPage.target + .locator(selector) + .setVisibility('visible') + .setTimeout(TIMEOUT_ELEMENT_APPEAR * 1000) + .click(); }; test( @@ -131,7 +181,8 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test async (t, browser) => { const acctEmail = 'ci.tests.gmail@flowcrypt.dev'; await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await BrowserRecipe.openGmailPageAndVerifyComposeBtnPresent(t, browser); + const gmailPage = await gotoGmailPage(await browser.newPage(t)); + await GmailPageRecipe.closeInitialSetupNotif(gmailPage); const composePage = await GmailPageRecipe.openSecureComposeWithRichTextWorkaround(t, gmailPage, browser); const subject = `New Rich Text Message ${Util.lousyRandom()}`; await ComposePageRecipe.fillMsg(composePage, { to: acctEmail }, subject, undefined, { @@ -154,13 +205,13 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test test( 'mail.google.com - back button works in offline mode', testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDWztBnnCgRHzjrvmFqLtcJD'); + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + const gmailPage = await gotoGmailPage(await browser.newPage(t)); + await gotoGmailPage(gmailPage, { path: '/FMfcgzGkbDWztBnnCgRHzjrvmFqLtcJD' }); const expectedMessage = { content: ['this should decrypt even offline'], signature: 'signed', encryption: 'encrypted' }; await Util.sleep(5); await BrowserRecipe.pgpBlockCheck(t, await gmailPage.getFrame(['/chrome/elements/pgp_block.htm'], { sleep: 10, timeout: 25 }), expectedMessage); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDRNgcQxLmkhBCKVSFwkfdvV'); // plain convo + await gotoGmailPage(gmailPage, plainConversation); await gmailPage.page.setOfflineMode(true); // go offline mode await gmailPage.page.goBack({ waitUntil: 'load' }); await BrowserRecipe.pgpBlockCheck(t, await gmailPage.getFrame(['/chrome/elements/pgp_block.htm']), expectedMessage); @@ -170,22 +221,21 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test test( 'mail.google.com - attachments rendered correctly', testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDXBWBWBfVKHssLtMqvDQSWN'); + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGkbDXBWBWBfVKHssLtMqvDQSWN' }); // Check if rendering attachments coorectly await gmailPage.waitForContent('.aVW span:first-child', '36'); const urls = await gmailPage.getFramesUrls(['/chrome/elements/attachment.htm']); expect(urls.length).to.equal(36); // simple attachments triggering processAttachments() keep "download all" button visible - await gotoGmailPage(gmailPage, '/KtbxLvHkSWwbVHxgCbWNvXVKGjFgqMbGQq'); + await gotoGmailPage(gmailPage, { path: '/KtbxLvHkSWwbVHxgCbWNvXVKGjFgqMbGQq' }); await Util.sleep(5); await gmailPage.waitAll('iframe'); await gmailPage.waitAll(['.pYTkkf-JX-ano'], { visible: true }); // attachments which contain emoji in filename are rendered correctly - await gotoGmailPage(gmailPage, '/FMfcgzGtwqFGhMwWtLRjkPJlQlZHSlrW'); + await gotoGmailPage(gmailPage, { path: '/FMfcgzGtwqFGhMwWtLRjkPJlQlZHSlrW' }); await Util.sleep(5); await gmailPage.waitAll('iframe'); await gmailPage.waitAll(['.aZo'], { visible: false }); @@ -201,8 +251,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test 'mail.google.com - msg.asc message content renders', testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/QgrcJHrtqfgLGKqwChjKsHKzZQpwRHMBqpG'); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/QgrcJHrtqfgLGKqwChjKsHKzZQpwRHMBqpG' }); await gmailPage.waitAll('@action-show-original-conversation'); const urls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { sleep: 10, appearIn: 25 }); expect(urls.length).to.equal(1); @@ -218,76 +267,42 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test ); test( - 'mail.google.com - Thunderbird signature [html] is recognized', - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDZKPJrNLplXZhKfWwtgjrXt'); - // validate pgp_block.htm is rendered - const pgpBlockUrls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { - sleep: 10, - appearIn: 25, - }); - expect(pgpBlockUrls.length).to.equal(1); - const pgpBlockFrame = await gmailPage.getFrame([pgpBlockUrls[0]]); - await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { - content: ['1234'], - encryption: 'not encrypted', - signature: 'signed', - }); - await pageHasSecureReplyContainer(t, browser, gmailPage); - await testMinimumElementHeight(gmailPage, '.pgp_block.signedDetached', 80); - await testMinimumElementHeight(gmailPage, '.pgp_block.publicKey', 120); - const pubkeyPage = await gmailPage.getFrame(['/chrome/elements/pgp_pubkey.htm']); - await pubkeyPage.waitForContent('@container-pgp-pubkey', 'Fingerprint: 50B7 A032 B5E1 FBAB 24BA B205 B362 45FD AC2F BF3D'); - expect(await gmailPage.isElementVisible('.aQH')).to.equal(false); // original attachment container(s) should be hidden - }) - ); - - test( - 'mail.google.com - Thunderbird signature [plain] is recognized + correct height', - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDZKPKzSnGtGKZrPZSbTBNnB'); - // validate pgp_block.htm is rendered - const pgpBlockUrls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { - sleep: 10, - appearIn: 25, - }); - expect(pgpBlockUrls.length).to.equal(1); - await testMinimumElementHeight(gmailPage, '.pgp_block.signedDetached', 80); - await testMinimumElementHeight(gmailPage, '.pgp_block.publicKey', 120); - const pgpBlockFrame = await gmailPage.getFrame([pgpBlockUrls[0]]); - await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { - content: ['1234'], - encryption: 'not encrypted', - signature: 'signed', - }); - await pageHasSecureReplyContainer(t, browser, gmailPage); - const pubkeyPage = await gmailPage.getFrame(['/chrome/elements/pgp_pubkey.htm']); - await pubkeyPage.waitForContent('@container-pgp-pubkey', 'Fingerprint: 50B7 A032 B5E1 FBAB 24BA B205 B362 45FD AC2F BF3D'); - expect(await gmailPage.isElementVisible('.aQH')).to.equal(false); // original attachment container(s) should be hidden - }) - ); - - test( - 'mail.google.com - pubkey gets rendered with new signed and encrypted Thunderbird signature', - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDZKPLBqWFzbgWqCrplTQdNz'); - const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm'], { sleep: 10, timeout: 25 }); - await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { - content: ['Encrypted Subject: [ci.test] Thunderbird html signed + encrypted', '1234'], - encryption: 'encrypted', - signature: 'signed', - }); - await pageHasSecureReplyContainer(t, browser, gmailPage); - const pubkeyPage = await gmailPage.getFrame(['/chrome/elements/pgp_pubkey.htm']); - await pubkeyPage.waitForContent('@container-pgp-pubkey', 'Fingerprint: 50B7 A032 B5E1 FBAB 24BA B205 B362 45FD AC2F BF3D'); - expect(await gmailPage.isElementVisible('.aQH')).to.equal(false); // original attachment container(s) should be hidden - }) + 'mail.google.com - Thunderbird HTML signed, plain signed, and signed + encrypted messages render correctly', + testWithBrowser( + async (t, browser) => { + t.timeout(minutes(6)); // allow time for account setup and all three messages + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + for (const { format, path, encrypted } of [ + { format: 'HTML signed', path: '/FMfcgzGkbDZKPJrNLplXZhKfWwtgjrXt', encrypted: false }, + { format: 'plain signed', path: '/FMfcgzGkbDZKPKzSnGtGKZrPZSbTBNnB', encrypted: false }, + { format: 'signed + encrypted', path: '/FMfcgzGkbDZKPLBqWFzbgWqCrplTQdNz', encrypted: true }, + ]) { + t.log(`Thunderbird message: ${format}`); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path }); + const pgpBlockFrame = await gmailPage.getFrame(['/chrome/elements/pgp_block.htm'], { sleep: 0, timeout: 35 }); + await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { + content: encrypted ? ['Encrypted Subject: [ci.test] Thunderbird html signed + encrypted', '1234'] : ['1234'], + encryption: encrypted ? 'encrypted' : 'not encrypted', + signature: 'signed', + }); + await pageHasSecureReplyContainer(t, browser, gmailPage); + await gmailPage.waitAll('iframe.pgp_block.publicKey'); + await withReattachedGmailPage(browser, gmailPage, async attachedPage => { + const pubkeyFrame = await attachedPage.getFrame(['/chrome/elements/pgp_pubkey.htm'], { sleep: 0 }); + await pubkeyFrame.waitForContent('@container-pgp-pubkey', 'Fingerprint: 50B7 A032 B5E1 FBAB 24BA B205 B362 45FD AC2F BF3D'); + }); + if (!encrypted) { + expect(await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { sleep: 0 })).to.have.length(1); + await testMinimumElementHeight(gmailPage, '.pgp_block.signedDetached', 80); + await testMinimumElementHeight(gmailPage, '.pgp_block.publicKey', 120); + } + expect(await gmailPage.isElementVisible('.aQH')).to.equal(false); // original attachment container(s) should be hidden + await gmailPage.close(); + } + }, + undefined, + minutes(6) + ) ); // draft-sensitive test @@ -297,7 +312,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); t.timeout(minutes(6)); // extend ava's timeout - const gmailPage = await openGmailPage(t, browser); + const gmailPage = await gotoGmailPage(await browser.newPage(t)); // create compose draft await gmailPage.waitAndClick('@action-secure-compose', { delay: 1 }); await createSecureDraft(t, browser, gmailPage, 'compose draft 1', { offline: true }); @@ -331,23 +346,22 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test testWithBrowser( async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); const threadId = '19ae97b85fe4f50e'; // 1st message -- thread id - await gotoGmailPage(gmailPage, `/${threadId}`); // go to encrypted convo + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: `/${threadId}` }); await GmailPageRecipe.trimConvo(gmailPage, threadId); await gmailPage.waitAndClick('@secure-reply-button'); - let replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); + const replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); await Util.sleep(3); expect(await replyBox.read('@recipients-preview')).to.equal('e2e.enterprise.test@flowcrypt.com'); await createSecureDraft(t, browser, gmailPage, 'reply draft'); await createSecureDraft(t, browser, gmailPage, 'offline reply draft', { offline: true }); - await gmailPage.reload({ timeout: TIMEOUT_PAGE_LOAD * 1000, waitUntil: 'load' }, true); - // Wait for extension to re-inject iframes after reload - await gmailPage.waitForIframes(3, 25); // 3 attempts, 25s each - await Util.sleep(5); // Let Gmail settle after reload - replyBox = await pageHasSecureDraft(gmailPage, 'offline reply draft'); - await Util.sleep(2); - await replyBox.waitAndClick('@action-send', { confirmGone: true }); + await gmailPage.reload({ timeout: TIMEOUT_PAGE_LOAD * 1000, waitUntil: 'domcontentloaded' }, true); + await gmailPage.waitAll(`${replyIframe}[src*="&draftId="]`); + await withReattachedGmailPage(browser, gmailPage, async attachedPage => { + const restoredReply = await pageHasSecureDraft(attachedPage, 'offline reply draft'); + await GmailPageRecipe.dismissMobileNotificationsPrompt(attachedPage); + await restoredReply.waitAndClick('@action-send', { confirmGone: true }); + }); await Util.sleep(2); await gmailPage.reload({ timeout: TIMEOUT_PAGE_LOAD * 1000, waitUntil: 'load' }, true); await gmailPage.waitAndClick('.h7:last-child .ajz', { delay: 1 }); // the small triangle which toggles the message details @@ -366,13 +380,13 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); t.timeout(minutes(4)); // extend ava's timeout - const gmailPage = await openGmailPage(t, browser); + const gmailPage = await gotoGmailPage(await browser.newPage(t)); // create compose draft await gmailPage.waitAndClick('@action-secure-compose', { delay: 1 }); await createSecureDraft(t, browser, gmailPage, 'a compose draft'); await gmailPage.reload({ timeout: TIMEOUT_PAGE_LOAD * 1000, waitUntil: 'load' }); t.timeout(minutes(4)); // extend ava's timeout - await gotoGmailPage(gmailPage, '', 'drafts'); // to go drafts section + await gotoGmailPage(gmailPage, { category: 'drafts' }); // open new compose window and saved draft await gmailPage.waitAndClick('@action-secure-compose', { delay: 1 }); await gmailPage.waitAndClick('//*[text()="Draft"]'); @@ -394,10 +408,8 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test test( 'mail.google.com - plain message contains smart replies', testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await Util.sleep(1); - await gotoGmailPage(gmailPage, '/FMfcgzGpHHKCrKRLptBSNwkpMxzkdcQc'); // plain convo with smart replies + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGpHHKCrKRLptBSNwkpMxzkdcQc' }); await gmailPage.waitForContent('.brb', 'Yes'); }) ); @@ -406,22 +418,26 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test 'mail.google.com - plain reply to encrypted and signed messages', testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - let gmailPage = await openGmailPage(t, browser, '/FMfcgzGkbDRNgcQxLmkhBCKVSFwkfdvV'); // plain convo - await gmailPage.waitAndClick('div.adn [aria-label="Reply"]', { delay: 1 }); + let gmailPage = await gotoGmailPage(await browser.newPage(t), plainConversation); + await clickGmailControl(gmailPage, 'div.adn [aria-label="Reply"]'); + await gmailPage.waitAll('[data-tooltip^="Send"]'); await gmailPage.close(); - gmailPage = await openGmailPage(t, browser, '/181d226b4e69f172'); // go to encrypted convo - await gmailPage.waitAndClick('div.adn [aria-label="Reply"]', { delay: 1 }); + gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/181d226b4e69f172' }); + await clickGmailControl(gmailPage, 'div.adn [aria-label="Reply"]'); await gmailPage.waitTillGone('.reply_message'); await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box await gmailPage.waitForContent( '.reply_message_evaluated .error_notification', 'The last message was encrypted, but you are composing a reply without encryption.' ); - await gmailPage.waitAndClick('[data-tooltip="Secure Reply"]'); // Switch to encrypted reply + await clickGmailControl(gmailPage, '[data-tooltip="Secure Reply"]'); await gmailPage.waitAll('.reply_message'); await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true }); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDRNpjDdNvCrwzqvXspZZxvh'); // go to signed convo - await gmailPage.waitAndClick('div.adn [aria-label="Reply"]', { delay: 1 }); + await gmailPage.close(); + gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGkbDRNpjDdNvCrwzqvXspZZxvh', subject: '[ci.test] signed email' }); + await gmailPage.waitAll('iframe.pgp_block.signedMsg'); + t.log('Opening Gmail Reply on the signed message'); + await clickGmailControl(gmailPage, 'div.adn button[aria-label="Reply"]'); await gmailPage.waitTillGone('.reply_message'); await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box await gmailPage.notPresent('.reply_message_evaluated .error_notification'); // should not show the warning about switching to encrypted reply @@ -429,86 +445,107 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test ); // https://github.com/FlowCrypt/flowcrypt-browser/issues/5906 - test( - 'mail.google.com - Keep original reply message when switching to secure mode', - testWithBrowser( - async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGqRGfPBbNLWvfPvDbxnHBwkdGf'); // plain convo - await Util.sleep(30); - await gmailPage.waitAndClick('[role="listitem"] .adf.ads', { delay: 1 }); // click first message of thread - await Util.sleep(3); - const messages = await gmailPage.target.$$('[role="listitem"] .adn.ads'); - const plainReplyButton = await messages[0].$('[aria-label="Reply"]'); - await Util.sleep(1); - await plainReplyButton!.click(); - await gmailPage.waitAndClick('#switch_to_encrypted_reply'); // Switch to encrypted compose - await Util.sleep(2); - await gmailPage.waitAll('.reply_message'); - await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true, composeFrameCount: 2 }); - const replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm', '&skipClickPrompt=___cu_true___'], { sleep: 5 }); - await replyBox.waitAll(['@action-expand-quoted-text']); - await replyBox.waitAndClick('@action-expand-quoted-text'); - // Check if quoted message doesn't contain last message - expect(await replyBox.read('@input-body')).to.not.contain(`Here's reply`); - }, - undefined, - minutes(6) - ) - ); - - test( - 'mail.google.com - switch to encrypted reply for middle message', - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGqRGfPBbNLWvfPvDbxnHBwkdGf'); // plain convo - await gmailPage.waitAndClick('[role="listitem"] .adf.ads', { delay: 1 }); // click first message of thread - await Util.sleep(3); - const messages = await gmailPage.target.$$('[role="listitem"] .adn.ads'); - expect(messages.length).to.equal(2); - - const plainReplyButton = await messages[0].$('[aria-label="Reply"]'); - expect(plainReplyButton).to.be.ok; - await Util.sleep(1); - await plainReplyButton!.click(); - await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box - await gmailPage.waitForContent( - '.reply_message_evaluated .error_notification', - 'The last message was encrypted, but you are composing a reply without encryption.' - ); + const openOlderReplyConversation = async (t: AvaContext, browser: BrowserHandle) => { + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); + return await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGqRGfPBbNLWvfPvDbxnHBwkdGf' }); + }; + const expandedMessageSelector = '[role="listitem"] .adn.ads'; + const getExpandedMessage = async (gmailPage: ControllablePage, index: number) => { + const id = await gmailPage.target.$$eval(expandedMessageSelector, (messages, i) => messages.at(i)?.getAttribute('data-legacy-message-id'), index); + if (!id) { + throw new Error(`No Gmail message ID found at index ${index}`); + } + return `${expandedMessageSelector}[data-legacy-message-id="${id}"]`; + }; + const expandOlderMessage = async (gmailPage: ControllablePage) => { + await clickGmailControl(gmailPage, '[role="listitem"] .adf.ads'); // expand first message of thread + await gmailPage.target.waitForFunction( + selector => document.querySelectorAll(selector).length === 2, + { timeout: TIMEOUT_ELEMENT_APPEAR * 1000 }, + expandedMessageSelector + ); + return await getExpandedMessage(gmailPage, 0); + }; - const secureReplyButton = await messages[0].$('[data-tooltip="Secure Reply"]'); - expect(secureReplyButton).to.be.ok; - await secureReplyButton!.click(); // Switch to encrypted reply - await gmailPage.waitAll('.reply_message'); - await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true, composeFrameCount: 2 }); - }) - ); + const olderReplyCases = [ + { control: 'warning link', selector: () => '#switch_to_encrypted_reply', checkQuotedText: true }, + { control: 'Secure Reply button', selector: (message: string) => `${message} [data-tooltip="Secure Reply"]`, checkQuotedText: false }, + ]; + // These tests share a live account and conversation. Account setup clears drafts before each case. + for (const { control, selector, checkQuotedText } of olderReplyCases) { + test.serial( + `mail.google.com - switch older-message reply to secure using the ${control}`, + testWithBrowser( + async (t, browser) => { + const gmailPage = await openOlderReplyConversation(t, browser); + const olderMessage = await expandOlderMessage(gmailPage); + await clickGmailControl(gmailPage, `${olderMessage} [aria-label="Reply"]`); + await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box + await gmailPage.waitForContent( + '.reply_message_evaluated .error_notification', + 'The last message was encrypted, but you are composing a reply without encryption.' + ); + + await clickGmailControl(gmailPage, selector(olderMessage)); + const replyBox = await getEditableGmailReply(gmailPage); + await replyBox.waitAll('@input-body'); + await gmailPage.target.waitForFunction(() => document.querySelectorAll('iframe[src*="/chrome/elements/compose.htm"]').length === 2, { + timeout: TIMEOUT_ELEMENT_APPEAR * 1000, + }); + await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true, composeFrameCount: 2, replyFrame: replyBox }); + if (checkQuotedText) { + await replyBox.waitAndClick('@action-expand-quoted-text', { delay: 0 }); + // The quote should exclude text from the newest message. + expect(await replyBox.read('@input-body')).to.not.contain(`Here's reply`); + } + }, + undefined, + minutes(6) + ) + ); + } + + for (const messagePosition of ['newest', 'older']) { + test.serial( + `mail.google.com - ${messagePosition} message menu shows the secure reply button`, + testWithBrowser( + async (t, browser) => { + const gmailPage = await openOlderReplyConversation(t, browser); + await gmailPage.waitAll(`${expandedMessageSelector} ${messageMenu}`); + const message = messagePosition === 'older' ? await expandOlderMessage(gmailPage) : await getExpandedMessage(gmailPage, -1); + await gmailPage.waitAll(`${message} iframe.pgp_block.encryptedMsg`); + const menu = `${message} ${messageMenu}`; + await gmailPage.waitAndFocus(menu); + await gmailPage.press('Enter'); + await gmailPage.waitAll(`${menu}[aria-expanded="true"]`); + await gmailPage.waitAll('@action-reply-message-button'); + }, + undefined, + minutes(6) + ) + ); + } test( 'mail.google.com - plain reply with dot menu', testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDRNgcQxLmkhBCKVSFwkfdvV'); // plain convo - await gmailPage.waitAndClick('div.adn [aria-label="Reply"]', { delay: 1 }); - await gotoGmailPage(gmailPage, '/FMfcgzGtwgfMhWTlgRwwKWzRhqNZzwXz'); // go to encrypted convo - await Util.sleep(5); - await gmailPage.waitAndClick('.adn [aria-label="More message options"]', { delay: 1 }); - await gmailPage.waitAndClick('li[data-action-type="24"]', { delay: 1 }); // click reply-all - await Util.sleep(3); + const gmailPage = await gotoGmailPage(await browser.newPage(t), plainConversation); + await clickGmailControl(gmailPage, 'div.adn [aria-label="Reply"]'); + await gmailPage.waitAll('[data-tooltip^="Send"]'); + await gotoGmailPage(gmailPage, replyAllConversation); + await gmailPage.waitAll('iframe.pgp_block'); + await clickGmailControl(gmailPage, `.adn ${messageMenu}`); + await clickGmailControl(gmailPage, 'li[data-action-type="24"]'); // click reply-all await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box await gmailPage.waitForContent( '.reply_message_evaluated .error_notification', 'The last message was encrypted, but you are composing a reply without encryption.' ); - await gmailPage.waitAndClick('[data-tooltip="Secure Reply"]'); // Switch to encrypted reply - await gmailPage.waitAll('.reply_message'); - await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true }); - const replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); - await Util.sleep(3); + await clickGmailControl(gmailPage, '[data-tooltip="Secure Reply"]'); + const replyBox = await getEditableGmailReply(gmailPage); + await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true, replyFrame: replyBox }); + await replyBox.waitForSelTestState('ready'); expect(await replyBox.read('@recipients-preview')).to.equal(['flowcrypt.compatibility@gmail.com', 'e2e.enterprise.test@flowcrypt.com'].join('')); }) ); @@ -517,10 +554,9 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test test( 'mail.google.com - test reply all for password protected message', testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzQZTMHNLflWQjRcSvWlMsKbLhpr'); - await gmailPage.waitAndClick('.adn [aria-label="More message options"]', { delay: 1 }); + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzQZTMHNLflWQjRcSvWlMsKbLhpr' }); + await clickGmailControl(gmailPage, `.adn ${messageMenu}`); await gmailPage.waitAll('.action_reply_all_message_button'); }) ); @@ -530,22 +566,18 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test testWithBrowser( async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGtwgfMhWTlgRwwKWzRhqNZzwXz'); // go to encrypted convo - await Util.sleep(5); - await gmailPage.waitAndClick('.adn [aria-label="More message options"]', { delay: 1 }); - await gmailPage.waitAndClick('li[data-action-type="25"]', { delay: 1 }); // click forward - await Util.sleep(3); + const gmailPage = await gotoGmailPage(await browser.newPage(t), replyAllConversation); + await gmailPage.waitAll('iframe.pgp_block'); + await clickGmailControl(gmailPage, `.adn ${messageMenu}`); + await clickGmailControl(gmailPage, 'li[data-action-type="25"]'); // click forward await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box await gmailPage.waitForContent( '.reply_message_evaluated .error_notification', 'The last message was encrypted, but you are composing a message without encryption. Switch to encrypted compose' ); - await gmailPage.waitAndClick('#switch_to_encrypted_reply'); // Switch to encrypted compose - await Util.sleep(3); - const replyBox2 = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); - await Util.sleep(3); - await replyBox2.waitForContent('@input-body', '---------- Forwarded message ---------'); + await clickGmailControl(gmailPage, '#switch_to_encrypted_reply'); + const replyBox = await getEditableGmailReply(gmailPage); + await replyBox.waitForContent('@input-body', '---------- Forwarded message ---------'); }, undefined, minutes(6) @@ -556,29 +588,62 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test 'mail.google.com - secure reply and forward in dot menu', testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGtwgfMhWTlgRwwKWzRhqNZzwXz'); // go to encrypted convo - const gmailContextMenu = '.adn [aria-label="More message options"]'; - await gmailPage.waitAndClick(gmailContextMenu); - await Util.sleep(1); - expect(await gmailPage.isElementPresent('@action-reply-message-button')); - await gmailPage.waitAndClick('@action-reply-message-button'); - const replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); - await replyBox.waitForContent('@input-body', ''); - await gmailPage.waitAndClick(gmailContextMenu); - await Util.sleep(1); - expect(await gmailPage.isElementPresent('@action-reply-all-message-button')); - await gmailPage.waitAndClick('@action-reply-all-message-button'); - const replyBox2 = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); - await replyBox2.waitForContent('@input-body', ''); - const recipientsCount = await replyBox2.target.$$eval('.email_address', elements => elements.length); - expect(recipientsCount).to.equal(2); - await gmailPage.waitAndClick(gmailContextMenu); - await Util.sleep(1); - expect(await gmailPage.isElementPresent('@action-forward-message-button')); - await gmailPage.waitAndClick('@action-forward-message-button'); - const replyBox3 = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 }); - await replyBox3.waitForContent('@input-body', '---------- Forwarded message ---------'); + const gmailPage = await gotoGmailPage(await browser.newPage(t), replyAllConversation); + await gmailPage.waitAll(`${replyIframe}[src*="&skipClickPrompt=___cu_false___"]`); + const gmailContextMenu = `[role="listitem"] .adn.ads ${messageMenu}`; + for (const action of ['reply', 'reply-all', 'forward'] as const) { + t.log(`Opening secure ${action} from the message menu`); + const menuItem = `[data-test="action-${action}-message-button"]`; + await clickGmailControl(gmailPage, gmailContextMenu); + await clickGmailControl(gmailPage, menuItem); + const replyOption = `a_${action.replace('-', '_')}`; + const iframe = await gmailPage.waitAny(`${replyIframe}[src*="&skipClickPrompt=___cu_true___"][src*="&replyOption=${replyOption}&"]`); + let composerUrl: string; + try { + await gmailPage.waitTillGone(menuItem); + composerUrl = await iframe.evaluate(el => (el as HTMLIFrameElement).src); + } finally { + await iframe.dispose(); + } + + const getReadableComposer = async (page: ControllablePage) => { + const composer = await page.getFrame([composerUrl], { sleep: 0 }); + // Check that Puppeteer can evaluate in the frame independently of composer readiness. + const probe = await composer.frame.waitForFunction(() => true, { timeout: TIMEOUT_ELEMENT_APPEAR * 1000 }); + await probe.dispose(); + return composer; + }; + + const checkComposer = async (composer: ControllableFrame) => { + await composer.waitUntilViewLoaded(); + await composer.waitAll(['@input-body', '@action-send']); + if (action === 'reply-all') { + await composer.waitForSelTestState('ready'); + const visibleRecipients = await composer.target.$$eval( + '[data-test="recipients-preview"] .email_address', + elements => elements.filter(element => element.checkVisibility({ visibilityProperty: true })).length + ); + expect(visibleRecipients).to.equal(2); + } else if (action === 'forward') { + await composer.waitForContent('@input-body', '---------- Forwarded message ---------'); + } + }; + + let composer: ControllableFrame; + try { + composer = await getReadableComposer(gmailPage); + } catch (e) { + if (!(e instanceof TimeoutError)) { + throw e; + } + t.log(`Reattaching to the Gmail tab after the secure ${action} iframe evaluation timed out`); + await withReattachedGmailPage(browser, gmailPage, async attachedPage => { + await checkComposer(await getReadableComposer(attachedPage)); + }); + continue; + } + await checkComposer(composer); + } }) ); @@ -589,7 +654,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); const threadId = '181d226b4e69f172'; // 1st message -- thread id - const gmailPage = await openGmailPage(t, browser, `/${threadId}`); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: `/${threadId}` }); await GmailPageRecipe.trimConvo(gmailPage, threadId); await gmailPage.waitAndClick('div.adn [aria-label="Reply"]', { delay: 5 }); t.timeout(minutes(2)); // extend ava's timeout @@ -609,7 +674,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test ); test( - 'mail.google.com - Outlook encrypted message with attachment is recognized', + 'mail.google.com - compatibility-key attachments: Outlook message and encrypted "message" attachment are recognized', testWithBrowser(async (t, browser) => { const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, 'ci.tests.gmail@flowcrypt.dev'); await SetupPageRecipe.manualEnter( @@ -618,29 +683,16 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test { submitPubkey: false, usedPgpBefore: true }, { isSavePassphraseChecked: false, isSavePassphraseHidden: false } ); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGllVqqBbjHQQRDsSwcZBlMRzDr'); + t.log('Outlook encrypted message with attachment'); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGllVqqBbjHQQRDsSwcZBlMRzDr' }); await Util.sleep(5); await gmailPage.waitAll('iframe'); expect(await gmailPage.isElementPresent('@container-attachments')).to.equal(false); await gmailPage.waitAll(['.pYTkkf-JX-ano'], { visible: false }); expect(await gmailPage.isElementVisible('.aQH')).to.equal(false); // original attachment container(s) should be hidden - await gmailPage.close(); - }) - ); - test( - `mail.google.com - encrypted text inside "message" attachment`, - testWithBrowser(async (t, browser) => { - const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, 'ci.tests.gmail@flowcrypt.dev'); - await SetupPageRecipe.manualEnter( - settingsPage, - 'flowcrypt.compatibility.1pp1', - { submitPubkey: false, usedPgpBefore: true }, - { isSavePassphraseChecked: false, isSavePassphraseHidden: false } - ); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGrbHprlHvtTJscCJQpZcqrKQbg'); + t.log('Encrypted text inside "message" attachment'); + await gotoGmailPage(gmailPage, { path: '/FMfcgzGrbHprlHvtTJscCJQpZcqrKQbg' }); await Util.sleep(5); await gmailPage.waitAll('iframe'); expect(await gmailPage.isElementPresent('@container-attachments')).to.equal(false); @@ -650,11 +702,11 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test ); test( - `mail.google.com - large clipped PGP/MIME encrypted message rendered correctly`, + `mail.google.com - large clipped PGP/MIME messages render correctly, including a text/plain attachment`, testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGtxKSjjzhRZRRzddjMvJnpDRQf'); + t.log('Regular clipped PGP/MIME message'); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGtxKSjjzhRZRRzddjMvJnpDRQf' }); const urls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { sleep: 10, appearIn: 25 }); expect(urls.length).to.equal(1); const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']); @@ -664,20 +716,14 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test signature: 'signed', }); await pageHasSecureReplyContainer(t, browser, gmailPage); - }) - ); - // https://github.com/FlowCrypt/flowcrypt-browser/issues/6171 - test( - `mail.google.com - large clipped PGP/MIME message with text/plain attachment decrypts`, - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzQfBspgLbfNnBHGtlBsFtcLGPsr'); - const urls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { sleep: 10, appearIn: 25 }); - expect(urls.length).to.equal(1); - const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']); - await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, { + // https://github.com/FlowCrypt/flowcrypt-browser/issues/6171 + t.log('Clipped PGP/MIME message with text/plain attachment'); + await gotoGmailPage(gmailPage, { path: '/FMfcgzQfBspgLbfNnBHGtlBsFtcLGPsr' }); + const attachmentUrls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_block.htm'], { sleep: 10, appearIn: 25 }); + expect(attachmentUrls.length).to.equal(1); + const attachmentPgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']); + await BrowserRecipe.pgpBlockCheck(t, attachmentPgpBlockFrame, { content: ['Test large clipped message'], encryption: 'encrypted', signature: 'not signed', @@ -688,9 +734,8 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test test( `mail.google.com - render plain text for "message" attachment (which has plain text)`, testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGrbHrBdFGBXqpFZvSkcQpKkvrM'); + await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail', { cleanUpDrafts: false }); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGrbHrBdFGBXqpFZvSkcQpKkvrM' }); await Util.sleep(5); await gmailPage.waitForContent('.a3s', 'Plain message'); expect(await gmailPage.isElementPresent('.aQH')).to.equal(true); // gmail attachment container @@ -704,8 +749,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test 'mail.google.com - pubkey file gets rendered', testWithBrowser(async (t, browser) => { await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - await gotoGmailPage(gmailPage, '/FMfcgzGkbDXBWCgTcMJlmBtfNxrbzTTn'); + const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/FMfcgzGkbDXBWCgTcMJlmBtfNxrbzTTn' }); const urls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_pubkey.htm']); expect(urls.length).to.equal(1); await pageHasSecureReplyContainer(t, browser, gmailPage); @@ -729,7 +773,7 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test // todo - missing equivalent sample at ci.tests.gmail // test('mail.google.com - pubkey gets rendered when using quoted-printable mime', testWithBrowser('compatibility', async (t, browser) => { - // const gmailPage = await openGmailPage(t, browser, '/WhctKJVRFztXGwvSbwcrbDshGTnLWMFvhwJmhqllRWwvpKnlpblQMXVZLTsKfWdPWKhPFBV'); + // const gmailPage = await gotoGmailPage(await browser.newPage(t), { path: '/WhctKJVRFztXGwvSbwcrbDshGTnLWMFvhwJmhqllRWwvpKnlpblQMXVZLTsKfWdPWKhPFBV' }); // const urls = await gmailPage.getFramesUrls(['/chrome/elements/pgp_pubkey.htm'], { sleep: 10, appearIn: 20 }); // expect(urls.length).to.equal(1); // await pageHasSecureReplyContainer(t, browser, gmailPage); @@ -738,44 +782,6 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test // expect(content).to.contain('Fingerprint: 7A2E 4FFD 34BC 4AED 0F54 4199 D652 7AD6 65C3 B0DD'); // })); - test( - 'mail.google.com - verify secure reply buttons on expanded older message', - testWithBrowser(async (t, browser) => { - await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail'); - const gmailPage = await openGmailPage(t, browser); - // Use a known thread with multiple messages. - await gotoGmailPage(gmailPage, '/FMfcgzGqRGfPBbNLWvfPvDbxnHBwkdGf'); - - // 1. Verify buttons on the newest message (usually expanded by default) - await Util.sleep(3); - let messages = await gmailPage.target.$$('[role="listitem"] .adn.ads'); - const newestMessage = messages[messages.length - 1]; - const newestMenuBtn = await newestMessage.$('[aria-label="More message options"]'); - await newestMenuBtn?.click(); - await Util.sleep(1); - - await gmailPage.waitAll('.action_reply_message_button'); - const collapsedMessage = await gmailPage.target.$('[role="listitem"] .adf.ads'); - if (collapsedMessage) { - await collapsedMessage.click(); - await Util.sleep(2); - } - - // Now find the 3-dot menu on this expanded older message. - // After expansion, it should have .adn.ads class active/visible. - - messages = await gmailPage.target.$$('[role="listitem"] .adn.ads'); - const olderExpandedMessage = messages[0]; - const olderMenuBtn = await olderExpandedMessage.$('[aria-label="More message options"]'); - expect(olderMenuBtn).to.be.ok; - await olderMenuBtn?.click(); - await Util.sleep(1); - - // Verify secure buttons exist in the open menu for the older message - await gmailPage.waitAll('.action_reply_message_button'); - }) - ); - const testMinimumElementHeight = async (page: ControllablePage, selector: string, min: number) => { // testing https://github.com/FlowCrypt/flowcrypt-browser/issues/3519 const elStyle = await page.target.$eval(selector, el => el.getAttribute('style')); // 'height: 289.162px;' diff --git a/test/source/tests/page-recipe/gmail-page-recipe.ts b/test/source/tests/page-recipe/gmail-page-recipe.ts index 294b549c900..dabd525ad90 100644 --- a/test/source/tests/page-recipe/gmail-page-recipe.ts +++ b/test/source/tests/page-recipe/gmail-page-recipe.ts @@ -2,14 +2,32 @@ import { BrowserHandle } from '../../browser/browser-handle'; import { ControllablePage } from '../../browser/controllable'; -import { TIMEOUT_PAGE_LOAD } from '../../browser'; +import { TIMEOUT_ELEMENT_GONE } from '../../browser'; import { AvaContext } from '../tooling/'; import { PageRecipe } from './abstract-page-recipe'; import { expect } from 'chai'; -import { Util } from '../../util'; export class GmailPageRecipe extends PageRecipe { + public static dismissMobileNotificationsPrompt = async (gmailPage: ControllablePage) => { + const selector = + 'xpath/.//*[@role="dialog"][.//div[starts-with(normalize-space(text()), "Pause mobile notifications while")]]//button[@aria-label="Close"]'; + const closeButton = await gmailPage.page.$(selector); + if (!closeButton) { + return; + } + try { + if (await closeButton.isVisible()) { + await closeButton.press('Enter'); + const hiddenButton = await gmailPage.page.waitForSelector(selector, { hidden: true, timeout: TIMEOUT_ELEMENT_GONE * 1000 }); + await hiddenButton?.dispose(); + gmailPage.t.log('Dismissed Gmail’s pause mobile notifications prompt'); + } + } finally { + await closeButton.dispose(); + } + }; + public static openSecureComposeWithRichTextWorkaround = async ( t: AvaContext, gmailPage: ControllablePage, @@ -51,14 +69,17 @@ export class GmailPageRecipe extends PageRecipe { if (!lastMessageId || !lastMessageElement || lastMessageId === messageId) { break; } - await Util.sleep(3); - // deleting last reply - use waitAndClick for more reliable interaction with Gmail's dynamic UI - await gmailPage.waitAndClick(`[${messageIdAttrName}="${lastMessageId}"] [aria-label="More message options"]`, { delay: 2 }); - await Util.sleep(3); - await gmailPage.press('ArrowDown', 4); + const lastMessage = `[${messageIdAttrName}="${lastMessageId}"]`; + await this.dismissMobileNotificationsPrompt(gmailPage); + await gmailPage.waitAndFocus(`${lastMessage} [aria-label="More message options"]`); await gmailPage.press('Enter'); - await Util.sleep(3); - await gmailPage.page.reload({ timeout: TIMEOUT_PAGE_LOAD * 1000, waitUntil: 'networkidle2' }); + const deleteItem = await gmailPage.waitAny('li[data-action-type="11"]'); // Delete this message + try { + await deleteItem.press('Enter'); + } finally { + await deleteItem.dispose(); + } + await gmailPage.waitTillGone(lastMessage); } if (await gmailPage.isElementPresent('//*[text()="delete forever"]')) { diff --git a/test/source/tests/page-recipe/oauth-page-recipe.ts b/test/source/tests/page-recipe/oauth-page-recipe.ts index 7bf6d2f8d6b..f19c977b914 100644 --- a/test/source/tests/page-recipe/oauth-page-recipe.ts +++ b/test/source/tests/page-recipe/oauth-page-recipe.ts @@ -3,7 +3,6 @@ import { Config, Util } from '../../util'; import { AvaContext } from '../tooling/'; import { ControllablePage } from '../../browser/controllable'; -import { TIMEOUT_PAGE_LOAD } from '../../browser'; import { PageRecipe } from './abstract-page-recipe'; import { Url } from '../../core/common'; @@ -52,22 +51,12 @@ export class OauthPageRecipe extends PageRecipe { acctEmail: string, action: 'close' | 'deny' | 'approve' | 'login' | 'login_with_invalid_state' ): Promise => { - try { - const isMock = oauthPage.target.url().includes('localhost'); - if (isMock) { - await OauthPageRecipe.mock(t, oauthPage, acctEmail, action); - return; - } else { - await Promise.race([ - oauthPage.page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: TIMEOUT_PAGE_LOAD * 1000 }), - oauthPage.page.waitForNavigation({ waitUntil: 'load', timeout: TIMEOUT_PAGE_LOAD * 1000 }), - ]); - } - } catch (e) { - if (String(e).includes('page has been closed')) { - // the extension may close the auth page after success before we had a chance to evaluate it - return; // in this case the login was already successful - } + if (oauthPage.page.isClosed()) { + return; + } + if (oauthPage.target.url().includes('localhost')) { + await OauthPageRecipe.mock(t, oauthPage, acctEmail, action); + return; } const auth = Config.secrets().auth.google.find(a => a.email === acctEmail); const acctPassword = auth?.password; @@ -78,14 +67,21 @@ export class OauthPageRecipe extends PageRecipe { auth0password: '#password', auth0loginBtn: 'button[type=submit][name=action][value=default]', googleApproveBtn: '#submit_approve_access', + googleConfirmAccountBtn: 'button[formaction*="confirmaccount?"], form[action*="confirmaccount?"] button[type="submit"]', + googleSamlConfirmAccountBtn: '[data-view-id="AZBvBc"] [jsname="Njthtb"] button', googleContinueAuthBtn: '.VfPpkd-LgbsSe', googleSignInWithGoogleContinueBtn: '//button[.//span[normalize-space(.)="Continue"]]', }; + // The SAML confirmation view uses JS buttons without form actions, and its labels are localized. + const confirmationButtons = [selectors.googleConfirmAccountBtn, selectors.googleSamlConfirmAccountBtn, selectors.googleSignInWithGoogleContinueBtn]; try { const alreadyLoggedSelector = '.w6VTHd, .wLBAL, .yAlK0b'; const alreadyLoggedChooseOtherAccountSelector = '.bLzI3e, .BHzsHc'; await oauthPage.waitAny( - `#Email, ${selectors.googleApproveBtn}, ${selectors.googleEmailInput}, ${alreadyLoggedSelector}, #profileIdentifier, ${selectors.auth0username}, ${selectors.googleContinueAuthBtn}`, + [ + `#Email, ${selectors.googleApproveBtn}, ${selectors.googleEmailInput}, ${alreadyLoggedSelector}, #profileIdentifier, ${selectors.auth0username}, ${selectors.googleContinueAuthBtn}`, + ...confirmationButtons, + ], { timeout: 45 } ); @@ -125,18 +121,7 @@ export class OauthPageRecipe extends PageRecipe { const actionButtons = await oauthPage.target.$$(selectors.googleContinueAuthBtn); await oauthPage.waitForNavigationIfAny(() => actionButtons[actionButtons.length - 1].click()); } - if (await oauthPage.isElementPresent(selectors.googleSignInWithGoogleContinueBtn)) { - // "Sign in with Google" can show a re-auth confirmation before the OAuth approval screen. - await oauthPage.waitForNavigationIfAny( - () => oauthPage.waitAndClick(selectors.googleSignInWithGoogleContinueBtn, { delay: 1 }), - OauthPageRecipe.longTimeout - ); - await Util.sleep(2); - if (oauthPage.page.isClosed()) { - return; - } - } - await oauthPage.waitAny([selectors.googleApproveBtn, selectors.auth0username]); + await oauthPage.waitAny([selectors.googleApproveBtn, selectors.auth0username, ...confirmationButtons]); if (await oauthPage.isElementPresent(selectors.auth0username)) { await oauthPage.waitAndType(selectors.auth0username, acctEmail); if (acctPassword) { @@ -144,18 +129,17 @@ export class OauthPageRecipe extends PageRecipe { } const loginButtons = await oauthPage.target.$$(selectors.auth0loginBtn); await oauthPage.waitForNavigationIfAny(() => loginButtons[loginButtons.length - 1].click()); - await oauthPage.waitAndClick(alreadyLoggedSelector, { delay: 1 }); + const nextButton = await oauthPage.waitAny([selectors.googleApproveBtn, ...confirmationButtons, alreadyLoggedSelector]); + if (await nextButton.evaluate((button, selector) => button.matches(selector), alreadyLoggedSelector)) { + await nextButton.click(); + } } - await Util.sleep(1); - const button = await oauthPage.waitAny('button'); - const formAction = await button.evaluate(button => (button as HTMLButtonElement).formAction); - if (formAction?.includes('confirmaccount?')) { - // click on "Continue" on "Verify it's you" screen - await button.click(); - await Util.sleep(2); - return await OauthPageRecipe.google(t, oauthPage, acctEmail, action); // it should handle the list of accounts + const button = await oauthPage.waitAny([selectors.googleApproveBtn, ...confirmationButtons]); + if (!(await button.evaluate((button, selector) => button.matches(selector), selectors.googleApproveBtn))) { + // Account confirmation can appear before either account selection or OAuth consent. + await oauthPage.waitForNavigationIfAny(() => button.click()); + return await OauthPageRecipe.google(t, oauthPage, acctEmail, action); } - await oauthPage.waitAll(selectors.googleApproveBtn); // if succeeds, we are logged in and presented with approve/deny choice // since we are successfully logged in, we may save cookies to keep them fresh // no need to await the API call because it's not crucial to always save it, can mostly skip errors if (action === 'close') { @@ -166,15 +150,12 @@ export class OauthPageRecipe extends PageRecipe { await oauthPage.waitAndClick(selectors.googleApproveBtn, { delay: 1 }); } } catch (e) { - const eStr = String(e); - if ( - !eStr.includes('Execution context was destroyed') && - !eStr.includes('Cannot find context with specified id') && - !eStr.includes('Argument should belong to the same JavaScript world as target object') - ) { + if (oauthPage.page.isClosed()) { + return; + } + if (!Util.isTransientPageError(e)) { throw e; // not a known retriable error } - // t.log(`Attempting to retry google auth:${action} on the same window for ${email} because: ${eStr}`); return await OauthPageRecipe.google(t, oauthPage, acctEmail, action); // retry, it should pick up where it left off } }; diff --git a/test/source/tests/setup.ts b/test/source/tests/setup.ts index 69e033726a8..75a0524c5e8 100644 --- a/test/source/tests/setup.ts +++ b/test/source/tests/setup.ts @@ -87,6 +87,70 @@ const openMockGmailPage = async (t: AvaContext, browser: BrowserHandle, acctEmai export const defineSetupTests = (testVariant: TestVariant, testWithBrowser: TestWithBrowser) => { if (testVariant !== 'CONSUMER-LIVE-GMAIL') { + test( + 'setup - Google OAuth confirmation handles English and German buttons', + testWithBrowser(async (t, browser) => { + for (const label of ['Continue', 'Weiter']) { + const oauthPage = await browser.newPage(t); + await oauthPage.page.setContent(` +
+
+
+
+ `); + await oauthPage.page.evaluate(() => { + document.querySelector('[jsname="Njthtb"] button')?.addEventListener('click', () => { + const approve = document.createElement('button'); + approve.id = 'submit_approve_access'; + approve.textContent = 'Allow'; + document.body.replaceChildren(approve); + }); + }); + await OauthPageRecipe.google(t, oauthPage, 'oauth-fixture@example.com', 'close'); + t.true(oauthPage.page.isClosed(), label); + } + }) + ); + + test( + 'setup - element polling recovers from stale queries and visibility checks within its deadline', + testWithBrowser(async (t, browser) => { + const page = await browser.newPage(t); + await page.page.setContent(''); + const query = page.page.$$.bind(page.page); + const staleNode = new Error('Protocol error (DOM.resolveNode): Node with given id does not belong to the document'); + let queries = 0; + page.page.$$ = async selector => { + queries++; + if (queries === 1) { + throw staleNode; + } + const elements = await query(selector); + if (queries === 2) { + elements[0].boundingBox = async () => { + throw staleNode; + }; + } + return elements; + }; + try { + const element = await page.waitAny('#target', { timeout: 2 }); + t.is(await element.evaluate(element => element.textContent), 'Ready'); + t.is(queries, 3); + page.page.$$ = async () => { + throw staleNode; + }; + await t.throwsAsync(() => page.waitAny('#target', { timeout: 0.1 }), { message: 'waiting failed: Elements did not appear: #target' }); + page.page.$$ = async () => { + throw new Error('Unexpected protocol failure'); + }; + await t.throwsAsync(() => page.waitAny('#target'), { message: 'Unexpected protocol failure' }); + } finally { + page.page.$$ = query; + } + }) + ); + // note - `SetupPageRecipe.createKey` tests are in `defineFlakyTests` - running serially // because the keygen CPU spike can cause trouble to other concurrent tests @@ -1006,33 +1070,6 @@ AN8G3r5Htj8olot+jm9mIa5XLXWzMNUZgg== // await Util.sleep(200); // })); - test( - 'setup - recover with a passphrase - no remaining', - testWithBrowser(async (t, browser) => { - const acctEmail = 'flowcrypt.test.key.recovered@gmail.com'; - t.context.mockApi!.configProvider = new ConfigurationProvider({ - attester: singlePubKeyAttesterConfig(acctEmail, somePubkey), - }); - const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, acctEmail); - await SetupPageRecipe.recover(settingsPage, 'flowcrypt.test.key.recovered', { hasRecoverMore: false }); - }) - ); - - test( - 'setup - fail to recover with a wrong passphrase', - testWithBrowser(async (t, browser) => { - const acctEmail = 'flowcrypt.test.key.recovered@gmail.com'; - t.context.mockApi!.configProvider = new ConfigurationProvider({ - attester: singlePubKeyAttesterConfig(acctEmail, somePubkey), - }); - const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, acctEmail); - await SetupPageRecipe.recover(settingsPage, 'flowcrypt.wrong.passphrase', { - hasRecoverMore: false, - wrongPp: true, - }); - }) - ); - test( 'setup - fail to recover with a wrong passphrase at first, then recover with good passphrase', testWithBrowser(async (t, browser) => { diff --git a/test/source/tests/tooling/browser-recipe.ts b/test/source/tests/tooling/browser-recipe.ts index 7793d50831d..9526d01b99e 100644 --- a/test/source/tests/tooling/browser-recipe.ts +++ b/test/source/tests/tooling/browser-recipe.ts @@ -100,7 +100,7 @@ export class BrowserRecipe { return gmailPage; }; - public static setUpCommonAcct = async (t: AvaContext, browser: BrowserHandle, acct: TestAccount) => { + public static setUpCommonAcct = async (t: AvaContext, browser: BrowserHandle, acct: TestAccount, { cleanUpDrafts = true } = {}) => { let acctEmail: string | undefined; let settingsPage: ControllablePage | undefined; if (acct === 'compatibility') { @@ -129,7 +129,7 @@ export class BrowserRecipe { } const accessToken = await BrowserRecipe.getGoogleAccessToken(settingsPage, acctEmail); const cleanupTasks = [settingsPage.close()]; - if (testVariant === 'CONSUMER-LIVE-GMAIL') { + if (testVariant === 'CONSUMER-LIVE-GMAIL' && cleanUpDrafts) { // clean up drafts so that broken tests from the past don't affect this test run cleanupTasks.push(BrowserRecipe.deleteAllDraftsInGmailAccount(accessToken)); } diff --git a/test/source/tests/unit-browser.ts b/test/source/tests/unit-browser.ts index 73dfcfbd48f..ad06a767bec 100644 --- a/test/source/tests/unit-browser.ts +++ b/test/source/tests/unit-browser.ts @@ -10,7 +10,7 @@ import { testConstants } from './tooling/consts'; import { BrowserRecipe } from './tooling/browser-recipe'; import { ConfigurationProvider, HttpClientErr, Status } from '../mock/lib/api'; import { somePubkey } from '../mock/attester/attester-key-constants'; -import { aliceKey, jackAdvancedKey, johnDoeDirectKey, johnDoeAdvancedKey } from '../mock/wkd/wkd-constants'; +import { aliceKey, jackAdvancedKey, johnDoeAdvancedKey } from '../mock/wkd/wkd-constants'; import { johnDoeExampleComKey } from '../mock/sks/sks-constants'; type UnitTest = { title: string; code: string; acct?: CommonAcct; only: boolean }; @@ -42,7 +42,7 @@ export const defineUnitBrowserTests = (testVariant: TestVariant, testWithBrowser t.context.mockApi!.configProvider = new ConfigurationProvider({ wkd: { directLookup: { - 'john.doe': { pubkeys: [johnDoeDirectKey] }, + 'john.doe': { pubkeys: [johnDoeExampleComKey] }, 'jack.advanced': { pubkeys: [jackAdvancedKey] }, }, advancedLookup: { diff --git a/test/source/tests/unit-node.ts b/test/source/tests/unit-node.ts index 0fbebcdc663..6a3511374d8 100644 --- a/test/source/tests/unit-node.ts +++ b/test/source/tests/unit-node.ts @@ -57,34 +57,25 @@ export const defineUnitNodeTests = (testVariant: TestVariant) => { }); t.pass(); }); - test(`[unit][OpenPGPKey.parseMany] throws on invalid input`, async t => { - await t.throwsAsync( - () => - OpenPGPKey.parseMany(`-----BEGIN PGP PUBLIC KEY BLOCK----- + const malformedKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- Version: FlowCrypt Email Encryption Comment: Seamlessly send and receive encrypted email -Something wrong with this key`), - { +Something wrong with this key`; + const malformedKeyParsers = [ + { name: 'OpenPGPKey.parseMany', parse: (input: string) => OpenPGPKey.parseMany(input) }, + { name: 'KeyUtil.parseMany', parse: (input: string) => KeyUtil.parseMany(input) }, + { name: 'OpenPGPKey.parse', parse: (input: string) => OpenPGPKey.parse(input) }, + { name: 'KeyUtil.parse', parse: (input: string) => KeyUtil.parse(input) }, + ]; + for (const { name, parse } of malformedKeyParsers) { + test(`[unit][${name}] throws on invalid input`, async t => { + await t.throwsAsync(() => parse(malformedKey), { instanceOf: Error, message: 'Misformed armored text', - } - ); - }); - test(`[unit][KeyUtil.parseMany] throws on invalid input`, async t => { - await t.throwsAsync( - () => - KeyUtil.parseMany(`-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: FlowCrypt Email Encryption -Comment: Seamlessly send and receive encrypted email - -Something wrong with this key`), - { - instanceOf: Error, - message: 'Misformed armored text', - } - ); - }); + }); + }); + } test(`[unit][KeyUtil.isChecksumMismatch] detects only present checksum mismatches`, t => { const armoredWithValidChecksum = `-----BEGIN PGP MESSAGE----- @@ -102,34 +93,6 @@ bG8= expect(KeyUtil.isChecksumMismatch(armoredWithMalformedChecksum)).to.equal(false); t.pass(); }); - test(`[unit][OpenPGPKey.parse] throws on invalid input`, async t => { - await t.throwsAsync( - () => - OpenPGPKey.parse(`-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: FlowCrypt Email Encryption -Comment: Seamlessly send and receive encrypted email - -Something wrong with this key`), - { - instanceOf: Error, - message: 'Misformed armored text', - } - ); - }); - test(`[unit][KeyUtil.parse] throws on invalid input`, async t => { - await t.throwsAsync( - () => - KeyUtil.parse(`-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: FlowCrypt Email Encryption -Comment: Seamlessly send and receive encrypted email - -Something wrong with this key`), - { - instanceOf: Error, - message: 'Misformed armored text', - } - ); - }); test(`[unit][OpenPGPKey.getOrCreateRevocationCertificate] operations`, async t => { const stringData = 'hello'; const data = Buf.fromUtfStr(stringData); @@ -146,20 +109,20 @@ Something wrong with this key`), const expectNotRevoked = async (key: Key) => { expect(key.revoked).to.be.false; if (key.isPrivate) { - await MsgUtil.sign(originalPrv, stringData); + await MsgUtil.sign(key, stringData); } else { - await MsgUtil.encryptMessage({ pubkeys: [pubkey], data, armor: true }); + await MsgUtil.encryptMessage({ pubkeys: [key], data, armor: true }); } }; const expectRevoked = async (key: Key) => { expect(key.revoked).to.be.true; if (key.isPrivate) { - await t.throwsAsync(() => MsgUtil.sign(revokedPrv, stringData), { + await t.throwsAsync(() => MsgUtil.sign(key, stringData), { instanceOf: Error, message: 'Error signing message: Primary key is revoked', }); } else { - await t.throwsAsync(() => MsgUtil.encryptMessage({ pubkeys: [revokedPub], data, armor: true }), { + await t.throwsAsync(() => MsgUtil.encryptMessage({ pubkeys: [key], data, armor: true }), { instanceOf: Error, message: 'Error encrypting message: Primary key is revoked', }); @@ -2931,7 +2894,8 @@ AAAAAAAAAAAAAAAAzzzzzzzzzzzzzzzzzzzzzzzzzzzz.....`) expect(PgpArmor.clip(messageWithNoise)).to.equal(validMessage); // Test multiple messages (should return first) - const multipleMessages = validMessage + '\n\n' + validMessage; + const secondMessage = '-----BEGIN PGP MESSAGE-----\n\nsecond content\n-----END PGP MESSAGE-----'; + const multipleMessages = validMessage + '\n\n' + secondMessage; expect(PgpArmor.clip(multipleMessages)).to.equal(validMessage); // Test with different block types @@ -2946,9 +2910,11 @@ AAAAAAAAAAAAAAAAzzzzzzzzzzzzzzzzzzzzzzzzzzzz.....`) const mismatchedMessage = '-----BEGIN PGP MESSAGE-----\n\ntest\n-----END PGP SIGNATURE-----'; expect(PgpArmor.clip(mismatchedMessage)).to.be.an.undefined; - // Test with very large input (over 10MB limit) - const largeInput = 'a'.repeat(11 * 1024 * 1024); - expect(PgpArmor.clip(largeInput)).to.be.an.undefined; + // Test valid armor at the 10MB limit and one character over it + const maxLength = 10 * 1024 * 1024; + const inputAtLimit = 'a'.repeat(maxLength - validMessage.length - 1) + '\n' + validMessage; + expect(PgpArmor.clip(inputAtLimit)).to.equal(validMessage); + expect(PgpArmor.clip(inputAtLimit + 'a')).to.be.an.undefined; // Test with pathological input that would have caused stack overflow const pathologicalBase = '-----BEGIN PGP MESSAGE-----\n' + 'a'.repeat(1000); diff --git a/test/source/util/index.ts b/test/source/util/index.ts index d789b08eb60..22ca11d6dd1 100644 --- a/test/source/util/index.ts +++ b/test/source/util/index.ts @@ -149,6 +149,18 @@ export class Util { return (await element.boundingBox()) !== null; }; + public static isTransientPageError = (e: unknown): boolean => { + return ( + e instanceof Error && + [ + 'Execution context was destroyed', + 'Cannot find context with specified id', + 'Argument should belong to the same JavaScript world as target object', + 'Node with given id does not belong to the document', + ].some(message => e.message.includes(message)) + ); + }; + public static wipeGoogleTokensUsingExperimentalSettingsPage = async (t: AvaContext, browser: BrowserHandle, acct: string) => { for (const wipeTokenBtnSelector of ['@action-wipe-google-refresh-token', '@action-wipe-google-access-token']) { const settingsPage = await browser.newExtensionSettingsPage(t, acct);