Skip to content

Commit

Permalink
Block Google telemetry in browser tests
Browse files Browse the repository at this point in the history
Earlier Puppeteer/Chromium versions weren't phoning home to Google, but this
appears to have changed after #145. This updates are proxy configuration to
return 403s for any Google URLs which keeps them out of the test fixtures and
makes things more predictable. A browser test has been added which verifies
this behavior.

Connects #145

Merges #150

LGTM given by: @KPreisner
  • Loading branch information
sangaline authored Sep 5, 2024
1 parent 49061cb commit 97fdefb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ test("library is injected and authorized", async (t) => {
t.truthy(baseUrl);
});

test("access to google.com is blocked", async (t) => {
// Squash Chrome's error logging for this page, we expect a 403 error.
t.context.page.removeAllListeners("console");
const status: number | null = await t.context.page.evaluate(async () => {
// Hackily use the sindri's internal client to make a request to Google.
sindri._clientConfig.BASE = "https://accounts.google.com";
try {
const response: { status: number } = await sindri._client.request.request(
{
method: "GET",
url: "/ListAccounts",
},
);
return response?.status ?? null;
} catch (error) {
return (error as { status: number })?.status ?? null;
}
});
t.deepEqual(
status,
403,
"Requests to google.com delays should be blocked with a 403 status code.",
);
});

test("create circuit from file array", async (t) => {
const circuitDirectory = path.join(dataDirectory, "circom-multiplier2");
const fileNames = await fs.readdir(circuitDirectory);
Expand Down
15 changes: 15 additions & 0 deletions test/utils/usePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ function createProxy(): Proxy {
const proxy = new Proxy();
proxy.use(Proxy.wildcard);

// Block Google phoning home.
proxy.onRequest((ctx, callback) => {
const host = ctx.clientToProxyRequest.headers.host ?? "";
if (/(^|.).google.com/i.test(host)) {
// Return 403 errors for any Google requests.
ctx.proxyToClientResponse.writeHead(403, {
"Content-Type": "text/plain",
});
ctx.proxyToClientResponse.end("Bad Request: Google Services Blocked");
} else {
// Continue processing the request normally if it's not Google.
return callback();
}
});

// The library uses `console.debug()` a lot and it's noisy.
console.debug = () => {};

Expand Down

0 comments on commit 97fdefb

Please sign in to comment.