mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
The switcher and the banner named a shared record's owner by their greeting name — the value they typed at onboarding for "how should HealthLog address you". When an owner has set a full name, that is what a delegate should see: entering somebody's record, you read whose it is by who they are. - the account-access resolver publishes the owner's `fullName` alongside the greeting name and the username - `accountLabel` prefers fullName, then displayName, then username. Optional on the argument so the grant-view and actor shapes that never carried it keep the old two-field behaviour untouched - the closed presentation schema carries `fullName` and its parity matcher compares it, so the two published views of the active record cannot name the same owner differently - the OpenAPI contract regenerates with the additive field This deliberately discloses the owner's full name to every delegate, read-only included — it was patient-identity data behind a MANAGE-gated export until now. That is the intended behaviour, documented at `accountLabel` so it is not mistaken for a leak and tightened back. The resolver, the schema parity, the label fallback and a read-only delegate's banner are each pinned by a test.
133 lines
3.9 KiB
TypeScript
133 lines
3.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { parseAccountAccess } from "../account-access-schema";
|
|
|
|
const sharedEntry = {
|
|
accountId: "record-a",
|
|
username: "record-a",
|
|
displayName: "Record A",
|
|
fullName: "Test Full Name",
|
|
access: "read",
|
|
level: "read",
|
|
recordKind: "shared",
|
|
sections: ["labs"],
|
|
canWrite: false,
|
|
};
|
|
|
|
function accessBlock(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
accounts: [sharedEntry],
|
|
active: sharedEntry,
|
|
recordKind: "shared",
|
|
canSwitch: true,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("parseAccountAccess", () => {
|
|
it("preserves canonical shared payloads, including an empty scope", () => {
|
|
const scoped = parseAccountAccess(accessBlock());
|
|
const empty = parseAccountAccess(
|
|
accessBlock({
|
|
accounts: [{ ...sharedEntry, sections: [] }],
|
|
active: { ...sharedEntry, sections: [] },
|
|
}),
|
|
);
|
|
|
|
expect(scoped?.active?.sections).toEqual(["labs"]);
|
|
expect(empty?.active?.sections).toEqual([]);
|
|
});
|
|
|
|
it("preserves the canonical manage compatibility fields", () => {
|
|
const manager = {
|
|
...sharedEntry,
|
|
access: "write",
|
|
level: "manage",
|
|
sections: null,
|
|
canWrite: true,
|
|
};
|
|
|
|
const parsed = parseAccountAccess(
|
|
accessBlock({ accounts: [manager], active: manager }),
|
|
);
|
|
|
|
expect(parsed?.active).toMatchObject({
|
|
level: "manage",
|
|
access: "write",
|
|
sections: null,
|
|
canWrite: true,
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"legacy access and resolved level",
|
|
{ access: "write", level: "write", canWrite: true },
|
|
{},
|
|
],
|
|
["record kind", { recordKind: "managed" }, { recordKind: "managed" }],
|
|
["scope", { sections: ["measurements"] }, {}],
|
|
[
|
|
"resolved write capability",
|
|
{ access: "write", level: "write", canWrite: true },
|
|
{},
|
|
],
|
|
["username", { username: "different-record" }, {}],
|
|
["display name", { displayName: "Different record" }, {}],
|
|
// v1.37.2 — the owner's full name is part of the entry now, so the two
|
|
// published views of the active record must agree on it like every other
|
|
// field. A parity matcher blind to it would let the banner and the
|
|
// switcher name the same owner differently.
|
|
["full name", { fullName: "Different name" }, {}],
|
|
])(
|
|
"fails closed when active disagrees with its canonical entry on %s",
|
|
(_field, activeOverrides, blockOverrides) => {
|
|
const active = { ...sharedEntry, ...activeOverrides };
|
|
const block = accessBlock({ active, ...blockOverrides });
|
|
|
|
expect(parseAccountAccess(block)).toBeNull();
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
["unknown level", { level: "owner" }],
|
|
["unknown record kind", { recordKind: "other" }],
|
|
["unknown section", { sections: ["other"] }],
|
|
["duplicated section", { sections: ["labs", "labs"] }],
|
|
["non-array section", { sections: "labs" }],
|
|
["read marked writable", { canWrite: true }],
|
|
["write marked read-only", { access: "write", level: "write" }],
|
|
[
|
|
"scoped manage",
|
|
{ access: "write", level: "manage", sections: ["labs"], canWrite: true },
|
|
],
|
|
[
|
|
"manage with read legacy field",
|
|
{ access: "read", level: "manage", sections: null, canWrite: true },
|
|
],
|
|
])("fails closed for %s entries", (_name, entryOverrides) => {
|
|
const entry = { ...sharedEntry, ...entryOverrides };
|
|
|
|
expect(
|
|
parseAccountAccess(accessBlock({ accounts: [entry], active: entry })),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("fails closed for a stale active entry or a contradictory switch block", () => {
|
|
expect(
|
|
parseAccountAccess(
|
|
accessBlock({ active: { ...sharedEntry, accountId: "stale-record" } }),
|
|
),
|
|
).toBeNull();
|
|
expect(parseAccountAccess(accessBlock({ canSwitch: false }))).toBeNull();
|
|
expect(
|
|
parseAccountAccess({
|
|
accounts: [],
|
|
active: null,
|
|
recordKind: "self",
|
|
canSwitch: true,
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|