mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
fix(02-12): refuse malformed record access
- Preserve absent-server compatibility while rejecting published invalid blocks\n- Partition refused record reads and withhold protected presentation
This commit is contained in:
1 parent
b844d04676
commit
21e111c06c
11 files changed
+380
-18
No files matched your search
@@ -52,6 +52,9 @@ const mockAccessRef: { value: AccountAccess } = {
|
||||
value: { accounts: [], active: null, canSwitch: false },
|
||||
};
|
||||
const mockAuthLoadingRef = { value: false };
|
||||
const mockAccountAccessStatusRef = {
|
||||
value: "valid" as "absent" | "valid" | "invalid",
|
||||
};
|
||||
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
useAuth: () => ({
|
||||
@@ -63,6 +66,7 @@ vi.mock("@/hooks/use-auth", () => ({
|
||||
avatarUrl: null,
|
||||
modules: {},
|
||||
accountAccess: mockAccessRef.value,
|
||||
accountAccessStatus: mockAccountAccessStatusRef.value,
|
||||
},
|
||||
isAuthenticated: true,
|
||||
isAuthUnknown: false,
|
||||
@@ -138,9 +142,14 @@ const MANAGED_GUARDIAN: AccountAccessEntry = {
|
||||
canWrite: true,
|
||||
};
|
||||
|
||||
function render(access: AccountAccess, pathname = "/"): string {
|
||||
function render(
|
||||
access: AccountAccess,
|
||||
pathname = "/",
|
||||
accountAccessStatus: "absent" | "valid" | "invalid" = "valid",
|
||||
): string {
|
||||
mockAccessRef.value = access;
|
||||
mockPathRef.value = pathname;
|
||||
mockAccountAccessStatusRef.value = accountAccessStatus;
|
||||
return renderToStaticMarkup(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<I18nProvider initialLocale="en">
|
||||
@@ -205,6 +214,18 @@ describe("<AuthShell> — the owner-only doors", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("refuses an invalid record block without mounting owner-only doors or children", () => {
|
||||
const html = render(OWN_RECORD, "/", "invalid");
|
||||
|
||||
expect(html).toContain("sentinel-unavailable");
|
||||
expect(html).not.toContain("sentinel-page");
|
||||
for (const slot of DOORS) {
|
||||
expect(html, `${slot} must not paint for a refused record`).not.toContain(
|
||||
slot,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
["read", OWNER_READ],
|
||||
["write", OWNER_WRITE],
|
||||
|
||||
@@ -79,7 +79,8 @@ export function AuthShell({
|
||||
// decides what to mount and the surfaces beneath it decide what to offer,
|
||||
// and the two disagreeing is the whole class of defect this hook exists to
|
||||
// close.
|
||||
const { inSharedRecord, recordKind, sections } = useRecordCapabilities();
|
||||
const { inSharedRecord, recordKind, sections, accessRefused } =
|
||||
useRecordCapabilities();
|
||||
// A managed profile has a deliberately small Settings surface of its own.
|
||||
// Let that route family reach its record-aware gate; adult shared records
|
||||
// stay in the generic refusal branch even at MANAGE.
|
||||
@@ -245,6 +246,23 @@ export function AuthShell({
|
||||
);
|
||||
}
|
||||
|
||||
// A present but malformed access block is not the older-server case. The
|
||||
// server may still be switched, so mounting children here could fetch target
|
||||
// data under owner controls. Offer only the actor-scoped way out.
|
||||
if (accessRefused) {
|
||||
return (
|
||||
<div
|
||||
data-slot="invalid-record-access-refusal"
|
||||
className="flex min-h-dvh flex-col"
|
||||
>
|
||||
<MaintainershipBanner />
|
||||
<main className="mx-auto w-full max-w-screen-xl px-4 py-10 md:px-6">
|
||||
<SharedRecordUnavailable />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Onboarding page — minimal shell, no sidebar/nav
|
||||
if (isOnboardingPage) {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user