-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from AikidoSec/e2e-n8n
Add end2end test for n8n
- Loading branch information
Showing
3 changed files
with
21,460 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.