GRI-1971: acceptance tests for permission scoping on reads #166

Merged
vivy merged 1 commit from test/GRI-1971-permission-scoping-reads into dev 2026-11-13 20:37:14 +00:00
Member

What

Acceptance tests for permission scoping on reads, written independently of
any implementation (there is none yet — forge #44 is open, just released to
the back-end engineer, target Monday 16 Nov).

crates/server/tests/permission_scoping_acceptance_integration.rs covers,
against the current, concrete contract settled today on forge #159/#44 and
the plan document on GRI-1960:

  • A campus editor's GET /devices never lists another campus's devices.
  • A campus editor fetching another campus's device by direct id gets 404,
    not 403 — the caller must not learn the object exists.
  • The same editor can still fetch their own campus's device by id (the
    paired happy path).
  • A campus editor's GET /ip-rules is refused with 403 — the IP tab is
    admin-only, not a campus-scoping question.
  • An admin (scoped to every campus) still sees every campus's devices and
    can still read the IP rules (two more paired happy paths).

Fail-first evidence

Against dev at afe0f41, with a real PostgreSQL:

SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \
  cargo test -p server --test permission_scoping_acceptance_integration -- --include-ignored
test an_admin_can_list_ip_rules ... ok
test an_admin_lists_devices_across_every_campus ... ok
test a_campus_editor_can_fetch_their_own_campuss_device_by_id ... ok
test a_campus_editor_lists_only_their_own_campuss_devices ... FAILED
  the AM editor must never see the HE device, got [<AM id>, <HE id>]
test a_campus_editor_fetching_another_campuss_device_by_id_gets_404_not_403 ... FAILED
  assertion `left == right` failed: a cross-campus direct id must read as not-found, never as forbidden
    left: 200
   right: 404
test a_campus_editor_cannot_list_ip_rules ... FAILED
  assertion `left == right` failed
    left: 200
   right: 403

test result: FAILED. 3 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out

The three failures are exactly the missing feature (every _current: CurrentUser in devices/handlers.rs is unused today — no permission or
campus check runs at all). The three passes are controls, proving the test
harness and fixtures are sound independent of the feature under test.

Criterion-to-test mapping

Acceptance criterion (forge #46 / #159 / #44, plan on GRI-1960) Test
A permission scope filters list endpoints (rest-api.md, "Scoping applies to reads") a_campus_editor_lists_only_their_own_campuss_devices
Admin sees every campus ("one campus or all") an_admin_lists_devices_across_every_campus
A direct id of another campus answers 404, not 403 (#159) a_campus_editor_fetching_another_campuss_device_by_id_gets_404_not_403
(paired happy path) a_campus_editor_can_fetch_their_own_campuss_device_by_id
IP tab hidden for non-admins (GRI-1960 plan, #44) a_campus_editor_cannot_list_ip_rules
(paired happy path) an_admin_can_list_ip_rules

Schema assumption — needs the back-end engineer's confirmation

No role or campus assignment exists on users in dev. To run at all, these
tests assume users.role ('admin' / 'campus_editor') and
users.campus_id (nullable, NULL = all), mirroring the existing nullable
campus_id convention for every other campus-owned table. This file adds
those two columns to its own per-test database only (ALTER TABLE in
add_role_and_campus_columns), not to crates/server/migrations/ — that
migration is #44's design decision, not this file's. If the real shape
differs, only insert_scoped_user and that one helper need to change; every
assertion tests the public HTTP contract and does not.

Not covered here (follow-up)

  • /api/v1/media and /api/v1/playlists need the identical list- and
    get-by-id-scoping tests (forge #159 says so explicitly). Left out to keep
    this file focused on one resource.
  • /api/v1/settings being hidden from a non-admin needs SettingsState
    (a full Config, a settings file, a Restarter) — enough extra fixture
    weight to deserve its own file.
  • GET /api/v1/session does not expose the caller's permissions yet
    (UserView carries only id/email/name), though rest-api.md says it
    must. Noted as a finding in the file header, not asserted — there is no
    field name yet to assert on.

Test plan

  • cargo test -p server --test permission_scoping_acceptance_integration -- --include-ignored against a real Postgres: 3 pass (controls), 3 fail (the unimplemented feature, as expected)
  • cargo fmt -p server -- --check
  • cargo clippy -p server --test permission_scoping_acceptance_integration --all-targets -- -D warnings
  • cargo test -p server (the rest of the crate's suite, unaffected)
## What Acceptance tests for permission scoping on reads, written independently of any implementation (there is none yet — forge #44 is open, just released to the back-end engineer, target Monday 16 Nov). `crates/server/tests/permission_scoping_acceptance_integration.rs` covers, against the current, concrete contract settled today on forge #159/#44 and the `plan` document on `GRI-1960`: - A campus editor's `GET /devices` never lists another campus's devices. - A campus editor fetching another campus's device by direct id gets `404`, not `403` — the caller must not learn the object exists. - The same editor can still fetch their own campus's device by id (the paired happy path). - A campus editor's `GET /ip-rules` is refused with `403` — the IP tab is admin-only, not a campus-scoping question. - An admin (scoped to every campus) still sees every campus's devices and can still read the IP rules (two more paired happy paths). ## Fail-first evidence Against `dev` at `afe0f41`, with a real `PostgreSQL`: ``` SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \ cargo test -p server --test permission_scoping_acceptance_integration -- --include-ignored ``` ``` test an_admin_can_list_ip_rules ... ok test an_admin_lists_devices_across_every_campus ... ok test a_campus_editor_can_fetch_their_own_campuss_device_by_id ... ok test a_campus_editor_lists_only_their_own_campuss_devices ... FAILED the AM editor must never see the HE device, got [<AM id>, <HE id>] test a_campus_editor_fetching_another_campuss_device_by_id_gets_404_not_403 ... FAILED assertion `left == right` failed: a cross-campus direct id must read as not-found, never as forbidden left: 200 right: 404 test a_campus_editor_cannot_list_ip_rules ... FAILED assertion `left == right` failed left: 200 right: 403 test result: FAILED. 3 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out ``` The three failures are exactly the missing feature (every `_current: CurrentUser` in `devices/handlers.rs` is unused today — no permission or campus check runs at all). The three passes are controls, proving the test harness and fixtures are sound independent of the feature under test. ## Criterion-to-test mapping | Acceptance criterion (forge #46 / #159 / #44, `plan` on GRI-1960) | Test | | --- | --- | | A permission scope filters list endpoints (`rest-api.md`, "Scoping applies to reads") | `a_campus_editor_lists_only_their_own_campuss_devices` | | Admin sees every campus ("one campus or all") | `an_admin_lists_devices_across_every_campus` | | A direct id of another campus answers 404, not 403 (#159) | `a_campus_editor_fetching_another_campuss_device_by_id_gets_404_not_403` | | (paired happy path) | `a_campus_editor_can_fetch_their_own_campuss_device_by_id` | | IP tab hidden for non-admins (GRI-1960 plan, #44) | `a_campus_editor_cannot_list_ip_rules` | | (paired happy path) | `an_admin_can_list_ip_rules` | ## Schema assumption — needs the back-end engineer's confirmation No role or campus assignment exists on `users` in `dev`. To run at all, these tests assume `users.role` (`'admin'` / `'campus_editor'`) and `users.campus_id` (nullable, `NULL` = all), mirroring the existing nullable `campus_id` convention for every other campus-owned table. This file adds those two columns to **its own per-test database only** (`ALTER TABLE` in `add_role_and_campus_columns`), not to `crates/server/migrations/` — that migration is #44's design decision, not this file's. If the real shape differs, only `insert_scoped_user` and that one helper need to change; every assertion tests the public HTTP contract and does not. ## Not covered here (follow-up) - `/api/v1/media` and `/api/v1/playlists` need the identical list- and get-by-id-scoping tests (forge #159 says so explicitly). Left out to keep this file focused on one resource. - `/api/v1/settings` being hidden from a non-admin needs `SettingsState` (a full `Config`, a settings file, a `Restarter`) — enough extra fixture weight to deserve its own file. - `GET /api/v1/session` does not expose the caller's permissions yet (`UserView` carries only `id`/`email`/`name`), though `rest-api.md` says it must. Noted as a finding in the file header, not asserted — there is no field name yet to assert on. ## Test plan - [x] `cargo test -p server --test permission_scoping_acceptance_integration -- --include-ignored` against a real Postgres: 3 pass (controls), 3 fail (the unimplemented feature, as expected) - [x] `cargo fmt -p server -- --check` - [x] `cargo clippy -p server --test permission_scoping_acceptance_integration --all-targets -- -D warnings` - [x] `cargo test -p server` (the rest of the crate's suite, unaffected)
GRI-1971: acceptance tests for permission scoping on reads
Some checks failed
CI / the pre-push hook (pull_request) Successful in 49s
CI / cargo fmt (pull_request) Successful in 48s
CI / cargo clippy (pull_request) Successful in 3m16s
CI / cargo deny advisories (pull_request) Failing after 2m26s
CI / cargo deny (pull_request) Successful in 2m28s
CI / repository boundary (pull_request) Successful in 58s
CI / frontend-web (pull_request) Successful in 2m8s
CI / cargo test (pull_request) Successful in 9m32s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 13s
da928b4bb6
Fail-first against today's unscoped handlers: a campus-scoped
non-admin currently sees every campus's devices, fetches another
campus's device by direct id with 200 instead of 404, and reads the
IP rules with 200 instead of 403. Three paired happy-path tests
(admin sees everything, admin reads IP rules, an editor reads their
own campus's device) confirm the harness and fixtures are sound.

No role or campus assignment exists on users yet (#44 is not
implemented); the file adds both to its own per-test database only,
mirroring the existing nullable campus_id convention, as a stand-in
documented in the file header for the real migration #44 lands with.
vivy merged commit 8a2491f94c into dev 2026-11-13 20:37:14 +00:00
vivy deleted branch test/GRI-1971-permission-scoping-reads 2026-11-13 20:37:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage!166
No description provided.