fix(caserun): 纠正 HWPOD 失败事实投影
This commit is contained in:
@@ -11,17 +11,19 @@ test("CaseRun internal requests reuse the existing bootstrap admin API key only
|
||||
const calls: Array<{ url: string; authorization: string | null }> = [];
|
||||
const fetchImpl = async (input: URL | RequestInfo, init: RequestInit = {}) => {
|
||||
const headers = new Headers(init.headers);
|
||||
calls.push({ url: String(input), authorization: headers.get("authorization") });
|
||||
calls.push({ url: input instanceof Request ? input.url : String(input), authorization: headers.get("authorization") });
|
||||
return new Response("{}", { status: 200, headers: { "content-type": "application/json" } });
|
||||
};
|
||||
const internalFetch = caseRunInternalFetch(fetchImpl as typeof fetch, "http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667", { HWLAB_BOOTSTRAP_ADMIN_API_KEY: "hwl_live_test" });
|
||||
|
||||
await internalFetch("http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667/v1/hwpod-node-ops", { method: "POST" });
|
||||
await internalFetch("https://lab-dev.hwpod.com/v1/hwpod-node-ops", { method: "POST" });
|
||||
await internalFetch(new Request("http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667/v1/hwpod-node-ops", { headers: { authorization: "Bearer caller-token" } }), { method: "POST" });
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
{ url: "http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667/v1/hwpod-node-ops", authorization: "Bearer hwl_live_test" },
|
||||
{ url: "https://lab-dev.hwpod.com/v1/hwpod-node-ops", authorization: null }
|
||||
{ url: "https://lab-dev.hwpod.com/v1/hwpod-node-ops", authorization: null },
|
||||
{ url: "http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667/v1/hwpod-node-ops", authorization: "Bearer caller-token" }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -223,7 +223,8 @@ export function caseRunInternalFetch(fetchImpl: typeof fetch, internalApiUrl: st
|
||||
return async (input: URL | RequestInfo, init: RequestInit = {}) => {
|
||||
const target = new URL(typeof input === "string" || input instanceof URL ? input : input.url);
|
||||
if (target.origin !== internalOrigin) return fetchImpl(input, init);
|
||||
const headers = new Headers(init.headers);
|
||||
const headers = new Headers(input instanceof Request ? input.headers : undefined);
|
||||
new Headers(init.headers).forEach((value, name) => headers.set(name, value));
|
||||
if (!headers.has("authorization")) headers.set("authorization", `Bearer ${apiKey}`);
|
||||
return fetchImpl(input, { ...init, headers });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user