feat: adopt shared internal SSO sessions and add no-sso launch mode
This commit is contained in:
1 parent
c209f1effc
commit
c02bf755f2
51 files changed
+2131
-362
No files matched your search
@@ -0,0 +1,221 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE);
|
||||
(async () => {
|
||||
const browser = await chromium.launch({
|
||||
executablePath: process.env.BROWSER_EXECUTABLE,
|
||||
headless: true,
|
||||
args: ["--host-resolver-rules=MAP *.localhost 127.0.0.1"],
|
||||
});
|
||||
const output = process.env.FILEBROWSER_QA_OUTPUT;
|
||||
fs.mkdirSync(output, { recursive: true });
|
||||
const errors = [];
|
||||
const contexts = [];
|
||||
const change = async (values) => {
|
||||
const response = await contexts[0].request.post(
|
||||
process.env.QA_ISSUER + "/__qa/change",
|
||||
{
|
||||
headers: { "X-QA-Control": process.env.QA_CONTROL },
|
||||
data: {
|
||||
Name: "Alice",
|
||||
Version: "A-1",
|
||||
Status: "authenticated",
|
||||
Denied: false,
|
||||
Offline: false,
|
||||
...values,
|
||||
},
|
||||
}
|
||||
);
|
||||
assert.equal(response.status(), 204);
|
||||
};
|
||||
try {
|
||||
const context = await browser.newContext({
|
||||
ignoreHTTPSErrors: true,
|
||||
viewport: { width: 1300, height: 900 },
|
||||
locale: "en-US",
|
||||
});
|
||||
contexts.push(context);
|
||||
await context.route("**/internal/session/frame?**", (route) =>
|
||||
route.abort()
|
||||
);
|
||||
const cookies = (device) =>
|
||||
[
|
||||
["one", process.env.QA_APP_ONE],
|
||||
["two", process.env.QA_APP_TWO],
|
||||
].map(([id, url]) => ({
|
||||
name: "__Host-internal_session",
|
||||
value: id + "-" + device + "-binding-123456789",
|
||||
url,
|
||||
secure: true,
|
||||
httpOnly: true,
|
||||
sameSite: "Lax",
|
||||
}));
|
||||
await context.addCookies(cookies("device-one"));
|
||||
const a = await context.newPage(),
|
||||
b = await context.newPage();
|
||||
for (const p of [a, b]) p.on("pageerror", (e) => errors.push(String(e)));
|
||||
await Promise.all([
|
||||
a.goto(process.env.QA_APP_ONE + "/files/"),
|
||||
b.goto(process.env.QA_APP_TWO + "/files/"),
|
||||
]);
|
||||
try {
|
||||
await Promise.all([
|
||||
a.getByText("Alice-private.txt", { exact: true }).waitFor(),
|
||||
b.getByText("Alice-private.txt", { exact: true }).waitFor(),
|
||||
]);
|
||||
} catch (error) {
|
||||
console.log("INITIAL ERRORS", errors);
|
||||
for (const [index, page] of [a, b].entries()) {
|
||||
console.log("BODY", index, await page.locator("body").innerText());
|
||||
console.log(
|
||||
"SESSION",
|
||||
await (
|
||||
await context.request.get(
|
||||
(index === 0 ? process.env.QA_APP_ONE : process.env.QA_APP_TWO) +
|
||||
"/auth/session"
|
||||
)
|
||||
).text()
|
||||
);
|
||||
await page.screenshot({
|
||||
path: path.join(output, `initial-${index}.png`),
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
const device2 = await browser.newContext({ ignoreHTTPSErrors: true });
|
||||
contexts.push(device2);
|
||||
await device2.addCookies(cookies("device-two"));
|
||||
const independent = await device2.newPage();
|
||||
await independent.goto(process.env.QA_APP_ONE + "/files/");
|
||||
await independent.getByText("Alice-private.txt", { exact: true }).waitFor();
|
||||
// Hold a valid A response until after both applications have switched to B.
|
||||
let release;
|
||||
const held = new Promise((r) => (release = r));
|
||||
let ready;
|
||||
const captured = new Promise((r) => (ready = r));
|
||||
let didHold = false;
|
||||
await a.route("**/api/resources/", async (route) => {
|
||||
if (didHold) {
|
||||
await route.continue();
|
||||
return;
|
||||
}
|
||||
didHold = true;
|
||||
const response = await route.fetch();
|
||||
ready();
|
||||
await held;
|
||||
await route.fulfill({ response }).catch(() => {});
|
||||
});
|
||||
await a.getByRole("button", { name: "Actions", exact: true }).click();
|
||||
await a.getByRole("menuitem", { name: "Refresh", exact: true }).click();
|
||||
await captured;
|
||||
await change({ Name: "Bob", Version: "B-1" });
|
||||
await Promise.all([
|
||||
a
|
||||
.getByText("Bob-private.txt", { exact: true })
|
||||
.waitFor({ timeout: 15000 }),
|
||||
b
|
||||
.getByText("Bob-private.txt", { exact: true })
|
||||
.waitFor({ timeout: 15000 }),
|
||||
]);
|
||||
release();
|
||||
|
||||
await a.unroute("**/api/resources/");
|
||||
await a.waitForTimeout(200);
|
||||
assert.equal(
|
||||
await a.getByText("Alice-private.txt", { exact: true }).count(),
|
||||
0
|
||||
);
|
||||
assert.equal(
|
||||
await b.getByText("Alice-private.txt", { exact: true }).count(),
|
||||
0
|
||||
);
|
||||
assert(
|
||||
await independent
|
||||
.getByText("Alice-private.txt", { exact: true })
|
||||
.isVisible()
|
||||
);
|
||||
assert(!new URL(a.url()).pathname.startsWith("/auth/"));
|
||||
assert(!new URL(b.url()).pathname.startsWith("/auth/"));
|
||||
await a.screenshot({ path: path.join(output, "account-B.png") });
|
||||
const stale = await context.request.post(
|
||||
process.env.QA_APP_ONE + "/api/resources/stale.txt",
|
||||
{
|
||||
headers: { "X-FB-Request": "1", "X-FB-Session-State": "A-1" },
|
||||
data: "must not write",
|
||||
}
|
||||
);
|
||||
assert.equal(stale.status(), 409);
|
||||
await change({ Name: "Bob", Version: "B-1", Denied: true });
|
||||
await b
|
||||
.getByRole("heading", { name: "Access denied", exact: true })
|
||||
.waitFor({ timeout: 15000 });
|
||||
assert.equal(
|
||||
await b.getByText("Alice-private.txt", { exact: true }).count(),
|
||||
0
|
||||
);
|
||||
assert.equal(
|
||||
await b.getByText("Bob-private.txt", { exact: true }).count(),
|
||||
0
|
||||
);
|
||||
await change({ Name: "Bob", Version: "B-1", Offline: true });
|
||||
await a
|
||||
.getByRole("heading", {
|
||||
name: "Sign-in service unavailable",
|
||||
exact: true,
|
||||
})
|
||||
.waitFor({ timeout: 15000 });
|
||||
assert.equal(
|
||||
await a.getByText("Bob-private.txt", { exact: true }).count(),
|
||||
0
|
||||
);
|
||||
assert(
|
||||
(await context.cookies(process.env.QA_APP_ONE)).some(
|
||||
(c) => c.name === "__Host-internal_session"
|
||||
)
|
||||
);
|
||||
await change({ Name: "Bob", Version: "B-2" });
|
||||
await a
|
||||
.getByText("Bob-private.txt", { exact: true })
|
||||
.waitFor({ timeout: 15000 });
|
||||
const logout = await context.request.post(
|
||||
process.env.QA_APP_ONE + "/auth/logout",
|
||||
{ headers: { "X-FB-Request": "1", "X-FB-Session-State": "B-2" } }
|
||||
);
|
||||
assert.equal(logout.status(), 204);
|
||||
await b
|
||||
.getByRole("heading", { name: "Signed out", exact: true })
|
||||
.waitFor({ timeout: 15000 });
|
||||
assert(
|
||||
await independent
|
||||
.getByText("Alice-private.txt", { exact: true })
|
||||
.isVisible()
|
||||
);
|
||||
await change({ Status: "factor_required", Version: "factor" });
|
||||
await b
|
||||
.getByRole("heading", { name: "Verify your sign-in", exact: true })
|
||||
.waitFor({ timeout: 15000 });
|
||||
assert(!new URL(b.url()).pathname.startsWith("/auth/"));
|
||||
const cookiesAtEnd = await context.cookies(process.env.QA_APP_TWO);
|
||||
const binding = cookiesAtEnd.find(
|
||||
(c) => c.name === "__Host-internal_session"
|
||||
);
|
||||
assert(
|
||||
binding &&
|
||||
binding.secure &&
|
||||
binding.httpOnly &&
|
||||
binding.path === "/" &&
|
||||
!binding.domain.startsWith(".")
|
||||
);
|
||||
assert.equal(errors.length, 0, errors.join("\n"));
|
||||
console.log(
|
||||
"Two apps: A→B, stale form, denied access, outage/recovery, shared logout, missing factor and independent device passed."
|
||||
);
|
||||
} finally {
|
||||
for (const c of contexts) await c.close();
|
||||
await browser.close();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -0,0 +1,121 @@
|
||||
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;
|
||||
});
|
||||
Reference in new issue
Block a user