Skip to content

Commit eb62524

Browse files
test(desktop): isolate expected TLS error navigation (#112)
* test(desktop): isolate expected certificate error navigations * test(desktop): retain certificate rejection diagnostics
1 parent 86e0a0b commit eb62524

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

‎apps/desktop/test/windows-pit-browser.mjs‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ try {
2121
await controls.goto(`chrome-extension://${id}/options.html`);
2222
const message = (type, on) => controls.evaluate(
2323
({ type, on }) => chrome.runtime.sendMessage({ type, on }), { type, on });
24+
// Certificate rejection can commit chrome-error:// after goto rejects. Keep
25+
// that late navigation out of the tab used for subsequent routing checks.
26+
const rejectUntrusted = async (url, { screenshotPath, timeout = 45000 } = {}) => {
27+
const invalid = await context.newPage();
28+
try {
29+
await assert.rejects(invalid.goto(url, {
30+
waitUntil: 'domcontentloaded', timeout,
31+
}), /ERR_CERT_AUTHORITY_INVALID/);
32+
if (screenshotPath) {
33+
await invalid.waitForFunction(() => Boolean(document.body?.innerText.trim()), null, { timeout: 5000 });
34+
await invalid.screenshot({ path: screenshotPath });
35+
}
36+
} catch (error) {
37+
await invalid.screenshot({ path: path.join(evidence, `${phase}-invalid-tls-failure.png`) }).catch(() => {});
38+
throw error;
39+
} finally {
40+
await invalid.close().catch(() => {});
41+
}
42+
};
2443

2544
const deadline = Date.now() + 5000;
2645
let initial, initialProxy;
@@ -51,10 +70,7 @@ try {
5170
check('HTTP Moshpit name resolves through the browser');
5271

5372
if (phase === 'before-trust' || phase === 'after-removal') {
54-
await assert.rejects(page.goto('https://profullstack.agent/', {
55-
waitUntil: 'domcontentloaded', timeout: 45000,
56-
}), /ERR_CERT_AUTHORITY_INVALID/);
57-
await page.screenshot({ path: path.join(evidence, `${phase}.png`) });
73+
await rejectUntrusted('https://profullstack.agent/', { screenshotPath: path.join(evidence, `${phase}.png`) });
5874
check('registry HTTPS is rejected without root trust');
5975
} else {
6076
const response = await page.goto('https://profullstack.agent/', {
@@ -70,9 +86,7 @@ try {
7086
check('registry HTTPS succeeds with normal browser certificate verification');
7187
}
7288

73-
await assert.rejects(page.goto(invalidTlsUrl, {
74-
waitUntil: 'domcontentloaded', timeout: 15000,
75-
}), /ERR_CERT_AUTHORITY_INVALID/);
89+
await rejectUntrusted(invalidTlsUrl, { timeout: 15000 });
7690
check('unrelated self-signed HTTPS remains rejected');
7791

7892
assert.equal((await message('pit-set', false)).enabled, false);

0 commit comments

Comments
 (0)