gunk-dev/the-valley

web-push-e2e.nix

source247c466675ffmain's published tip history
5.6 KiB
1# End-to-end check for the web push path using the packaged binaries:
2# valley-web-publish, valley-web-receive, and valley-web as built and
3# wrapped by nix/packages.nix (with their pinned tools and schemas),
4# the packaged valley CLI (valley-script, unstamped so commits alone do
5# not trigger a rebuild), and git.
6#
7# The test creates a valley instance with four projects in one group: two
8# that anyone may read, app and site; docs, which two named readers may
9# read, alice and the operator; and notes, which has no effective reader.
10# It verifies that:
11# 1. valley-web-publish sends an authorization and uploads app, site and
12# docs to valley-web-receive, which makes the store's descriptor
13# and its v2 payload directory, and valley-web serves them at their
14# group URLs and redirects a short alias and a former name with 308.
15# A project's Markdown README renders with an id on its heading and
16# its relative link rewritten to the target's page at the same
17# commit. Every response, a page, a redirect, an archive and a 404,
18# for GET and HEAD, is Cache-Control: private, no-store with Vary:
19# Cookie and no ETag, is never answered 304, and carries its route's
20# policy: the knots page's admits its script by its hash, every
21# other route's admits no script, and none lets a script connect.
22# The pages say when the policy was last checked, and a pass with
23# nothing changed sends no content but a newly signed authorization,
24# whose later check the pages show, while export.json keeps its
25# bytes. A replayed authorization, a forged one, and a manifest of the
26# first protocol are refused, and valley-web refuses the directory the
27# first store layout took as its state. docs reaches the store, its
28# authorization naming both its readers; nothing of notes does; and
29# an anonymous request gets 404 for both on every route.
30# 2. An upload with a wrong token fails as unauthenticated while
31# valley-web continues serving the previous export.
32# 3. A policy check that cannot read docs keeps only the readers a
33# grant still covers, on the basis of the stored authorization, and
34# fails as incomplete. Removing one of docs' two readers keeps docs;
35# removing the last withdraws it and deletes its repository while
36# export.json keeps its bytes. Withdrawing anyone's grant removes a
37# project from anonymous view on the next pass, and keeps it on the
38# edge for its named readers. A withdrawal of site that coincides
39# with growth past the 256 KiB a receiver reads still reaches the
40# edge, by the bounded fallback, and the pass fails naming the
41# overflow. A --policy-only pass withdraws site
42# and docs while a content upload is stalled on the receiver's
43# activation lock: the next request to valley-web, not restarted, no
44# longer serves site; the stalled upload, whose export still holds
45# both, activates later and restores neither's authorization; the
46# receiver deletes both repositories, and the active export.json
47# keeps its bytes. Removing the stored authorization serves no
48# project. Granting a project again sends its bundle again.
49# 4. Both servers preserve the active export across a restart.
50# 5. Read links: issued only to a principal who may read a project,
51# carried to the edge as bindings, and revoked by the next pass. A
52# revoke does not wait for a pass checking the policy. It waits for
53# a pass paused holding the links lock, and the pass after it signs
54# no binding for the revoked link. A host
55# restore restores the links as they were at the backup, and
56# revoke --all then cuts every link off.
57# 6. When the receiver is stopped, valley-web continues serving, a
58# pass fails because it cannot send its authorization, and the next
59# pass after the receiver restarts signs a new authorization, with a
60# later sequence, that applies the withdrawal.
61# 7. Readers sign in at the origin valley-web is given, with its browser
62# state in a directory the test makes for it. valley-web started
63# before the receiver made its store exits, and one started under
64# an authorization that binds no link makes an empty state. A link
65# the host issues redeems once, into a session renewed on a
66# redirect, a 404, a page and an archive, whose bytes match
67# anyone's download; of eight concurrent redemptions of one link one
68# wins; the session survives both servers' restarts, ends at logout,
69# and ends at the pass that delivers its link's revocation; a second
70# valley-web over the same browser state refuses to start. A lost
71# state is not made again while a link is bound, with redemption and
72# cookies answered 503 and anyone served, until every link is
73# revoked and a pass delivers that; an unreadable state is kept as it
74# is until the operator removes it. No log, no browser state and no
75# host state holds a link's secret or a session's token.
76#
77# The check runs inside the Nix build sandbox as a single user. The
78# separation between the receiver's user and valley-web's user is
79# checked by module-eval and web-image.
80{
81 pkgs,
82 packages,
83 ...
84}:
85{
86 web-push-e2e = pkgs.runCommand "valley-web-push-e2e" {
87 nativeBuildInputs = [
88 pkgs.git
89 pkgs.cue
90 pkgs.curl
91 pkgs.jq
92 pkgs.util-linux
93 packages.valley-script
94 packages.valley-web-publish
95 packages.valley-web-receive
96 packages.valley-web
97 ];
98 schema = ../../schema/valley.cue;
99 readSchema = ../../schema/read.cue;
100 } (builtins.readFile ./web-push-e2e.sh);
101}