mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
* fix(studio)!: use a dedicated administrator token header * fix(studio): migrate iOS administrator authentication
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { UiError } from "../src/i18n.ts";
|
|
import { ReMeClient } from "../src/reme-client.ts";
|
|
|
|
test("administrator credentials stay scoped to the selected backend", async () => {
|
|
const endpoint = "https://reme.example";
|
|
const credentials = { endpoint, token: "test-admin" };
|
|
const signal = new AbortController().signal;
|
|
const requests: RequestInit[] = [];
|
|
const fetchRequest: typeof fetch = async (_url, options) => {
|
|
requests.push(options!);
|
|
return Response.json({}, { status: requests.length === 1 ? 200 : 401 });
|
|
};
|
|
|
|
await new ReMeClient(endpoint, fetchRequest).manage(
|
|
{ type: "backend", action: "status", credentials },
|
|
signal,
|
|
);
|
|
assert.equal(
|
|
new Headers(requests[0].headers).get("x-reme-admin-token"),
|
|
"test-admin",
|
|
);
|
|
assert.equal(new Headers(requests[0].headers).get("authorization"), null);
|
|
assert.equal(requests[0].redirect, "error");
|
|
await assert.rejects(
|
|
new ReMeClient("https://different.example", fetchRequest).manage(
|
|
{ type: "backend", action: "status", credentials },
|
|
signal,
|
|
),
|
|
(error) => error instanceof UiError && error.key === "backendAuthRequired",
|
|
);
|
|
assert.equal(
|
|
new Headers(requests[1].headers).get("x-reme-admin-token"),
|
|
null,
|
|
);
|
|
assert.equal(new Headers(requests[1].headers).get("authorization"), null);
|
|
});
|