| 1 | # End-to-end test script for the web push path (see web-push-e2e.nix). |
| 2 | # Each background server is launched with start, which waits up to 30 |
| 3 | # seconds for its listening address, and the EXIT trap stops all running |
| 4 | # servers when the script exits. |
| 5 | set -euo pipefail |
| 6 | |
| 7 | export HOME="$TMPDIR/home" |
| 8 | export XDG_CACHE_HOME="$TMPDIR/cache" |
| 9 | export XDG_STATE_HOME="$TMPDIR/xdg-state" |
| 10 | export GIT_CONFIG_NOSYSTEM=1 |
| 11 | export GIT_CONFIG_GLOBAL="$TMPDIR/gitconfig" |
| 12 | printf '[user]\n\tname = operator\n\temail = operator@example.org\n[init]\n\tdefaultBranch = main\n' > "$GIT_CONFIG_GLOBAL" |
| 13 | cd "$TMPDIR" |
| 14 | |
| 15 | fail() { |
| 16 | echo "web-push-e2e: $*" >&2 |
| 17 | exit 1 |
| 18 | } |
| 19 | |
| 20 | # The servers still running, stopped on every exit. |
| 21 | pids=() |
| 22 | stop() { |
| 23 | local pid=$1 rest=() p |
| 24 | kill -TERM "$pid" 2> /dev/null || true |
| 25 | for _ in $(seq 150); do |
| 26 | kill -0 "$pid" 2> /dev/null || break |
| 27 | sleep 0.1 |
| 28 | done |
| 29 | kill -KILL "$pid" 2> /dev/null || true |
| 30 | wait "$pid" 2> /dev/null || true |
| 31 | for p in "${pids[@]}"; do |
| 32 | if [ "$p" != "$pid" ]; then rest+=("$p"); fi |
| 33 | done |
| 34 | pids=("${rest[@]}") |
| 35 | } |
| 36 | cleanup() { |
| 37 | for pid in "${pids[@]}"; do stop "$pid"; done |
| 38 | } |
| 39 | trap cleanup EXIT |
| 40 | |
| 41 | # start NAME LOG COMMAND...: start a server that prints "NAME: listening |
| 42 | # on ADDR" on stderr once it listens, and wait at most 30 seconds for it. |
| 43 | # It sets pid and addr. |
| 44 | start() { |
| 45 | local name=$1 log=$2 |
| 46 | shift 2 |
| 47 | "$@" 2> "$log" & |
| 48 | pid=$! |
| 49 | pids+=("$pid") |
| 50 | for _ in $(seq 300); do |
| 51 | addr=$(sed -n "s/^$name: listening on //p" "$log") |
| 52 | if [ -n "$addr" ]; then return; fi |
| 53 | kill -0 "$pid" 2> /dev/null || fail "$name exited before it listened: $(cat "$log")" |
| 54 | sleep 0.1 |
| 55 | done |
| 56 | fail "$name did not say where it listens within 30 seconds" |
| 57 | } |
| 58 | |
| 59 | # get PATH: valley-web's status and Location for a GET of PATH, with its |
| 60 | # body in $TMPDIR/body. follow PATH: the same after following redirects. |
| 61 | get() { |
| 62 | curl -sS --max-time 10 -o "$TMPDIR/body" -w '%{http_code} %header{location}' "http://$web$1" |
| 63 | } |
| 64 | follow() { |
| 65 | curl -sS --max-time 10 --max-redirs 3 -L -o "$TMPDIR/body" -w '%{http_code}' "http://$web$1" |
| 66 | } |
| 67 | # serves PATH TEXT: valley-web serves PATH, after its redirect to the |
| 68 | # tree, with TEXT in the page. gone PATH: it answers 404. |
| 69 | serves() { |
| 70 | local status |
| 71 | status=$(follow "$1") |
| 72 | [ "$status" = 200 ] || fail "valley-web answered $1 with $status, want 200" |
| 73 | grep -qF "$2" "$TMPDIR/body" || fail "valley-web's page for $1 does not show $2" |
| 74 | } |
| 75 | gone() { |
| 76 | local status |
| 77 | status=$(get "$1") |
| 78 | [ "$status" = "404 " ] || fail "valley-web answered $1 with $status, want 404" |
| 79 | } |
| 80 | |
| 81 | # One pass of the publisher as the package wraps it, with its pinned git, |
| 82 | # cue, valley CLI and schemas. |
| 83 | publish() { |
| 84 | timeout -k 10 "${within:-300}" valley-web-publish --instance-repo "$TMPDIR/srv/valley.git" \ |
| 85 | --instance valley-host --destination example.org --host "$TMPDIR/host.json" \ |
| 86 | --state "$TMPDIR/publisher" --principals "$TMPDIR/principals.json" --links "$TMPDIR/links/links" "$@" |
| 87 | } |
| 88 | # The link command, with the flags each verb reads; issued PRINCIPAL |
| 89 | # issues a link and prints its ID alone. |
| 90 | link() { |
| 91 | valley-web-publish link "$@" --links "$TMPDIR/links/links" --state "$TMPDIR/publisher" |
| 92 | } |
| 93 | issue_link() { |
| 94 | link issue "$@" --instance-repo "$TMPDIR/srv/valley.git" --destination example.org --host "$TMPDIR/host.json" |
| 95 | } |
| 96 | issued() { issue_link --principal "$1" 2> /dev/null | sed 's/.*#\(lk-[0-9a-f]*\)\..*/\1/'; } |
| 97 | bindings() { grep -c '^binding ' edge/v2/authorization || true; } |
| 98 | |
| 99 | commit() { |
| 100 | git -C "work/$1" add --all |
| 101 | git -C "work/$1" commit --quiet -m "$1: $2" |
| 102 | git -C "work/$1" push --quiet origin main |
| 103 | } |
| 104 | |
| 105 | # The projects' publication identities, which their policy/read declares |
| 106 | # and the registry's grants name. |
| 107 | declare -A id=( |
| 108 | [valley]=f83927d5a4ed068cdd02a8cdaa09f26d |
| 109 | [app]=9da6809f038df92138c131cd16bed76d |
| 110 | [site]=273d5668702918ea7ae079de374db96b |
| 111 | ) |
| 112 | read_policy() { |
| 113 | printf 'package read\n\nproject: "%s"\nidentity: "%s"\nreaders: {%s}\n' "$1" "${id[$1]}" "$2" |
| 114 | } |
| 115 | # The instance's registry: the operator governs it, and anyone may read |
| 116 | # the projects of the scope given at the edge. |
| 117 | registry() { |
| 118 | cat << EOF |
| 119 | package identity |
| 120 | |
| 121 | boundaries: { |
| 122 | registry: kind: "registry" |
| 123 | web: {kind: "edge-read", destination: "example.org"} |
| 124 | } |
| 125 | genesis: "operator" |
| 126 | principals: operator: { |
| 127 | kind: "human" |
| 128 | keys: [{class: "ssh-ed25519", bound: "hardware", public: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyForARejectedFixtureAAAAAAAAAAA"}] |
| 129 | grants: { |
| 130 | govern: boundary: "registry" |
| 131 | read: {boundary: "web", projects: "all"} |
| 132 | } |
| 133 | } |
| 134 | principals: alice: {kind: "human", keys: [], grants: read: {boundary: "web", projects: "all"}} |
| 135 | anyone: grants: read: {boundary: "web", projects: $1} |
| 136 | EOF |
| 137 | } |
| 138 | |
| 139 | # 1. The instance and its two projects, each with its own Markdown README, |
| 140 | # which links its read policy, and both readable by anyone, in the group |
| 141 | # tools. app has the short alias a, and site the former name homepage. |
| 142 | for name in valley app site; do |
| 143 | git init --quiet --bare "srv/$name.git" |
| 144 | git init --quiet "work/$name" |
| 145 | git -C "work/$name" remote add origin "$TMPDIR/srv/$name.git" |
| 146 | git -C "work/$name" config valley.principal operator |
| 147 | done |
| 148 | mkdir -p work/valley/policy/instance work/valley/policy/read work/valley/identity |
| 149 | echo 'package verification' > work/valley/policy/instance/floor.cue |
| 150 | read_policy valley 'operator: true' > work/valley/policy/read/read.cue |
| 151 | registry "{app: \"${id[app]}\", site: \"${id[site]}\"}" > work/valley/identity/registry.cue |
| 152 | commit valley "the instance" |
| 153 | projects=$(printf 'app\nsite\nvalley\n' | git -C srv/valley.git hash-object -w --stdin) |
| 154 | git -C srv/valley.git update-ref refs/the-valley/projects "$projects" |
| 155 | for name in app site; do |
| 156 | mkdir -p "work/$name/policy/read" |
| 157 | echo "$TMPDIR/srv/valley.git" > "work/$name/policy/valley" |
| 158 | printf '# %s\n\n%s-readme-text, under [its read policy](policy/read/read.cue).\n' "$name" "$name" > "work/$name/README.md" |
| 159 | read_policy "$name" 'anyone: true, operator: true, alice: true' > "work/$name/policy/read/read.cue" |
| 160 | commit "$name" "the first commit" |
| 161 | done |
| 162 | knot=$(cd work/app && valley knot new outcome "Open the edge" --json | jq -r .knot.id) |
| 163 | |
| 164 | cat > host.cue << 'EOF' |
| 165 | package valley |
| 166 | |
| 167 | groups: core: name: "tools" |
| 168 | projects: app: {group: "core", aliases: ["a"]} |
| 169 | projects: site: {group: "core", formerNames: ["homepage"]} |
| 170 | projects: valley: {} |
| 171 | EOF |
| 172 | cue export --out json "$schema" host.cue > host.json |
| 173 | echo '{"operator": "operator"}' > principals.json |
| 174 | |
| 175 | # 2. A pass to a directory makes the export key, whose verifier line the |
| 176 | # receiver pins from its first start. Then the receiver and valley-web |
| 177 | # start over one state directory, and a pass uploads. |
| 178 | publish --out first > /dev/null |
| 179 | test -s publisher/verifier || fail "the first pass made no verifier line" |
| 180 | echo edge-token-0123456789abcdef0123456789 > token |
| 181 | echo another-token-0123456789abcdef0123456 > wrong |
| 182 | # valley-web signs readers in at the origin https://example.org, and keeps |
| 183 | # their sessions in edge/browser, which the deployment makes for it alone. |
| 184 | # Before the receiver makes its store, valley-web cannot open it and |
| 185 | # exits, for its service to start it again. |
| 186 | mkdir -p edge |
| 187 | mkdir -m 700 edge/browser |
| 188 | if valley-web --state edge/store --listen 127.0.0.1:0 --origin https://example.org 2> early.log; then |
| 189 | fail "valley-web started before the receiver made its store" |
| 190 | fi |
| 191 | receive() { |
| 192 | start valley-web-receive receive.log valley-web-receive --state edge/store --listen 127.0.0.1:0 \ |
| 193 | --instance valley-host --destination example.org --verifiers publisher/verifier --token-file token |
| 194 | receiver_pid=$pid receiver=http://$addr |
| 195 | } |
| 196 | serve() { |
| 197 | start valley-web web.log valley-web --state edge/store --listen 127.0.0.1:0 --origin https://example.org |
| 198 | web_pid=$pid web=$addr |
| 199 | cat web.log >> web.logs |
| 200 | } |
| 201 | receive |
| 202 | publish --receiver "$receiver" --receiver-token token > pass.out |
| 203 | grep -q "the receiver stored authorization 2: anyone may read app, site" pass.out || |
| 204 | fail "the pass did not say the receiver stored its authorization: $(cat pass.out)" |
| 205 | grep -q "the receiver activated sequence" pass.out || fail "the pass did not say the receiver activated it: $(cat pass.out)" |
| 206 | test -f edge/store && test -d edge/v2/generations && test -f edge/v2/authorization || |
| 207 | fail "the receiver did not make the store's descriptor, generations and authorization" |
| 208 | serve |
| 209 | serves /tools/app app-readme-text |
| 210 | # valley-web made its browser state when it started, under authorization |
| 211 | # 2, which binds no link, and the state holds no link yet. |
| 212 | [ "$(cat edge/browser/state)" = the-valley/web-reader-state/v1 ] || |
| 213 | fail "valley-web did not make an empty browser state: $(cat edge/browser/state)" |
| 214 | [ "$(stat -c %a edge/browser/state)" = 600 ] || fail "the browser state is mode $(stat -c %a edge/browser/state)" |
| 215 | # The README renders as Markdown: its heading has an id, and its relative |
| 216 | # link goes to the file's page at the same commit. |
| 217 | app_tip=$(git -C srv/app.git rev-parse main) |
| 218 | serves "/tools/app/source/tree/$app_tip/" '<h1 id="app">app <a class="anchor" href="#app">#</a></h1>' |
| 219 | grep -qF "<a href=\"/tools/app/source/blob/$app_tip/policy/read/read.cue\">its read policy</a>" "$TMPDIR/body" || |
| 220 | fail "app's README does not link its read policy at $app_tip: $(grep -F readme-text "$TMPDIR/body")" |
| 221 | serves /tools/site site-readme-text |
| 222 | # / lands on the source of the first project published, app, at its tip. |
| 223 | [ "$(get /)" = "302 /tools/app/source/tree/$app_tip/" ] || fail "/ answered $(get /)" |
| 224 | serves "/tools/app/knots/$knot" "Open the edge" |
| 225 | [ "$(get "/a/knots/$knot?x=1")" = "308 /tools/app/knots/$knot?x=1" ] || |
| 226 | fail "the alias a answered $(get "/a/knots/$knot?x=1")" |
| 227 | [ "$(get /tools/homepage/source/)" = "308 /tools/site/source/" ] || |
| 228 | fail "the former name homepage answered $(get /tools/homepage/source/)" |
| 229 | |
| 230 | # A reader downloads app's source from the link on its tree page: a |
| 231 | # gzipped tar archive of main's tip that lists main's files and |
| 232 | # directories, each under one directory named for the project and the |
| 233 | # commit. |
| 234 | serves /tools/app app-readme-text |
| 235 | tip=$(git -C work/app rev-parse HEAD) |
| 236 | grep -qF "href=\"/tools/app/source/archive/$tip.tar.gz\">Download .tar.gz<" "$TMPDIR/body" || |
| 237 | fail "app's tree page does not link the archive of main's tip" |
| 238 | status=$(curl -sS --max-time 10 -o app.tar.gz -w '%{http_code} %header{content-type}' "http://$web/tools/app/source/archive/$tip.tar.gz") |
| 239 | [ "$status" = "200 application/gzip" ] || fail "valley-web answered app's archive with $status" |
| 240 | prefix=app-${tip:0:12}/ |
| 241 | tar -tzf app.tar.gz | LC_ALL=C sort > listed |
| 242 | { |
| 243 | echo "$prefix" |
| 244 | git -C work/app ls-tree -r -t --format='%(objecttype) %(path)' HEAD | |
| 245 | sed -e "s|^tree \(.*\)|$prefix\1/|" -e "s|^blob \(.*\)|$prefix\1|" |
| 246 | } | LC_ALL=C sort > want |
| 247 | cmp -s listed want || fail "app's archive lists $(cat listed), not $(cat want)" |
| 248 | |
| 249 | # main.tar.gz is one address for the archive of main's tip, wherever main |
| 250 | # is: a temporary redirect to that archive, which curl -L follows to the |
| 251 | # same bytes. |
| 252 | [ "$(get /tools/app/source/archive/main.tar.gz)" = "302 /tools/app/source/archive/$tip.tar.gz" ] || |
| 253 | fail "app's main.tar.gz answered $(get /tools/app/source/archive/main.tar.gz)" |
| 254 | status=$(curl -sS --max-time 10 --max-redirs 3 -L -o main.tar.gz -w '%{http_code} %header{content-type}' "http://$web/tools/app/source/archive/main.tar.gz") |
| 255 | [ "$status" = "200 application/gzip" ] || fail "valley-web answered app's main.tar.gz with $status" |
| 256 | cmp -s main.tar.gz app.tar.gz || fail "app's main.tar.gz is not the archive of main's tip" |
| 257 | |
| 258 | # Every response is private and never stored: a page, a redirect, an |
| 259 | # archive, a 404 and a HEAD alike, even one that asks to be answered 304. |
| 260 | # None carries an ETag. The knots page's policy admits its one script by |
| 261 | # its hash; every other route's admits none. No policy lets a script |
| 262 | # connect anywhere. |
| 263 | headers() { curl -sS --max-time 10 -o /dev/null -D - -H 'If-None-Match: *' "$@" | tr -d '\r'; } |
| 264 | for path in / /-/knots "/tools/app/source/tree/$app_tip/" "/tools/app/source/archive/$tip.tar.gz" \ |
| 265 | /tools/app/source/archive/main.tar.gz "/a/knots/$knot" /tools/nosuch/ /-/nosuch; do |
| 266 | for method in GET HEAD; do |
| 267 | if [ "$method" = HEAD ]; then got=$(headers -I "http://$web$path"); else got=$(headers "http://$web$path"); fi |
| 268 | grep -qx 'Cache-Control: private, no-store' <<< "$got" || fail "$method $path is not private and unstored: $got" |
| 269 | grep -qx 'Vary: Cookie' <<< "$got" || fail "$method $path does not vary by cookie: $got" |
| 270 | if grep -qi '^etag:' <<< "$got" || grep -q '^HTTP/[0-9.]* 304' <<< "$got"; then |
| 271 | fail "$method $path answered with an ETag or 304: $got" |
| 272 | fi |
| 273 | policy=$(sed -n 's/^Content-Security-Policy: //p' <<< "$got") |
| 274 | case $path in |
| 275 | /-/knots) script="script-src 'sha256-" ;; |
| 276 | *) script="script-src 'none';" ;; |
| 277 | esac |
| 278 | [[ $policy == *"$script"* && $policy == *"connect-src 'none'"* ]] || |
| 279 | fail "$method $path answered with the policy $policy" |
| 280 | done |
| 281 | done |
| 282 | |
| 283 | # The pages say when the policy was last checked, apart from when the |
| 284 | # plan was collected. A pass that finds nothing changed sends no content, |
| 285 | # and still sends an authorization, signed again with a later sequence and |
| 286 | # a later check, so the time the pages show advances while export.json |
| 287 | # keeps its bytes. |
| 288 | checked_of() { sed -n 's/^checked //p' "$1"; } |
| 289 | sequence_of() { sed -n 's/^sequence //p' "$1"; } |
| 290 | shown() { date -u -d "$1" '+%Y-%m-%d %H:%M UTC'; } |
| 291 | serves /-/knots "Policy last checked $(shown "$(checked_of edge/v2/authorization)")" |
| 292 | grep -qF "Collected " "$TMPDIR/body" || fail "the knots page does not say when the plan was collected" |
| 293 | digest=$(sha256sum edge/v2/current/export.json | cut -d' ' -f1) |
| 294 | before=$(checked_of edge/v2/authorization) |
| 295 | sleep 1.1 |
| 296 | publish --receiver "$receiver" --receiver-token token > pass.out |
| 297 | grep -q "nothing has changed since; nothing is sent" pass.out || fail "an unchanged pass sent content: $(cat pass.out)" |
| 298 | [ "$(sequence_of edge/v2/authorization)" = 3 ] || fail "an unchanged pass stored authorization $(sequence_of edge/v2/authorization), want 3" |
| 299 | [ "$(checked_of edge/v2/authorization)" != "$before" ] || fail "an unchanged pass did not advance the policy check from $before" |
| 300 | [ "$(sha256sum edge/v2/current/export.json | cut -d' ' -f1)" = "$digest" ] || |
| 301 | fail "an unchanged pass changed export.json" |
| 302 | serves /-/knots "Policy last checked $(shown "$(checked_of edge/v2/authorization)")" |
| 303 | |
| 304 | # A read link: issued only to a principal the registry grants an edge |
| 305 | # read that a project consents to, here alice, who holds no key. The host |
| 306 | # keeps its verifier, and the next pass carries it to the edge. |
| 307 | mkdir -m 750 links |
| 308 | if issue_link --principal bob > bob.out 2> bob.err; then fail "a link was issued to bob, whom the registry does not name"; fi |
| 309 | grep -q "grants bob no edge read" bob.err || fail "issuing to bob failed for another reason: $(cat bob.err)" |
| 310 | url=$(issue_link --principal alice --note laptop 2> issue.err) |
| 311 | [[ $url =~ ^https://example\.org/-/redeem#(lk-[0-9a-f]{16})\.([A-Za-z0-9_-]{43})$ ]] || |
| 312 | fail "issue printed ${#url} characters, not one link: $(cat issue.err)" |
| 313 | lk=${BASH_REMATCH[1]} secret=${BASH_REMATCH[2]} |
| 314 | link list > list.out |
| 315 | grep -Eq "^$lk +alice +active +pending" list.out || fail "an undelivered link is not pending: $(cat list.out)" |
| 316 | publish --receiver "$receiver" --receiver-token token > pass.out |
| 317 | verifier=$(printf '%s=' "$secret" | tr '_-' '/+' | base64 -d | sha256sum | cut -d' ' -f1) |
| 318 | grep -Eqx "binding $lk alice $verifier" edge/v2/authorization || |
| 319 | fail "the stored authorization does not bind $lk to alice by the secret's SHA-256: $(grep binding edge/v2/authorization)" |
| 320 | link list > list.out |
| 321 | grep -Eq "^$lk +alice +active +enforced +[0-9TZ:-]+ +laptop$" list.out || fail "a delivered link is not enforced: $(cat list.out)" |
| 322 | if grep -rqF "$secret" publisher edge links first ./*.out ./*.err ./*.log; then |
| 323 | fail "the link's secret is in the publisher's state, the edge, the credential file, an export or a log" |
| 324 | fi |
| 325 | |
| 326 | # An authorization the receiver stored already is refused as replayed, |
| 327 | # and one whose text was changed is refused for its signature, whatever |
| 328 | # its sequence. |
| 329 | post() { |
| 330 | curl -sS --max-time 10 -o "$TMPDIR/reply" -w '%{http_code}' -H "Authorization: Bearer $(cat token)" \ |
| 331 | --data-binary "@$2" "$receiver$1" |
| 332 | } |
| 333 | [ "$(post /web-export/v2/authorization publisher/authorization)" = 409 ] && grep -q '"error":"replayed"' reply || |
| 334 | fail "a replayed authorization was not refused as replayed: $(cat reply)" |
| 335 | sed 's/^sequence .*/sequence 99/' publisher/authorization > forged |
| 336 | [ "$(post /web-export/v2/authorization forged)" = 403 ] && grep -q '"error":"bad-signature"' reply || |
| 337 | fail "an authorization whose text was changed was not refused for its signature: $(cat reply)" |
| 338 | |
| 339 | # A publisher of the first protocol is refused with a clear error, and |
| 340 | # valley-web refuses the directory the first store layout took as its |
| 341 | # state. |
| 342 | [ "$(post /web-export/v1/manifest forged)" = 410 ] && grep -q '"error":"unsupported-version"' reply || |
| 343 | fail "a manifest of the first protocol was not refused as unsupported-version: $(cat reply)" |
| 344 | if valley-web --state edge --listen 127.0.0.1:0 2> old.log; then fail "valley-web served the store's directory"; fi |
| 345 | grep -q "is a directory" old.log || fail "valley-web refused the store's directory for another reason: $(cat old.log)" |
| 346 | |
| 347 | # 3. A comment changes the export, so the next pass uploads. With another |
| 348 | # token it is refused as unauthenticated, and the edge keeps serving what |
| 349 | # it had. |
| 350 | (cd work/app && valley knot comment "$knot" -m "edge-comment-text" > /dev/null) |
| 351 | if publish --receiver "$receiver" --receiver-token wrong > pass.out 2> pass.err; then |
| 352 | fail "a pass with another token succeeded" |
| 353 | fi |
| 354 | grep -q unauthenticated pass.err || fail "a pass with another token failed for another reason: $(cat pass.err)" |
| 355 | serves "/tools/app/knots/$knot" "Open the edge" |
| 356 | if grep -qF edge-comment-text "$TMPDIR/body"; then fail "the refused pass's comment is served"; fi |
| 357 | |
| 358 | # 4. Withdrawing anyone's grant for app takes app off the edge on the |
| 359 | # next pass, its alias with it, and site stays. |
| 360 | registry "{site: \"${id[site]}\"}" > work/valley/identity/registry.cue |
| 361 | commit valley "withdraw app" |
| 362 | publish --receiver "$receiver" --receiver-token token > /dev/null |
| 363 | gone /tools/app |
| 364 | gone /a |
| 365 | serves /tools/site site-readme-text |
| 366 | |
| 367 | # 4b. A withdrawal by authorization alone, while content work is |
| 368 | # stalled. With app granted again, a new knot changes the export, and a |
| 369 | # pass reads it, site included, then stalls at its upload: the test holds |
| 370 | # the receiver's activation lock, as a commit that checks a large |
| 371 | # repository would. Meanwhile site's grant is withdrawn, and a |
| 372 | # --policy-only pass takes site off the edge at once: valley-web, not |
| 373 | # restarted, answers the next request without it. Once the lock is |
| 374 | # released, the stalled upload, whose content holds site and whose |
| 375 | # sequence is later, activates and restores nothing. The receiver deletes |
| 376 | # site's repository, and the active export.json keeps its signed bytes. |
| 377 | registry "{app: \"${id[app]}\", site: \"${id[site]}\"}" > work/valley/identity/registry.cue |
| 378 | commit valley "grant app again" |
| 379 | publish --receiver "$receiver" --receiver-token token > /dev/null |
| 380 | serves /tools/app app-readme-text |
| 381 | (cd work/site && valley knot new outcome "Withdrawn while stalled" > /dev/null) |
| 382 | flock -o edge/v2/lock sleep 300 & |
| 383 | holder=$! |
| 384 | pids+=("$holder") |
| 385 | publish --receiver "$receiver" --receiver-token token > stalled.out 2> stalled.err & |
| 386 | stalled=$! |
| 387 | for _ in $(seq 600); do |
| 388 | grep -q "^valley-web-publish: public: app, site" stalled.out && break |
| 389 | kill -0 "$stalled" 2> /dev/null || fail "the stalled pass ended before its upload: $(cat stalled.out stalled.err)" |
| 390 | sleep 0.1 |
| 391 | done |
| 392 | grep -q "^valley-web-publish: public: app, site" stalled.out || fail "the stalled pass did not read the valley within a minute" |
| 393 | sleep 1 |
| 394 | registry "{app: \"${id[app]}\"}" > work/valley/identity/registry.cue |
| 395 | commit valley "withdraw site" |
| 396 | link revoke "$lk" > /dev/null |
| 397 | if link list --check "$lk" > /dev/null 2> check.err; then fail "an undelivered revocation is not pending"; fi |
| 398 | grep -q "$lk: revoked here; the edge may accept it until a pass delivers the revocation" check.err || |
| 399 | fail "list --check did not say the revocation is pending: $(cat check.err)" |
| 400 | within=40 publish --receiver "$receiver" --receiver-token token --policy-only > policy.out || |
| 401 | fail "a --policy-only pass failed while content was stalled" |
| 402 | grep -q "anyone may read app$" policy.out || fail "the --policy-only pass did not withdraw site: $(cat policy.out)" |
| 403 | if grep -q "the receiver activated" policy.out; then fail "the --policy-only pass sent content"; fi |
| 404 | gone /tools/site |
| 405 | gone /tools/homepage |
| 406 | serves /tools/app app-readme-text |
| 407 | if grep -q "^binding $lk " edge/v2/authorization; then fail "the --policy-only pass did not revoke $lk"; fi |
| 408 | link list --check "$lk" > list.out || fail "a delivered revocation is still pending" |
| 409 | grep -Eq "^$lk +alice +revoked +enforced" list.out || fail "a delivered revocation is not enforced: $(cat list.out)" |
| 410 | kill -0 "$stalled" 2> /dev/null || fail "the stalled pass did not stall: $(cat stalled.out stalled.err)" |
| 411 | stop "$holder" |
| 412 | wait "$stalled" || fail "the stalled pass failed once its upload went on: $(cat stalled.err)" |
| 413 | grep -q "the receiver activated sequence" stalled.out || fail "the stalled pass did not activate its upload: $(cat stalled.out)" |
| 414 | grep -q '"project":"site"' edge/v2/current/export.json || fail "the stalled upload's export does not hold site" |
| 415 | gone /tools/site |
| 416 | digest=$(sha256sum edge/v2/current/export.json | cut -d' ' -f1) |
| 417 | for _ in $(seq 300); do |
| 418 | [ -e edge/v2/current/repos/site.git ] || break |
| 419 | sleep 0.1 |
| 420 | done |
| 421 | [ ! -e edge/v2/current/repos/site.git ] || fail "the receiver kept the repository of site after its withdrawal" |
| 422 | [ -e edge/v2/current/repos/app.git ] || fail "the receiver deleted the repository of app" |
| 423 | [ "$(sha256sum edge/v2/current/export.json | cut -d' ' -f1)" = "$digest" ] || |
| 424 | fail "the withdrawal changed the signed export.json" |
| 425 | |
| 426 | # Revoking a principal's links, and then every link, reaches the edge |
| 427 | # through a policy pass the same way. |
| 428 | issued alice > /dev/null |
| 429 | issued alice > /dev/null |
| 430 | kept=$(issued operator) |
| 431 | publish --receiver "$receiver" --receiver-token token --policy-only > /dev/null |
| 432 | [ "$(bindings)" = 3 ] || fail "the authorization carries $(bindings) bindings, want 3" |
| 433 | link revoke --principal alice > /dev/null |
| 434 | publish --receiver "$receiver" --receiver-token token --policy-only > /dev/null |
| 435 | [ "$(bindings)" = 1 ] && grep -Eq "^binding $kept operator " edge/v2/authorization || |
| 436 | fail "revoking alice's links left $(grep binding edge/v2/authorization)" |
| 437 | link revoke --all > /dev/null |
| 438 | publish --receiver "$receiver" --receiver-token token --policy-only > /dev/null |
| 439 | [ "$(bindings)" = 0 ] || fail "revoking every link left $(bindings) bindings" |
| 440 | link list --check > /dev/null || fail "a delivered revocation of every link is still pending" |
| 441 | |
| 442 | policy() { publish --receiver "$receiver" --receiver-token token --policy-only "$@"; } |
| 443 | |
| 444 | # A pass holds the links lock, the file lock beside the credential file, |
| 445 | # from just before it reads the file until it has signed. Every change to |
| 446 | # the file holds the same lock. Here a pass pauses holding it: the |
| 447 | # credential file is a FIFO, which the pass waits to read. A revoke |
| 448 | # meanwhile waits, and writes nothing, until the pass has signed, so the |
| 449 | # paused pass signs the link as active. The revocation is pending until |
| 450 | # the next pass, the one the wrapper starts after a revoke, signs no |
| 451 | # binding for the link and the receiver acknowledges it. |
| 452 | paused_lk=$(issued alice) |
| 453 | policy > /dev/null |
| 454 | grep -q "^binding $paused_lk " edge/v2/authorization || fail "the pass did not deliver $paused_lk" |
| 455 | # A revoke while a pass is checking the policy does not wait for the |
| 456 | # check: the pass holds only the authorization lock then. |
| 457 | mkdir pause |
| 458 | mkfifo pause/read.cue |
| 459 | VALLEY_READ_SCHEMA="$TMPDIR/pause/read.cue" policy > checking.out 2> checking.err & |
| 460 | checking=$! |
| 461 | for _ in $(seq 300); do |
| 462 | flock -n publisher/authorization.lock true || break |
| 463 | kill -0 "$checking" 2> /dev/null || fail "the pass ended before its policy check: $(cat checking.out checking.err)" |
| 464 | sleep 0.1 |
| 465 | done |
| 466 | if flock -n publisher/authorization.lock true; then fail "the pass did not take the authorization lock"; fi |
| 467 | early=$(issued alice) |
| 468 | link revoke "$early" > early.out 2> early.err || fail "a revoke while a pass checks the policy failed: $(cat early.err)" |
| 469 | if grep -q waiting early.err; then fail "a revoke waited for a pass that was checking the policy: $(cat early.err)"; fi |
| 470 | cp "$readSchema" pause/read.regular |
| 471 | timeout 30 bash -c 'exec 3> pause/read.cue && mv -f pause/read.regular pause/read.cue && cat "$1" >&3' _ "$readSchema" || |
| 472 | fail "the pass checking the policy did not read its schema" |
| 473 | wait "$checking" || fail "the pass checking the policy failed: $(cat checking.err)" |
| 474 | if grep -q "^binding $early " edge/v2/authorization; then fail "a pass signed $early, revoked while it checked the policy"; fi |
| 475 | # Now the pause inside the links lock. The FIFO is linked at the credential |
| 476 | # file's name, and keeps a second name for the test to write it through. |
| 477 | cp links/links pause/links.regular |
| 478 | cp links/links pause/links.content |
| 479 | mkfifo pause/links.fifo |
| 480 | ln -f pause/links.fifo links/links |
| 481 | policy > paused.out 2> paused.err & |
| 482 | paused=$! |
| 483 | for _ in $(seq 600); do |
| 484 | flock -n links/lock true || break |
| 485 | kill -0 "$paused" 2> /dev/null || fail "the paused pass ended before it read the credential file: $(cat paused.out paused.err)" |
| 486 | sleep 0.1 |
| 487 | done |
| 488 | if flock -n links/lock true; then fail "the paused pass did not take the links lock"; fi |
| 489 | link revoke "$paused_lk" > revoke.out 2> revoke.err & |
| 490 | revoking=$! |
| 491 | for _ in $(seq 300); do |
| 492 | grep -q "waiting up to 1m0s for the policy pass or the change that holds the links lock" revoke.err && break |
| 493 | kill -0 "$revoking" 2> /dev/null || fail "the revoke did not wait for the paused pass: $(cat revoke.out revoke.err)" |
| 494 | sleep 0.1 |
| 495 | done |
| 496 | grep -q "waiting up to 1m0s for the policy pass or the change that holds the links lock" revoke.err || |
| 497 | fail "the revoke did not say it waits for the paused pass: $(cat revoke.err)" |
| 498 | sleep 1 |
| 499 | kill -0 "$revoking" 2> /dev/null || fail "the revoke ended while a pass held the links lock: $(cat revoke.out revoke.err)" |
| 500 | [ -p links/links ] || fail "the revoke wrote the credential file while a pass held the links lock" |
| 501 | # Let the pass go on: once it has opened the FIFO, the regular file takes |
| 502 | # its place for the revoke, and the pass reads the file through the FIFO. |
| 503 | timeout 30 bash -c 'exec 3> pause/links.fifo && mv -f pause/links.regular links/links && cat pause/links.content >&3' || |
| 504 | fail "the paused pass did not read the credential file" |
| 505 | wait "$paused" || fail "the paused pass failed: $(cat paused.err)" |
| 506 | wait "$revoking" || fail "the revoke failed: $(cat revoke.err)" |
| 507 | grep -q "^revoked $paused_lk " revoke.out || fail "the revoke did not revoke $paused_lk: $(cat revoke.out)" |
| 508 | grep -q "^binding $paused_lk " edge/v2/authorization || fail "the paused pass did not sign $paused_lk, active as it signed" |
| 509 | if link list --check "$paused_lk" > list.out 2> check.err; then fail "a revocation no pass has delivered is not pending: $(cat list.out)"; fi |
| 510 | grep -Eq "^$paused_lk +alice +revoked +pending" list.out || fail "a revocation no pass has delivered is not pending: $(cat list.out)" |
| 511 | policy > /dev/null |
| 512 | if grep -q "^binding $paused_lk " edge/v2/authorization; then fail "the pass after the revoke signed the revoked $paused_lk"; fi |
| 513 | link list --check "$paused_lk" > list.out || fail "a delivered revocation is still pending: $(cat list.out)" |
| 514 | grep -Eq "^$paused_lk +alice +revoked +enforced" list.out || fail "a delivered revocation is not enforced: $(cat list.out)" |
| 515 | |
| 516 | # A lost acknowledgement: the receiver stored an authorization carrying a |
| 517 | # link, and the publisher never recorded it. A revocation after that is |
| 518 | # pending, never enforced, until a pass delivers it. |
| 519 | cp publisher/links-delivery delivery.before |
| 520 | cp publisher/authorization authorization.before |
| 521 | lost=$(issued alice) |
| 522 | policy > /dev/null |
| 523 | grep -q "^binding $lost " edge/v2/authorization || fail "the pass did not deliver $lost" |
| 524 | cp delivery.before publisher/links-delivery |
| 525 | cp authorization.before publisher/authorization |
| 526 | link revoke "$lost" > /dev/null |
| 527 | if link list --check "$lost" > list.out 2> check.err; then fail "a revocation after a lost acknowledgement is not pending: $(cat list.out)"; fi |
| 528 | grep -Eq "^$lost +alice +revoked +pending" list.out || fail "a revocation after a lost acknowledgement is not pending: $(cat list.out)" |
| 529 | policy > /dev/null |
| 530 | link list --check "$lost" > list.out || fail "a delivered revocation is still pending: $(cat list.out)" |
| 531 | |
| 532 | # A missing credential file holds no links, and the pass succeeds. A |
| 533 | # corrupt one sends an authorization with no bindings, and fails the pass. |
| 534 | kept=$(issued alice) |
| 535 | mv links/links links.kept |
| 536 | policy > /dev/null || fail "a pass with no credential file failed" |
| 537 | [ "$(bindings)" = 0 ] || fail "a pass with no credential file sent $(bindings) bindings" |
| 538 | echo '{' > links/links |
| 539 | if policy > /dev/null 2> corrupt.err; then fail "a pass with a corrupt credential file succeeded"; fi |
| 540 | grep -q "is not a credential file" corrupt.err || fail "a pass with a corrupt credential file failed for another reason: $(cat corrupt.err)" |
| 541 | [ "$(bindings)" = 0 ] || fail "a corrupt credential file sent $(bindings) bindings" |
| 542 | mv links.kept links/links |
| 543 | policy > /dev/null |
| 544 | grep -q "^binding $kept " edge/v2/authorization || fail "the credential file put back did not deliver $kept" |
| 545 | |
| 546 | # A credential file restored from an older copy holds a link revoked |
| 547 | # since. A pass signs the file as it is, so the link is active at the edge |
| 548 | # again. The next change writes past every revision a pass signed from, |
| 549 | # and revoke --all cuts every link off. |
| 550 | cp links/links links.older |
| 551 | link revoke "$kept" > /dev/null |
| 552 | policy > /dev/null |
| 553 | signed=$(jq .signed publisher/links-delivery) |
| 554 | cp links.older links/links |
| 555 | policy > /dev/null 2> older.err || fail "a pass from an older credential file failed: $(cat older.err)" |
| 556 | grep -q "^binding $kept " edge/v2/authorization || fail "a pass from an older credential file did not deliver the $kept it holds" |
| 557 | link revoke --all > /dev/null |
| 558 | [ "$(jq .revision links/links)" = $((signed + 1)) ] || |
| 559 | fail "revoke --all on an older credential file wrote revision $(jq .revision links/links), not $((signed + 1))" |
| 560 | policy > /dev/null |
| 561 | [ "$(bindings)" = 0 ] || fail "revoke --all on an older credential file left $(bindings) bindings" |
| 562 | link list --check > /dev/null || fail "after revoke --all a link is pending" |
| 563 | |
| 564 | # A host restore: the credential file and the publisher's state come back |
| 565 | # from one older backup, after a pass delivered a revocation. The pass |
| 566 | # after the restore signs above the authorization the receiver holds, and |
| 567 | # the links are as they were at the backup: the revoked link is active |
| 568 | # again. revoke --all then cuts every link off. |
| 569 | restored=$(issued alice) |
| 570 | policy > /dev/null |
| 571 | cp -a publisher backup.publisher |
| 572 | cp links/links backup.links |
| 573 | link revoke "$restored" > /dev/null |
| 574 | policy > /dev/null |
| 575 | if grep -q "^binding $restored " edge/v2/authorization; then fail "the pass did not revoke $restored"; fi |
| 576 | rm -rf publisher |
| 577 | cp -a backup.publisher publisher |
| 578 | cp backup.links links/links |
| 579 | policy > restored.out 2> restored.err || fail "a pass after a host restore failed: $(cat restored.err)" |
| 580 | grep -q "refused [0-9]* as replayed" restored.err || fail "the restored counter was not refused as replayed: $(cat restored.err)" |
| 581 | grep -q "^binding $restored " edge/v2/authorization || fail "a host restore did not restore $restored as it was at the backup" |
| 582 | serves /tools/app app-readme-text |
| 583 | link list --check "$restored" > list.out || fail "the restored link is pending after a pass: $(cat list.out)" |
| 584 | link revoke --all > /dev/null |
| 585 | policy > /dev/null |
| 586 | [ "$(bindings)" = 0 ] || fail "revoke --all after a host restore left $(bindings) bindings" |
| 587 | link list --check > /dev/null || fail "after revoke --all a link is pending" |
| 588 | |
| 589 | # Readers sign in, as a reader page's script asks: each request is a |
| 590 | # POST from the origin, of JSON, with X-Valley-Reader: 1. A link the host |
| 591 | # issues redeems once, into a session whose cookie each response renews, |
| 592 | # an archive's too. Of eight concurrent redemptions of one link, one wins. |
| 593 | # A session survives both servers' restarts, ends at logout, and ends at |
| 594 | # the pass that delivers its link's revocation. A second valley-web over |
| 595 | # the same browser state refuses to start. Neither a link's secret nor a |
| 596 | # session's token reaches a log or the browser state. |
| 597 | reader_post() { |
| 598 | curl -sS --max-time 10 -o "$TMPDIR/reply" -D "$TMPDIR/reply.headers" -w '%{http_code}' \ |
| 599 | -H 'Origin: https://example.org' -H 'Content-Type: application/json' -H 'X-Valley-Reader: 1' \ |
| 600 | -H "Cookie: __Host-valley-reader=${3:-}" --data-binary "$2" "http://$web$1" |
| 601 | } |
| 602 | redeem() { reader_post /-/redeem "{\"credential\":\"$1\"}" "${2:-}"; } |
| 603 | token_of() { tr -d '\r' < "$TMPDIR/reply.headers" | sed -n 's/^Set-Cookie: __Host-valley-reader=\([^;]*\);.*/\1/p'; } |
| 604 | as_reader() { |
| 605 | curl -sS --max-time 10 -o "$TMPDIR/body" -D "$TMPDIR/headers" -w '%{http_code}' \ |
| 606 | -H "Cookie: __Host-valley-reader=$1" "http://$web$2" |
| 607 | } |
| 608 | renewed() { |
| 609 | tr -d '\r' < "$TMPDIR/headers" | |
| 610 | grep -qx "Set-Cookie: __Host-valley-reader=$1; Secure; HttpOnly; Path=/; SameSite=Lax; Max-Age=2592000" |
| 611 | } |
| 612 | # redact FILE: the file for a failure's message, with each credential and |
| 613 | # session token in it cut to its credential ID. |
| 614 | redact() { sed -E 's/(lk-[0-9a-f]{16})\.[A-Za-z0-9_-]{43}/\1.<redacted>/g' "$1"; } |
| 615 | # new_link PRINCIPAL: a link issued and delivered; its credential. |
| 616 | new_link() { |
| 617 | local url |
| 618 | url=$(issue_link --principal "$1" 2> /dev/null) |
| 619 | policy > /dev/null |
| 620 | echo "${url#*#}" | tee -a secrets |
| 621 | } |
| 622 | cred=$(new_link alice) |
| 623 | [ "$(redeem "$cred")" = 204 ] || fail "a host-issued link did not redeem: $(cat reply)" |
| 624 | token=$(token_of) |
| 625 | echo "$token" >> secrets |
| 626 | [[ $token =~ ^${cred%%.*}\.[A-Za-z0-9_-]{43}$ ]] || fail "the redemption set no session token: $(redact reply.headers)" |
| 627 | [ "$(redeem "$cred")" = 403 ] && [ "$(cat reply)" = "This link cannot be used. Request another link." ] || |
| 628 | fail "a redeemed link redeemed again: $(cat reply)" |
| 629 | [ "$(as_reader "$token" /tools/app)" = 302 ] && renewed "$token" || fail "a session was not renewed on a redirect" |
| 630 | [ "$(as_reader "$token" /tools/nosuch/)" = 404 ] && renewed "$token" || fail "a session was not renewed on a 404" |
| 631 | [ "$(as_reader "$token" /-/knots)" = 200 ] && grep -qF '<a href="/-/logout">Sign out</a>' body || |
| 632 | fail "a session's knots page does not link to Sign out" |
| 633 | if get /-/knots > /dev/null && grep -qF 'Sign out' body; then fail "anyone's knots page links to Sign out"; fi |
| 634 | archive=$(get /tools/app/source/archive/main.tar.gz) |
| 635 | archive=${archive#302 } |
| 636 | curl -sS --max-time 10 -o anonymous.tar.gz "http://$web$archive" |
| 637 | [ "$(as_reader "$token" "$archive")" = 200 ] && renewed "$token" && cmp -s body anonymous.tar.gz || |
| 638 | fail "a session's download of app's archive differs, or was not renewed" |
| 639 | tr -d '\r' < headers | grep -qx 'Cache-Control: private, no-store' && tr -d '\r' < headers | grep -qx 'Content-Type: application/gzip' && |
| 640 | tr -d '\r' < headers | grep -q '^Content-Disposition: attachment' || fail "a session's archive lost its headers: $(redact headers)" |
| 641 | race=$(new_link alice) |
| 642 | racers=() |
| 643 | for i in $(seq 8); do |
| 644 | curl -sS --max-time 10 -o /dev/null -w '%{http_code}\n' -H 'Origin: https://example.org' \ |
| 645 | -H 'Content-Type: application/json' -H 'X-Valley-Reader: 1' --data-binary "{\"credential\":\"$race\"}" \ |
| 646 | "http://$web/-/redeem" > "race.$i" & |
| 647 | racers+=("$!") |
| 648 | done |
| 649 | wait "${racers[@]}" |
| 650 | [ "$(cat race.* | grep -c '^204$')" = 1 ] && [ "$(cat race.* | grep -c '^403$')" = 7 ] || |
| 651 | fail "eight concurrent redemptions of one link answered $(cat race.* | tr '\n' ' ')" |
| 652 | stop "$web_pid" |
| 653 | stop "$receiver_pid" |
| 654 | receive |
| 655 | serve |
| 656 | [ "$(as_reader "$token" /tools/app)" = 302 ] && renewed "$token" || fail "a session did not survive both servers' restarts" |
| 657 | if valley-web --state edge/store --listen 127.0.0.1:0 --origin https://example.org 2> second.log; then |
| 658 | fail "a second valley-web started over the same browser state" |
| 659 | fi |
| 660 | grep -q "another process owns the browser state" second.log || fail "a second valley-web failed for another reason: $(cat second.log)" |
| 661 | [ "$(reader_post /-/logout '{}' "$token")" = 204 ] && |
| 662 | tr -d '\r' < reply.headers | grep -qx 'Set-Cookie: __Host-valley-reader=; Secure; HttpOnly; Path=/; SameSite=Lax; Max-Age=0' || |
| 663 | fail "logout did not clear the cookie: $(redact reply.headers)" |
| 664 | [ "$(as_reader "$token" /tools/app)" = 302 ] && ! renewed "$token" || fail "a signed-out session is still renewed" |
| 665 | [ "$(reader_post /-/logout '{}' "$token")" = 204 ] || fail "a second logout failed" |
| 666 | revoked=$(new_link alice) |
| 667 | [ "$(redeem "$revoked")" = 204 ] || fail "a third link did not redeem" |
| 668 | revoked_token=$(token_of) |
| 669 | echo "$revoked_token" >> secrets |
| 670 | link revoke "${revoked%%.*}" > /dev/null |
| 671 | policy > /dev/null |
| 672 | [ "$(as_reader "$revoked_token" /tools/app)" = 302 ] && ! renewed "$revoked_token" || |
| 673 | fail "the session of a revoked link is still renewed" |
| 674 | |
| 675 | # A lost browser state is never made again under an authorization that |
| 676 | # binds a link: redemption and requests with a cookie answer 503, and |
| 677 | # anyone is served. The guide's recovery revokes every link, delivers an |
| 678 | # authorization that binds none, which the next request makes the state |
| 679 | # under, and issues new links. |
| 680 | pending=$(new_link alice) |
| 681 | stop "$web_pid" |
| 682 | mv edge/browser/state lost.state |
| 683 | serve |
| 684 | [ "$(redeem "$pending")" = 503 ] || fail "with its browser state lost, a redemption answered $(cat reply)" |
| 685 | [ "$(as_reader "$revoked_token" /tools/app)" = 503 ] || fail "with its browser state lost, a request with a cookie was served" |
| 686 | [ "$(get /tools/app | cut -d' ' -f1)" = 302 ] || fail "with its browser state lost, anyone was not served" |
| 687 | [ ! -e edge/browser/state ] || fail "valley-web made a browser state under an authorization that binds a link" |
| 688 | link revoke --all > /dev/null |
| 689 | policy > /dev/null |
| 690 | get /-/knots > /dev/null |
| 691 | [ "$(cat edge/browser/state)" = the-valley/web-reader-state/v1 ] || fail "no empty browser state was made once no link was bound" |
| 692 | [ "$(redeem "$(new_link alice)")" = 204 ] || fail "a new link did not redeem after the recovery: $(cat reply)" |
| 693 | recovered=$(token_of) |
| 694 | echo "$recovered" >> secrets |
| 695 | # A browser state that cannot be read is never replaced: anyone is served, |
| 696 | # and a request with a cookie answers 503, until the operator delivers an |
| 697 | # authorization that binds no link, removes the state while valley-web is |
| 698 | # stopped, and starts it. |
| 699 | stop "$web_pid" |
| 700 | echo garbage > edge/browser/state |
| 701 | serve |
| 702 | grep -q "the browser state is unavailable" web.log || fail "valley-web did not say its browser state is unavailable: $(cat web.log)" |
| 703 | [ "$(as_reader "$recovered" /tools/app)" = 503 ] || fail "with its browser state unreadable, a request with a cookie was served" |
| 704 | [ "$(get /-/knots | cut -c1-3)" = 200 ] || fail "with its browser state unreadable, anyone was not served" |
| 705 | [ "$(cat edge/browser/state)" = garbage ] || fail "valley-web replaced a browser state it could not read" |
| 706 | link revoke --all > /dev/null |
| 707 | policy > /dev/null |
| 708 | stop "$web_pid" |
| 709 | rm edge/browser/state |
| 710 | serve |
| 711 | [ "$(cat edge/browser/state)" = the-valley/web-reader-state/v1 ] || fail "valley-web did not make the browser state again" |
| 712 | if grep -rqFf secrets --exclude=secrets --exclude=reply.headers --exclude=headers --exclude='race.*' \ |
| 713 | ./*.log web.logs edge/browser links publisher; then |
| 714 | fail "a link's secret or a session's token is in a log, the browser state, the credential file or the publisher's state" |
| 715 | fi |
| 716 | |
| 717 | # A store whose authorization is removed serves no project, though |
| 718 | # valley-web has the export indexed already; once it is back, it serves. |
| 719 | mv edge/v2/authorization authorization.kept |
| 720 | [ "$(get /tools/app)" = "503 " ] || fail "with no authorization valley-web answered /tools/app with $(get /tools/app)" |
| 721 | grep -qF "Nothing published yet" "$TMPDIR/body" || fail "with no authorization the page does not say nothing is published" |
| 722 | if grep -qF app-readme-text "$TMPDIR/body"; then fail "with no authorization valley-web served app's README"; fi |
| 723 | [ "$(get /)" = "503 " ] || fail "with no authorization valley-web answered / with $(get /)" |
| 724 | mv authorization.kept edge/v2/authorization |
| 725 | serves /tools/app app-readme-text |
| 726 | |
| 727 | # Granting site again, and withdrawing app as step 4 left it, serves site |
| 728 | # once more: the receiver's reply says it no longer holds site's |
| 729 | # repository, so the pass sends site's bundle again. |
| 730 | registry "{site: \"${id[site]}\"}" > work/valley/identity/registry.cue |
| 731 | commit valley "withdraw app again" |
| 732 | publish --receiver "$receiver" --receiver-token token > pass.out |
| 733 | grep -q "^valley-web-publish: sent .*site; the receiver activated" pass.out || fail "the pass did not send site's bundle again: $(cat pass.out)" |
| 734 | serves /tools/site site-readme-text |
| 735 | gone /tools/app |
| 736 | |
| 737 | # 5. Both servers restart onto the same content. |
| 738 | stop "$receiver_pid" |
| 739 | stop "$web_pid" |
| 740 | receive |
| 741 | serve |
| 742 | gone /tools/app |
| 743 | serves /tools/site site-readme-text |
| 744 | |
| 745 | # 6. With the receiver stopped, valley-web keeps serving. A pass that |
| 746 | # withdraws site fails because it cannot send its authorization, not |
| 747 | # because it failed earlier or hung until timeout ended it, and changes |
| 748 | # nothing served. Once the receiver is back, the next pass checks the |
| 749 | # policy again, signs a new authorization with a later sequence, and takes |
| 750 | # site off the edge. |
| 751 | stop "$receiver_pid" |
| 752 | serves /tools/site site-readme-text |
| 753 | read_policy site 'operator: true' > work/site/policy/read/read.cue |
| 754 | commit site "withdraw it" |
| 755 | status=0 |
| 756 | publish --receiver "$receiver" --receiver-token token > pass.out 2> pass.err || status=$? |
| 757 | case $status in |
| 758 | 0) fail "a pass to a stopped receiver succeeded" ;; |
| 759 | 124 | 137) fail "a pass to a stopped receiver hung until timeout ended it (status $status)" ;; |
| 760 | esac |
| 761 | grep -q "sending authorization [0-9]* failed [0-9]* times: .*dial tcp ${receiver#http://}: connect: connection refused" pass.err || |
| 762 | fail "a pass to a stopped receiver failed with status $status, but not because it could not connect: $(cat pass.err)" |
| 763 | serves /tools/site site-readme-text |
| 764 | unsent=$(sequence_of publisher/authorization) |
| 765 | receive |
| 766 | publish --receiver "$receiver" --receiver-token token > /dev/null |
| 767 | [ "$(sequence_of edge/v2/authorization)" -gt "$unsent" ] || |
| 768 | fail "the pass after the receiver came back stored authorization $(sequence_of edge/v2/authorization), not one signed after $unsent" |
| 769 | gone /tools/site |
| 770 | gone /tools/homepage |
| 771 | gone /tools/app |
| 772 | |
| 773 | touch "$out" |