Skip to content

Commit bb4e46f

Browse files
committed
Identify WebBrain E2E control requests
1 parent b1230c9 commit bb4e46f

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

ci/lib/webbrain-client.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export class GnippetsE2EClient {
146146
method,
147147
headers: {
148148
authorization: `Bearer ${this.controlToken}`,
149+
accept: 'application/json',
150+
'user-agent': 'Mozilla/5.0 (compatible; WebBrainCloudE2E/1.0; +https://webbrain.cloud)',
149151
...(body === undefined ? {} : { 'content-type': 'application/json' }),
150152
},
151153
body: body === undefined ? undefined : JSON.stringify(body),

ci/test.mjs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,30 @@ assert.deepEqual(
3131
);
3232

3333
const diagnosticSecret = 'diagnostic-secret-that-must-not-leak';
34+
let diagnosticRequest;
3435
const diagnosticClient = new GnippetsE2EClient({
3536
baseUrl: 'https://gnippets.example',
3637
controlToken: diagnosticSecret,
37-
fetchImpl: async () => ({
38-
ok: false,
39-
status: 403,
40-
headers: {
41-
get(name) {
42-
return {
43-
server: 'cloudflare',
44-
'cf-ray': 'fixture-ray-IST',
45-
'cf-mitigated': 'challenge',
46-
'content-type': 'text/html',
47-
}[name.toLowerCase()] || null;
38+
fetchImpl: async (url, options) => {
39+
diagnosticRequest = { url, options };
40+
return {
41+
ok: false,
42+
status: 403,
43+
headers: {
44+
get(name) {
45+
return {
46+
server: 'cloudflare',
47+
'cf-ray': 'fixture-ray-IST',
48+
'cf-mitigated': 'challenge',
49+
'content-type': 'text/html',
50+
}[name.toLowerCase()] || null;
51+
},
4852
},
49-
},
50-
async text() {
51-
return `<html><title>Attention Required</title><body>Bearer ${diagnosticSecret}</body></html>`;
52-
},
53-
}),
53+
async text() {
54+
return `<html><title>Attention Required</title><body>Bearer ${diagnosticSecret}</body></html>`;
55+
},
56+
};
57+
},
5458
});
5559
await assert.rejects(
5660
diagnosticClient.createRun('fixture'),
@@ -64,6 +68,8 @@ await assert.rejects(
6468
return true;
6569
},
6670
);
71+
assert.equal(diagnosticRequest.options.headers.accept, 'application/json');
72+
assert.match(diagnosticRequest.options.headers['user-agent'], /WebBrainCloudE2E/);
6773

6874
const mountainScenario = scenarios.find((scenario) => scenario.id === 'wikipedia-table-extraction');
6975
const invalidMountainHeights = gradeScenario({

0 commit comments

Comments
 (0)