Skip to content

Commit

Permalink
Merge pull request #457 from AikidoSec/e2e-n8n
Browse files Browse the repository at this point in the history
Add end2end test for n8n
  • Loading branch information
hansott authored Nov 20, 2024
2 parents 323f74d + 10e609e commit e5c5a08
Show file tree
Hide file tree
Showing 3 changed files with 21,460 additions and 0 deletions.
90 changes: 90 additions & 0 deletions end2end/tests/n8n.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const t = require("tap");
const { spawnSync, spawn, execSync } = require("child_process");
const { resolve, join } = require("path");
const timeout = require("../timeout");

const pathToApp = resolve(__dirname, "../../sample-apps/n8n");

t.test("it logs in", (t) => {
const port = 5678;
const server = spawn(`node_modules/.bin/n8n`, {
env: {
...process.env,
AIKIDO_DEBUG: "true",
AIKIDO_BLOCK: "true",
NODE_OPTIONS: "-r @aikidosec/firewall",
N8N_PORT: port.toString(),
},
cwd: pathToApp,
});

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

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

let stdout = "";
server.stdout.on("data", (data) => {
stdout += data.toString();
});

let stderr = "";
server.stderr.on("data", (data) => {
stderr += data.toString();
});

// Wait for the server to start
timeout(5000)
.then(() => {
return fetch(`http://127.0.0.1:${port}/rest/owner/setup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
agree: true,
email: "[email protected]",
firstName: "John",
lastName: "Doe",
password: "Password1234!",
}),
signal: AbortSignal.timeout(5000),
});
})
.then((registerAdmin) => {
t.equal(registerAdmin.status, 200);
const setCookie = registerAdmin.headers.get("Set-Cookie").split(";")[0];
t.ok(setCookie.includes("n8n-auth"));

return setCookie;
})
.then((cookie) => {
return Promise.all([
fetch(`http://127.0.0.1:${port}/home/workflows`, {
headers: {
Cookie: cookie,
},
signal: AbortSignal.timeout(5000),
}),
fetch(`http://127.0.0.1:${port}/rest/workflows`, {
headers: {
Cookie: cookie,
},
signal: AbortSignal.timeout(5000),
}),
]);
})
.then(([workflows, restWorkflows]) => {
t.equal(workflows.status, 200);
t.equal(restWorkflows.status, 200);
})
.catch((error) => {
t.fail(error.message);
})
.finally(() => {
server.kill();
});
});
Loading

0 comments on commit e5c5a08

Please sign in to comment.