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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,51 @@ 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:
secrets:
- &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
Expand Down Expand Up @@ -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:
Expand All @@ -84,7 +110,7 @@ blocks:
on_fail: *flowcrypt_ci_epilogue_on_fail

- name: Other tests
dependencies: []
dependencies: [Build]
execution_time_limit:
minutes: 20
task:
Expand Down Expand Up @@ -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
10 changes: 8 additions & 2 deletions extension/js/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,13 @@ export class Settings {

private static async fetchAcctAliasesFromGmail(acctEmail: string): Promise<Dict<SendAsAlias>> {
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<SendAsAlias> = {};
for (const a of validAliases) {
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion test/source/browser/browser-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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];
Expand All @@ -127,6 +129,7 @@ export class BrowserHandle {
.join('\n');
html += '<div class="page">';
html += `<pre title="url">Page ${i} (${cPage.page.isClosed() ? 'closed' : 'active'}) ${Util.htmlEscape(url)}</pre>`;
html += composeFramesHtmls[i] ?? '';
html += `<pre title="console">${consoleMsgs || '(no console messages)'}</pre>`;
html += `<pre title="alerts">${alerts || '(no alerts)'}</pre>`;
if (url !== 'about:blank' && !cPage.page.isClosed()) {
Expand All @@ -148,6 +151,25 @@ export class BrowserHandle {
return html;
};

private debugComposeFramesHtml = async (page: Page): Promise<string> => {
const framesHtml = await Promise.all(
page
.frames()
.filter(frame => frame.url().includes('/chrome/elements/compose.htm'))
.map(async frame => {
let html = `<pre title="compose-frame-url">${Util.htmlEscape(frame.url())} (detached: ${frame.detached})</pre>`;
try {
const frameHtml = await Promise.race([frame.content(), newTimeoutPromise('compose frame diagnostics', 5)]);
html += `<pre title="compose-frame-html" style="height:300px;overflow:auto;">${Util.htmlEscape(frameHtml)}</pre>`;
} catch (e) {
html += `<pre title="compose-frame-error">${Util.htmlEscape(String(e))}</pre>`;
}
return html;
})
);
return framesHtml.join('');
};

private doAwaitTriggeredPage = (triggeringAction: () => Promise<void>): Promise<Page | null> => {
return new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('Action did not trigger a new page within timeout period')), TIMEOUT_ELEMENT_APPEAR * 1000);
Expand Down
3 changes: 3 additions & 0 deletions test/source/browser/browser-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion test/source/browser/controllable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
70 changes: 34 additions & 36 deletions test/source/buf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
10 changes: 6 additions & 4 deletions test/source/mock/google/strategies/send-message-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -318,7 +320,6 @@ class PlainTextMessageTestStrategy implements ITestMsgStrategy {
};
}


class NoopTestStrategy implements ITestMsgStrategy {
// eslint-disable-next-line @typescript-eslint/no-empty-function
public test = async () => {};
Expand Down Expand Up @@ -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')) {
Expand Down
28 changes: 0 additions & 28 deletions test/source/mock/wkd/wkd-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
CQoLAgUWAgMBAAAK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TdfXX7lVeZtbpSVhSl9Z1YMhth+oWVJ79iQQ8OPKEvt471Qwk1LH7k4a9O
nT5+WNnpAkcxrjMd
=fISM
-----END PGP PUBLIC KEY BLOCK-----
`;

export const jackAdvancedKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----

xsBNBF+J56IBCADSvEei1mAEQCEXHxaOKzsxvM8Qvgjj0vr+zHE+hUFg1znRAyjQ9XSDGwJ4+dut
Expand Down
3 changes: 3 additions & 0 deletions test/source/mock/wkd/wkd-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Loading
Loading