forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { createAccountProvisioner } from "../scripts/openobserve-accounts";
|
||||
const native = {
|
||||
code: 200,
|
||||
user: "vp7-query@example.invalid",
|
||||
token: "SyntheticToken-123456",
|
||||
};
|
||||
test("native service-account success saves exact credential before returning without a human-user API", async () => {
|
||||
const events: string[] = [];
|
||||
const provision = createAccountProvisioner({
|
||||
create: async (path, body) => {
|
||||
events.push(path);
|
||||
expect(body.email).toBe(native.user);
|
||||
return { status: 200, data: native };
|
||||
},
|
||||
save: async (principal, account) => {
|
||||
events.push("saved:" + principal);
|
||||
expect(account).toEqual({ user: native.user, token: native.token });
|
||||
},
|
||||
});
|
||||
expect(await provision("query")).toEqual({
|
||||
user: native.user,
|
||||
token: native.token,
|
||||
});
|
||||
expect(events).toEqual(["/api/default/service_accounts", "saved:query"]);
|
||||
});
|
||||
for (const status of [401, 403, 500])
|
||||
test(`native HTTP${status} never publishes an account`, async () => {
|
||||
let saves = 0;
|
||||
const provision = createAccountProvisioner({
|
||||
create: async () => ({ status, data: native }),
|
||||
save: async () => {
|
||||
saves++;
|
||||
},
|
||||
});
|
||||
await expect(provision("query")).rejects.toThrow(
|
||||
"OPENOBSERVE_ACCOUNT_CREATE_REJECTED",
|
||||
);
|
||||
expect(saves).toBe(0);
|
||||
});
|
||||
for (const patch of [
|
||||
{ code: 403 },
|
||||
{ token: "" },
|
||||
{ token: "x".repeat(4097) },
|
||||
{ user: "foreign@example.invalid" },
|
||||
{ token: null },
|
||||
])
|
||||
test(`invalid native result fails closed ${Object.keys(patch)[0]} ${String(Object.values(patch)[0]).length}`, async () => {
|
||||
let saves = 0;
|
||||
const provision = createAccountProvisioner({
|
||||
create: async () => ({ status: 200, data: { ...native, ...patch } }),
|
||||
save: async () => {
|
||||
saves++;
|
||||
},
|
||||
});
|
||||
await expect(provision("query")).rejects.toThrow(
|
||||
"OPENOBSERVE_ACCOUNT_INVALID_RESPONSE",
|
||||
);
|
||||
expect(saves).toBe(0);
|
||||
});
|
||||
test("account persistence failure stays primary and prevents a success result", async () => {
|
||||
const failure = new Error("FIXTURE_STORAGE_FAILED");
|
||||
const provision = createAccountProvisioner({
|
||||
create: async () => ({ status: 200, data: native }),
|
||||
save: async () => {
|
||||
throw failure;
|
||||
},
|
||||
});
|
||||
try {
|
||||
await provision("query");
|
||||
throw new Error("UNEXPECTED_SUCCESS");
|
||||
} catch (error) {
|
||||
expect(error).toBe(failure);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user