fix(public-api): a key narrowed away from days stops getting days back through places

Places, notes and reservations hang off days, so asking for one of them implies
the day container. That implication ran ahead of the grant: a key minted with
scopes ['trips','places'] and deliberately no 'days' still received every day's
title and the day's own free-text notes, either by naming places or by naming
nothing at all, since an absent include narrows to the granted sections and
lands back in the same branch. Asking for days by name was a 403 the whole
time, so the two routes disagreed about the same fields.

The grant now reaches the service alongside the narrowed include. The container
is still implied, because the places inside it are useless without their date,
but the day's title and notes only go out to a key that was granted days. A key
with full access is unaffected: it is granted days whether or not it asks.
This commit is contained in:
Maurice
2026-09-13 22:27:01 +02:00
parent 54e5525568
commit c42cf5477b
5 changed files with 58 additions and 16 deletions
@@ -273,7 +273,7 @@ describe('PublicApiController — what a narrowed key reaches', () => {
expect(ctl.listTrips(req(ALL))).toEqual({ trips: [TRIP] });
expect(ctl.listBucketList(req(ALL))).toEqual({ items: [] });
expect(ctl.getTrip(req(ALL), '12', undefined)).toEqual(TRIP);
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES]);
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES], [...PUBLIC_API_SCOPES]);
});
it('PUBAPI-SCOPE-U021: a trips-only key reads the trip list', () => {
@@ -305,20 +305,21 @@ describe('PublicApiController — what a narrowed key reaches', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
apiController({ getTrip }).getTrip(req(limited('trips', 'days', 'notes')), '12', undefined);
// `include` absent means "everything"; refusing a key for wanting sections it
// never named would make a narrow key unable to read a trip at all.
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes']);
// never named would make a narrow key unable to read a trip at all. The grant
// rides along so the service can tell an implied day block from a granted one.
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes'], ['trips', 'days', 'notes']);
});
it('PUBAPI-SCOPE-U025: a trips-only key gets the summary and nothing that hangs off it', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
apiController({ getTrip }).getTrip(req(limited('trips')), '12', undefined);
expect(getTrip).toHaveBeenCalledWith(12, 7, []);
expect(getTrip).toHaveBeenCalledWith(12, 7, [], ['trips']);
});
it('PUBAPI-SCOPE-U026: an empty include is treated like an absent one, and narrowed too', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
apiController({ getTrip }).getTrip(req(limited('trips', 'days')), '12', ' ');
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days']);
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days'], ['trips', 'days']);
});
it('PUBAPI-SCOPE-U027: a section named explicitly and not granted is a 403, not a silent drop', () => {
@@ -340,7 +341,7 @@ describe('PublicApiController — what a narrowed key reaches', () => {
it('PUBAPI-SCOPE-U028: an include the key covers is passed through untouched', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
apiController({ getTrip }).getTrip(req(limited('trips', 'days', 'notes')), '12', 'days, notes');
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes']);
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes'], ['trips', 'days', 'notes']);
});
it('PUBAPI-SCOPE-U029: a bad id is still a 400 — the scope check does not swallow it', () => {
@@ -112,19 +112,19 @@ describe('PublicApiController', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
const res = makeController({ getTrip }).getTrip(req(7), '12', undefined);
expect(res).toEqual(TRIP);
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES]);
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES], expect.arrayContaining(['days']));
});
it('treats an empty include the same as an absent one', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
makeController({ getTrip }).getTrip(req(7), '12', ' ');
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES]);
expect(getTrip).toHaveBeenCalledWith(12, 7, [...PUBLIC_API_INCLUDES], expect.arrayContaining(['days']));
});
it('narrows to the requested sections and tolerates spacing', () => {
const getTrip = vi.fn().mockReturnValue(TRIP);
makeController({ getTrip }).getTrip(req(7), '12', 'days, notes');
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes']);
expect(getTrip).toHaveBeenCalledWith(12, 7, ['days', 'notes'], expect.arrayContaining(['days']));
});
/**