Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Feb 16, 2024
1 parent 3974f72 commit 8035480
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions end2end/tests/express-mongodb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ t.test("it blocks in blocking mode", (t) => {
const server = spawn(`node`, [pathToApp, "4000"], { shell: true });

server.on("close", () => {
console.log("received close");
t.end();
});

server.on("error", (err) => {
console.log("received error");
t.fail(err.message);
});

let stdout = "";
server.stdout.on("data", (data) => {
stdout += data.toString();
Expand All @@ -33,31 +39,36 @@ t.test("it blocks in blocking mode", (t) => {

// Wait for the server to start
timeout(2000)
.then(() =>
Promise.all([
.then(() => {
console.log("sending requests");
return Promise.all([
fetch("http://localhost:4000/?search[$ne]=null", {
signal: AbortSignal.timeout(5000),
}),
fetch("http://localhost:4000/?search=title", {
signal: AbortSignal.timeout(5000),
}),
])
)
]);
})
.then(([noSQLInjection, normalSearch]) => {
console.log("noSQLInjection", noSQLInjection.status);
console.log("normalSearch", normalSearch.status);
t.equal(noSQLInjection.status, 500);
t.equal(normalSearch.status, 200);
t.match(stdout, /Starting agent/);
t.match(stderr, /Aikido guard has blocked a NoSQL injection/);
})
.catch((error) => {
console.log("error", error.message);
t.fail(error.message);
})
.finally(() => {
console.log("killing server");
server.kill();
});
});

t.test("it does not block in dry mode", (t) => {
/*t.test("it does not block in dry mode", (t) => {
const server = spawn(`node`, [pathToApp, "4001"], {
env: { ...process.env, AIKIDO_NO_BLOCKING: "true" },
shell: true,
Expand Down Expand Up @@ -103,4 +114,4 @@ t.test("it does not block in dry mode", (t) => {
.finally(() => {
server.kill();
});
});
});*/

0 comments on commit 8035480

Please sign in to comment.