Skip to content

Commit

Permalink
Run unit tests on Windows in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Sep 25, 2024
1 parent 13af45e commit b590a84
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push: {}
workflow_call: {}
jobs:
build:
test:
runs-on: ubuntu-latest
services:
s3:
Expand Down Expand Up @@ -57,3 +57,23 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
slug: AikidoSec/firewall-node
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v2
with:
node-version: 20.x
- name: Add local.aikido.io to hosts file
run: |
Add-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value "127.0.0.1 local.aikido.io"
- run: npm install
- run: npm run test:ci
- name: "Upload coverage"
uses: codecov/codecov-action@v4.0.1
with:
file: ./library/.tap/report/lcov.info
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
slug: AikidoSec/firewall-node
37 changes: 20 additions & 17 deletions library/sinks/BetterSQLite3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReportingAPIForTesting } from "../agent/api/ReportingAPIForTesting";
import { runWithContext, type Context } from "../agent/Context";
import { LoggerNoop } from "../agent/logger/LoggerNoop";
import { BetterSQLite3 } from "./BetterSQLite3";
import { isWindows } from "../helpers/isWindows";

const dangerousContext: Context = {
remoteAddress: "::1",
Expand Down Expand Up @@ -117,25 +118,27 @@ t.test("it detects SQL injections", async (t) => {
}
});

await runWithContext(dangerousPathContext, async () => {
const error = t.throws(() => db.backup("/tmp/insecure"));
t.ok(error instanceof Error);
if (error instanceof Error) {
t.same(
error.message,
"Zen has blocked a path traversal attack: better-sqlite3.backup(...) originating from body.myTitle"
);
}
await db.backup("/tmp/sqlite-test-secure");
});
if (!isWindows) {
await runWithContext(dangerousPathContext, async () => {
const error = t.throws(() => db.backup("/tmp/insecure"));
t.ok(error instanceof Error);
if (error instanceof Error) {
t.same(
error.message,
"Zen has blocked a path traversal attack: better-sqlite3.backup(...) originating from body.myTitle"
);
}
await db.backup("/tmp/sqlite-test-secure");
});

await db.backup("/tmp/sqlite-test-secure-2");
await db.backup("/tmp/sqlite-test-secure-2");

try {
await db.backup();
t.fail("Expected an error");
} catch (error: any) {
t.same(error.message, "Expected first argument to be a string");
try {
await db.backup();
t.fail("Expected an error");
} catch (error: any) {
t.same(error.message, "Expected first argument to be a string");
}
}
} catch (error: any) {
t.fail(error);
Expand Down

0 comments on commit b590a84

Please sign in to comment.