122 lines
3.8 KiB
JavaScript
122 lines
3.8 KiB
JavaScript
const fs = require("node:fs"),
|
|
path = require("node:path"),
|
|
assert = require("node:assert/strict"),
|
|
{ spawn } = require("node:child_process");
|
|
const { chromium } = require(process.env.PLAYWRIGHT_MODULE);
|
|
(async () => {
|
|
const root = fs.mkdtempSync(
|
|
path.join(process.env.FILEBROWSER_QA_OUTPUT, "no-sso-")
|
|
);
|
|
const files = path.join(root, "files");
|
|
fs.mkdirSync(files);
|
|
fs.writeFileSync(path.join(files, "anonymous.txt"), "NO PASSWORD");
|
|
const config = path.join(root, "config.json"),
|
|
db = path.join(root, "test.db");
|
|
fs.writeFileSync(
|
|
config,
|
|
JSON.stringify({
|
|
root: files,
|
|
database: db,
|
|
sso: { issuer: "invalid-provider-configuration" },
|
|
})
|
|
);
|
|
const args = [
|
|
"--config",
|
|
config,
|
|
"--root",
|
|
files,
|
|
"--database",
|
|
db,
|
|
"--port",
|
|
"0",
|
|
];
|
|
const processOne = spawn(process.env.FILEBROWSER_EXE, [...args, "--no-sso"], {
|
|
cwd: root,
|
|
windowsHide: true,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let logs = "",
|
|
browser;
|
|
const started = new Promise((resolve, reject) => {
|
|
const timeout = setTimeout(
|
|
() => reject(Error("startup timeout " + logs)),
|
|
12000
|
|
);
|
|
const read = (chunk) => {
|
|
logs += chunk.toString();
|
|
const found = logs.match(/Listening on (127\.0\.0\.1:\d+)/);
|
|
if (found) {
|
|
clearTimeout(timeout);
|
|
resolve("http://" + found[1]);
|
|
}
|
|
};
|
|
processOne.stdout.on("data", read);
|
|
processOne.stderr.on("data", read);
|
|
processOne.once("exit", (code) => {
|
|
clearTimeout(timeout);
|
|
reject(Error("exited " + code + " " + logs));
|
|
});
|
|
});
|
|
try {
|
|
const url = await started;
|
|
browser = await chromium.launch({
|
|
executablePath: process.env.BROWSER_EXECUTABLE,
|
|
headless: true,
|
|
});
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
const response = await context.request.get(url + "/api/session");
|
|
assert.equal(response.status(), 200);
|
|
const user = await response.json();
|
|
assert.equal(user.authMode, "no-sso");
|
|
assert.equal(user.perm.admin, true);
|
|
await page.goto(url + "/files/");
|
|
await page.getByText("anonymous.txt", { exact: true }).waitFor();
|
|
assert.equal(await page.locator("iframe").count(), 0);
|
|
assert.equal(await page.locator('a[href$="/auth/account"]').count(), 0);
|
|
const write = await context.request.post(
|
|
url + "/api/resources/created.txt",
|
|
{ headers: { "X-FB-Request": "1" }, data: "CREATED WITHOUT PASSWORD" }
|
|
);
|
|
assert.equal(write.status(), 200);
|
|
assert.equal(
|
|
fs.readFileSync(path.join(files, "created.txt"), "utf8"),
|
|
"CREATED WITHOUT PASSWORD"
|
|
);
|
|
await page.screenshot({ path: path.join(root, "anonymous-workspace.png") });
|
|
} finally {
|
|
if (browser) await browser.close();
|
|
if (processOne.exitCode === null) {
|
|
processOne.kill();
|
|
await new Promise((r) => processOne.once("exit", r));
|
|
}
|
|
fs.writeFileSync(path.join(root, "server.log"), logs);
|
|
}
|
|
const normal = spawn(process.env.FILEBROWSER_EXE, args, {
|
|
cwd: root,
|
|
windowsHide: true,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let normalLogs = "";
|
|
normal.stdout.on("data", (d) => (normalLogs += d));
|
|
normal.stderr.on("data", (d) => (normalLogs += d));
|
|
const code = await new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
normal.kill();
|
|
reject(Error("SSO mode unexpectedly started"));
|
|
}, 12000);
|
|
normal.once("exit", (code) => {
|
|
clearTimeout(timer);
|
|
resolve(code);
|
|
});
|
|
});
|
|
assert.notEqual(code, 0);
|
|
assert(!normalLogs.includes("Listening on"));
|
|
console.log(
|
|
"CLI --no-sso: no provider, cookie or password; reads/writes and administrator UI passed. Without flag, invalid SSO cannot start."
|
|
);
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exitCode = 1;
|
|
});
|