Caretaker Express · PostgreSQL · Cedar

Module 10 · Complete, test and operate the application

10.2 The whole application, as six users

Walk through the finished Caretaker as Alice, Bob, Carol, Dave, Nora and Ravi, compare each screen with the access matrix, and read the complete test suite as a specification.

≈ 30 min 17 steps 0 lines of code Replay verified

Starting point

Every feature, every policy and 131 tests are in place. You have mostly seen the application one lesson at a time.

Outcome

A complete tour with real screenshots from your own build, and a test report you can read as the specification of who may do what. No code changes.

The problem

Unit by unit, everything passes. But users meet the whole application at once: a dashboard, a list, a page with some buttons and not others. The last check before calling it finished is to look at it as each person in the scenario, and to make sure that what each person sees matches what the matrix says they may do.

Build it

Start from the seeded scenario, so your screens match these:

Run and comparecaretaker/
npm run db:reset

> caretaker@1.0.0 db:reset
> node --env-file=.env scripts/reset.js

database reset: schema dropped, migrations applied, scenario seeded
Server terminal (leave it running)caretaker/
npm run dev
> caretaker@1.0.0 dev
> node --env-file=.env --watch src/server.js

Caretaker listening on http://localhost:3000

Alice: admin at building 10, viewer at building 20

localhost:3000/issuessigned in as alice
Alice's issues list: buildings 10 and 20 only, with filters, sorting and pages.
Alice's issues list: buildings 10 and 20 only, with filters, sorting and pages.
localhost:3000/issues/101signed in as alice
Issue 101 at building 10, where Alice is admin: Edit, Move and Delete are offered.
Issue 101 at building 10, where Alice is admin: Edit, Move and Delete are offered.
localhost:3000/issues/103signed in as alice
Issue 103 at building 20, where Alice is a viewer: no buttons.
Issue 103 at building 20, where Alice is a viewer: no buttons.
localhost:3000/inspections/202signed in as alice
Inspection 202, which Alice created: Return is offered; Approve is not, because forbid-self-approval applies.
Inspection 202, which Alice created: Return is offered; Approve is not, because forbid-self-approval applies.
localhost:3000/buildings/10/accesssigned in as alice
Access to building 10, managed by Alice.
Access to building 10, managed by Alice.

Bob: admin at building 30 in another company

localhost:3000/issuessigned in as bob
Bob's issues list: one issue at Galway Studios. Liffey does not exist for him.
Bob's issues list: one issue at Galway Studios. Liffey does not exist for him.

Carol: organisation admin of Liffey

localhost:3000/signed in as carol
Carol's dashboard: both Liffey buildings, through her organisation role, without any building assignment.
Carol's dashboard: both Liffey buildings, through her organisation role, without any building assignment.

Dave: inspector at 10, reporter at 20

localhost:3000/inspections/201signed in as dave
Dave's own inspection 201, submitted: he cannot approve it, both because he is not an admin and because he created it.
Dave's own inspection 201, submitted: he cannot approve it, both because he is not an admin and because he created it.

Nora: registered, no access

localhost:3000/signed in as nora
Nora's dashboard: zeros and empty tables. Logged in is not the same as allowed.
Nora's dashboard: zeros and empty tables. Logged in is not the same as allowed.

Run and inspect

Read the test report as a specification. Count the tests in each file:

Run and comparecaretaker/
for f in test/*.test.js; do printf "%-32s %s\n" "$(basename $f .test.js)" "$(grep -cE "^\s*test\(" $f)"; done
access-matrix                    2
access                           4
auth                             5
authz-decisions                  5
authz-service                    4
building-access                  5
buildings                        6
csrf                             4
dashboard                        2
forged-input                     4
hardening                        3
inspections                      6
isolation                        5
issue-authz                      8
issue-list                       5
issue-moves                      5
issues                           11
list-parity                      2
members                          6
organisations                    5
policies                         2
rate-limit                       1
require-login                    7
resource-authz                   8
tenant-isolation                 2

The access-matrix and tenant-isolation files show few test( calls because they generate tests in a loop: one test per matrix row, and one per attacker. Now the complete run:

Run and comparecaretaker/
npm test 2>&1 | grep -E "^ℹ (tests|pass|fail)"
ℹ tests 131
ℹ pass 131
ℹ fail 0

What these 131 tests state, grouped:

Group Files States that
Features issues, issue-list, organisations, buildings, inspections, dashboard CRUD, validation, paging, sorting, workflow, transactions work
Authentication auth, require-login, csrf, rate-limit, hardening identity is established and protected
Policies policies, authz-decisions the policy store is valid; allow, forbid, implicit deny and failure behave as designed
The matrix access-matrix, issue-authz, resource-authz, access each user gets the specified answer for each request
Isolation isolation, list-parity, tenant-isolation, forged-input no tenant sees or changes another's data, lists agree with Cedar, forged input changes nothing
Administration members, building-access, issue-moves, authz-service grants, revocation, moves and the decision service follow the rules

Experiment

Predict Ravi is a member of Harbour Lets whose only building role was revoked. What does his dashboard show, and what does his organisation page show?
localhost:3000/signed in as ravi
Ravi's dashboard: nothing.
Ravi's dashboard: nothing.
localhost:3000/organisations/2signed in as ravi
Ravi's organisation page: he can see Harbour Lets and its building names, with no access to any building.
Ravi's organisation page: he can see Harbour Lets and its building names, with no access to any building.
Reveal Answer

His dashboard is empty, like Nora's: no building is visible. But he still sees the organisation page, because his membership remains; only his building role was revoked. That is the design from lesson 5.1, and the screenshot is the matrix cell made visible.

Ctrl+C Stop the server in the server terminal.

Checkpoint

Nothing changed in the code. Confirm the tree is clean:

Run and comparecaretaker/
git status
On branch main
nothing to commit, working tree clean

Recap and next step

Each user sees exactly what the matrix says, and the test suite reads as a specification of features, authentication, policies, isolation and administration.

One question remains for the application you built: does it run from nothing, on a fresh checkout, with only the documented commands? Next lesson answers it, then looks at what production would need.