Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end2end test for n8n #457

Merged
merged 3 commits into from
Nov 20, 2024
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
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
Loading