fix(device-manager): keep auth redirects alive
This commit is contained in:
@@ -197,7 +197,10 @@ export function createDeviceManagerAuth({
|
|||||||
const launch = new URL(`/api/services/${encodeURIComponent(serviceSlug)}/launch`, launcherBaseUrl);
|
const launch = new URL(`/api/services/${encodeURIComponent(serviceSlug)}/launch`, launcherBaseUrl);
|
||||||
launch.searchParams.set("returnTo", safeReturnTo(`${url.pathname}${url.search}`));
|
launch.searchParams.set("returnTo", safeReturnTo(`${url.pathname}${url.search}`));
|
||||||
loginUrl.searchParams.set("returnTo", `${launch.pathname}${launch.search}`);
|
loginUrl.searchParams.set("returnTo", `${launch.pathname}${launch.search}`);
|
||||||
if (isHtmlRequest(request, url)) return redirect(response, loginUrl.toString());
|
if (isHtmlRequest(request, url)) {
|
||||||
|
redirect(response, loginUrl.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
sendJson(response, 401, {
|
sendJson(response, 401, {
|
||||||
ok: false,
|
ok: false,
|
||||||
error: "device_manager_auth_required",
|
error: "device_manager_auth_required",
|
||||||
|
|||||||
@@ -112,6 +112,10 @@ export function createDeviceManagerServer({
|
|||||||
}
|
}
|
||||||
return serveStatic(request, response, url, distRoot);
|
return serveStatic(request, response, url, distRoot);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (response.headersSent) {
|
||||||
|
response.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const statusCode = normalizeStatus(error?.statusCode);
|
const statusCode = normalizeStatus(error?.statusCode);
|
||||||
return sendJson(response, statusCode, {
|
return sendJson(response, statusCode, {
|
||||||
ok: false,
|
ok: false,
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ test("production configuration starts with runner-owned file tokens", async (t)
|
|||||||
authRequired: true,
|
authRequired: true,
|
||||||
deviceCoreConfigured: true,
|
deviceCoreConfigured: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rootResponse = await fetch(`http://127.0.0.1:${address.port}/`, {
|
||||||
|
redirect: "manual",
|
||||||
|
headers: { accept: "text/html" },
|
||||||
|
});
|
||||||
|
assert.equal(rootResponse.status, 302);
|
||||||
|
assert.equal(
|
||||||
|
rootResponse.headers.get("location"),
|
||||||
|
"https://hub.nodedc.ru/auth/login?returnTo=%2Fapi%2Fservices%2Fdevice-core%2Flaunch%3FreturnTo%3D%252F",
|
||||||
|
);
|
||||||
|
|
||||||
|
const healthAfterRedirect = await fetch(`http://127.0.0.1:${address.port}/healthz`);
|
||||||
|
assert.equal(healthAfterRedirect.status, 200);
|
||||||
|
assert.equal((await healthAfterRedirect.json()).ok, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Device Manager BFF exposes an empty, mutation-driven project workspace", async (t) => {
|
test("Device Manager BFF exposes an empty, mutation-driven project workspace", async (t) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user