Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/run-all-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,29 @@ jobs:
run: npm run build --workspace=@jazzer.js/fuzzer
- name: run all fuzz tests
run: node fuzztests/runFuzzTests.js
end-to-end:
name: end-to-end
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: node
uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- name: pack jazzer.js
run: cd end-to-end && ./package-jazzer-js.sh
- name: build example
run: cd end-to-end && npm install --save-dev *.tgz && npm run build
- name: run tests
run: cd end-to-end && npx jest
auto-merge:
needs:
- linting
- unit_tests
- fuzz_tests
- end-to-end
permissions:
pull-requests: write
contents: write
Expand Down
2 changes: 2 additions & 0 deletions end-to-end/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/package-lock.json
**/.cifuzz-corpus
22 changes: 22 additions & 0 deletions end-to-end/README.md
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.
35 changes: 35 additions & 0 deletions end-to-end/integration.fuzz.ts
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);
},
);
});
37 changes: 37 additions & 0 deletions end-to-end/integration.test.ts
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);
});
});
40 changes: 40 additions & 0 deletions end-to-end/jest.config.ts
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;
16 changes: 16 additions & 0 deletions end-to-end/package-jazzer-js.sh
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
24 changes: 24 additions & 0 deletions end-to-end/package.json
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"
}
}
1 change: 1 addition & 0 deletions end-to-end/remove-version.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s/-[0-9]+\.[0-9]+\.[0-9]+\.tgz/\.tgz/g
58 changes: 58 additions & 0 deletions end-to-end/target.ts
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);
}
});
});
}
17 changes: 17 additions & 0 deletions end-to-end/tsconfig.json
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
}
}