Skip to content

Commit 709c702

Browse files
committed
test(bug-detectors): cover code injection across Jest files
Run two fuzz files in one in-band Jest invocation and assert that both report the same base canary name. This proves the lazy vmContext install works across sequential files without drifting to suffixed canaries.
1 parent 474b168 commit 709c702

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

tests/bug-detectors/code-injection.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
const path = require("path");
18+
const { spawnSync } = require("child_process");
1819

1920
const {
2021
FuzzTestBuilder,
@@ -151,6 +152,36 @@ describe("CLI", () => {
151152
});
152153

153154
describe("Jest", () => {
155+
it("keeps the canary stable across sequential Jest files", () => {
156+
const proc = spawnSync(
157+
"npx",
158+
[
159+
"jest",
160+
"--runInBand",
161+
"--no-colors",
162+
"--runTestsByPath",
163+
"context-a.fuzz.js",
164+
"context-b.fuzz.js",
165+
],
166+
{
167+
cwd: bugDetectorDirectory,
168+
env: { ...process.env },
169+
shell: true,
170+
stdio: "pipe",
171+
windowsHide: true,
172+
},
173+
);
174+
175+
const output = proc.stdout.toString() + proc.stderr.toString();
176+
expect(proc.status?.toString()).toBe(JestRegressionExitCode);
177+
expect(output).toContain("context-a.fuzz.js");
178+
expect(output).toContain("context-b.fuzz.js");
179+
expect(output).not.toContain("accessed canary: jaz_zer_1");
180+
expect(
181+
(output.match(/accessed canary: jaz_zer/g) ?? []).length,
182+
).toBeGreaterThanOrEqual(2);
183+
});
184+
154185
it("reports potential access", () => {
155186
const fuzzTest = fuzzTestBuilder
156187
.dryRun(false)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2026 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const tests = require("./fuzz");
18+
19+
describe("context a", () => {
20+
it.fuzz("Accesses canary", (data) => {
21+
tests.evalAccessesCanary(data);
22+
});
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2026 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const tests = require("./fuzz");
18+
19+
describe("context b", () => {
20+
it.fuzz("Accesses canary", (data) => {
21+
tests.evalAccessesCanary(data);
22+
});
23+
});

0 commit comments

Comments
 (0)