-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a test to the PR CI workflow to package up jazzer.js and run it against a project that imports in similar form to what it would get if it were importing the released version rather than using local file references. This will catch the issue we had previously where an import worked locally but not in the released version.
- Loading branch information
Showing
11 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/package-lock.json | ||
**/.cifuzz-corpus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Jazzer End to End Canary Test | ||
|
||
This is the code from `examples/jest_typescript_integration` with a single | ||
change to `package.json`: the Jazzer.js dependencies now come from | ||
`jazzer-js-<package name>.tgz` files in this directory. These can be created by | ||
running `./package-jazzer-js.sh` which will call `npm pack` on the Jazzer | ||
packages so that we can test for any packaging errors. | ||
|
||
The Typescript integration example was chosen as that should exercise more of | ||
jazzer.js than the other examples. | ||
|
||
## Running Locally | ||
|
||
```bash | ||
./package-jazzer-js.sh | ||
npm install --save-dev *.tgz | ||
npx jest | ||
``` | ||
|
||
_Note_: running just `npm install` may result in caching issues where the | ||
contents of the tarballs in this directory are ignored and older versions from | ||
somewhere are used instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import "@jazzer.js/jest-runner"; | ||
import * as target from "./target"; | ||
|
||
describe("Target", () => { | ||
it.fuzz("executes sync methods", (data: Buffer) => { | ||
target.fuzzMe(data); | ||
}); | ||
|
||
it.fuzz("executes async methods", async (data: Buffer) => { | ||
await target.asyncFuzzMe(data); | ||
}); | ||
|
||
it.fuzz( | ||
"executes methods with a done callback", | ||
(data: Buffer, done: (e?: Error) => void) => { | ||
target.callbackFuzzMe(data, done); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as target from "./target"; | ||
|
||
describe("My describe", () => { | ||
it("My normal Jest test", () => { | ||
expect(1).toEqual(1); | ||
}); | ||
|
||
it("My done callback Jest test", (done) => { | ||
expect(1).toEqual(1); | ||
done(); | ||
}); | ||
|
||
it("My async Jest test", async () => { | ||
expect(1).toEqual(1); | ||
}); | ||
|
||
it("Test target function", () => { | ||
const data = Buffer.from("a"); | ||
target.fuzzMe(data); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import type { Config } from "jest"; | ||
|
||
const config: Config = { | ||
verbose: true, | ||
projects: [ | ||
{ | ||
displayName: "Jest", | ||
preset: "ts-jest", | ||
}, | ||
{ | ||
displayName: { | ||
name: "Jazzer.js", | ||
color: "cyan", | ||
}, | ||
preset: "ts-jest", | ||
runner: "@jazzer.js/jest-runner", | ||
testEnvironment: "node", | ||
testMatch: ["<rootDir>/*.fuzz.[jt]s"], | ||
}, | ||
], | ||
coveragePathIgnorePatterns: ["/node_modules/", "/dist/"], | ||
modulePathIgnorePatterns: ["/node_modules", "/dist/"], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
cd .. | ||
npm install | ||
npm run build | ||
npm run build --workspace='@jazzer.js/fuzzer' | ||
|
||
sed_version_and_mv() { | ||
while read data; do | ||
local no_version=$(echo $data | sed -r -f end-to-end/remove-version.sed) | ||
echo "mv $data end-to-end/$no_version" | ||
mv $data end-to-end/$no_version | ||
done | ||
} | ||
|
||
npm pack --workspaces | sed_version_and_mv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "jest_typescript_integration", | ||
"version": "1.0.0", | ||
"description": "An example showing how Jazzer.js integrates with Jest and TypeScript", | ||
"scripts": { | ||
"build": "tsc", | ||
"dryRun": "jest", | ||
"fuzz": "JAZZER_FUZZ=1 jest --coverage", | ||
"coverage": "jest --coverage" | ||
}, | ||
"devDependencies": { | ||
"@jazzer.js/bug-detectors": "file:jazzer.js-bug-detectors.tgz", | ||
"@jazzer.js/core": "file:jazzer.js-core.tgz", | ||
"@jazzer.js/fuzzer": "file:jazzer.js-fuzzer.tgz", | ||
"@jazzer.js/hooking": "file:jazzer.js-hooking.tgz", | ||
"@jazzer.js/instrumentor": "file:jazzer.js-instrumentor.tgz", | ||
"@jazzer.js/jest-runner": "file:jazzer.js-jest-runner.tgz", | ||
"@types/jest": "^29.4.0", | ||
"jest": "^29.4.1", | ||
"ts-jest": "^29.0.5", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
s/-[0-9]+\.[0-9]+\.[0-9]+\.tgz/\.tgz/g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export function fuzzMe(data: Buffer) { | ||
const s = data.toString(); | ||
if (s.length !== 16) { | ||
return; | ||
} | ||
if ( | ||
s.slice(0, 8) === "Awesome " && | ||
s.slice(8, 15) === "Fuzzing" && | ||
s[15] === "!" | ||
) { | ||
throw Error("Welcome to Awesome Fuzzing!"); | ||
} | ||
} | ||
|
||
export function callbackFuzzMe(data: Buffer, done: (e?: Error) => void) { | ||
// Use setImmediate here to unblock the event loop but still have better | ||
// performance compared to setTimeout. | ||
setImmediate(() => { | ||
try { | ||
fuzzMe(data); | ||
done(); | ||
} catch (e: unknown) { | ||
if (e instanceof Error) { | ||
done(e); | ||
} else { | ||
done(new Error(`Error: ${e}`)); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export async function asyncFuzzMe(data: Buffer) { | ||
return new Promise((resolve, reject) => { | ||
callbackFuzzMe(data, (e?: Error) => { | ||
if (e) { | ||
reject(e); | ||
} else { | ||
resolve(null); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "node", | ||
"allowJs": true, | ||
"rootDir": ".", | ||
"outDir": "./dist", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"declaration": true, | ||
"composite": true, | ||
"sourceMap": true | ||
} | ||
} |