| 1 | # The signed fixture valley-web's tests read (web-published in |
| 2 | # nix/packages.nix): the real publisher's output, written with --out, over |
| 3 | # a small valley made with the packaged CLI and real git. Anyone may read |
| 4 | # app. alice alone may read site, and the operator alone docs, so the two |
| 5 | # named readers see different private projects. notes' policy/read lets |
| 6 | # bob alone read it, and no grant names bob, so it has no effective |
| 7 | # reader. app, site and notes are in the group tools, and docs in a group |
| 8 | # of its own, guides. site and docs each have an alias, a former name, a |
| 9 | # knot with a comment, an abandoned knot and a ready change. Three of |
| 10 | # app's knots are each blocked by an open knot, an abandoned knot and a |
| 11 | # missing knot of one other project: site, docs or notes. $out holds the export the |
| 12 | # publisher wrote, as published/, and the export key's verifier line, as |
| 13 | # verifier. |
| 14 | set -euo pipefail |
| 15 | |
| 16 | export HOME="$TMPDIR/home" |
| 17 | export XDG_CACHE_HOME="$TMPDIR/cache" |
| 18 | export XDG_STATE_HOME="$TMPDIR/xdg-state" |
| 19 | export GIT_CONFIG_NOSYSTEM=1 |
| 20 | export GIT_CONFIG_GLOBAL="$TMPDIR/gitconfig" |
| 21 | printf '[user]\n\tname = operator\n\temail = operator@example.org\n[init]\n\tdefaultBranch = main\n' > "$GIT_CONFIG_GLOBAL" |
| 22 | cd "$TMPDIR" |
| 23 | |
| 24 | commit() { |
| 25 | git -C "work/$1" add --all |
| 26 | git -C "work/$1" commit --quiet -m "$1: $2" |
| 27 | git -C "work/$1" push --quiet origin main |
| 28 | } |
| 29 | |
| 30 | declare -A id=( |
| 31 | [valley]=f83927d5a4ed068cdd02a8cdaa09f26d |
| 32 | [app]=9da6809f038df92138c131cd16bed76d |
| 33 | [site]=273d5668702918ea7ae079de374db96b |
| 34 | [docs]=5b1e0c7a9f3d2e4c6a8b0d1f3e5c7a92 |
| 35 | [notes]=8e3b6f1d2a4c7e9b0d5f3a1c6e8b2d47 |
| 36 | ) |
| 37 | declare -A readers=( |
| 38 | [valley]='operator: true' |
| 39 | [app]='anyone: true' |
| 40 | [site]='alice: true' |
| 41 | [docs]='operator: true' |
| 42 | [notes]='bob: true' |
| 43 | ) |
| 44 | read_policy() { |
| 45 | printf 'package read\n\nproject: "%s"\nidentity: "%s"\nreaders: {%s}\n' "$1" "${id[$1]}" "${readers[$1]}" |
| 46 | } |
| 47 | |
| 48 | for name in valley app site docs notes; do |
| 49 | git init --quiet --bare "srv/$name.git" |
| 50 | git init --quiet "work/$name" |
| 51 | git -C "work/$name" remote add origin "$TMPDIR/srv/$name.git" |
| 52 | git -C "work/$name" config valley.principal operator |
| 53 | mkdir -p "work/$name/policy/read" |
| 54 | read_policy "$name" > "work/$name/policy/read/read.cue" |
| 55 | done |
| 56 | |
| 57 | # The instance: the operator governs the registry, and the operator and |
| 58 | # alice, who holds no key, may read every project at the edge. Anyone may |
| 59 | # read app alone. |
| 60 | mkdir -p work/valley/policy/instance work/valley/identity |
| 61 | echo 'package verification' > work/valley/policy/instance/floor.cue |
| 62 | cat > work/valley/identity/registry.cue << EOF |
| 63 | package identity |
| 64 | |
| 65 | boundaries: { |
| 66 | registry: kind: "registry" |
| 67 | web: {kind: "edge-read", destination: "example.org"} |
| 68 | } |
| 69 | genesis: "operator" |
| 70 | principals: operator: { |
| 71 | kind: "human" |
| 72 | keys: [{class: "ssh-ed25519", bound: "hardware", public: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyForARejectedFixtureAAAAAAAAAAA"}] |
| 73 | grants: { |
| 74 | govern: boundary: "registry" |
| 75 | read: {boundary: "web", projects: "all"} |
| 76 | } |
| 77 | } |
| 78 | principals: alice: {kind: "human", keys: [], grants: read: {boundary: "web", projects: "all"}} |
| 79 | anyone: grants: read: {boundary: "web", projects: {app: "${id[app]}"}} |
| 80 | EOF |
| 81 | commit valley "the instance" |
| 82 | projects=$(printf 'app\ndocs\nnotes\nsite\nvalley\n' | git -C srv/valley.git hash-object -w --stdin) |
| 83 | git -C srv/valley.git update-ref refs/the-valley/projects "$projects" |
| 84 | |
| 85 | for name in app site docs notes; do |
| 86 | echo "$TMPDIR/srv/valley.git" > "work/$name/policy/valley" |
| 87 | printf '# %s\n\n%s-readme-text\n' "$name" "$name" > "work/$name/README.md" |
| 88 | commit "$name" "the first commit" |
| 89 | done |
| 90 | # Each private project's knots, comment and ready change carry its name, |
| 91 | # so a page that shows any of them to another reader is caught. |
| 92 | declare -A waits=([site]=first [docs]=second [notes]=third) |
| 93 | declare -A change=([site]=ssssssssssssssssssssssssssssssss [docs]=tttttttttttttttttttttttttttttttt) |
| 94 | for name in site docs notes; do |
| 95 | open=$(cd "work/$name" && valley knot new outcome "$name-knot-text" --json | jq -r .knot.id) |
| 96 | ended=$(cd "work/$name" && valley knot new outcome "$name-abandoned-text" --json | jq -r .knot.id) |
| 97 | (cd "work/$name" && valley knot set "$ended" status=abandoned > /dev/null) |
| 98 | (cd "work/$name" && valley knot comment "$open" -m "$name-comment-text" > /dev/null) |
| 99 | (cd work/app && valley knot new outcome "Waits on the ${waits[$name]} private project" \ |
| 100 | --blocked-by "$name:$open" --blocked-by "$name:$ended" --blocked-by "$name:oc-0000000" > /dev/null) |
| 101 | done |
| 102 | for name in site docs; do |
| 103 | git -C "work/$name" checkout --quiet -b "$name-change-handle" |
| 104 | echo "$name-change-text" > "work/$name/change.md" |
| 105 | git -C "work/$name" add --all |
| 106 | git -C "work/$name" commit --quiet -m "$name-change-subject" |
| 107 | git -C "work/$name" push --quiet origin "$name-change-handle" |
| 108 | (cd "work/$name" && valley ready --change "${change[$name]}" "$name-change-handle" > /dev/null) |
| 109 | git -C "work/$name" checkout --quiet main |
| 110 | done |
| 111 | |
| 112 | cat > host.cue << 'EOF' |
| 113 | package valley |
| 114 | |
| 115 | groups: core: name: "tools" |
| 116 | groups: library: name: "guides" |
| 117 | projects: app: group: "core" |
| 118 | projects: site: {group: "core", aliases: ["portal"], formerNames: ["homepage"]} |
| 119 | projects: docs: {group: "library", aliases: ["handbook"], formerNames: ["manual"]} |
| 120 | projects: notes: group: "core" |
| 121 | projects: valley: {} |
| 122 | EOF |
| 123 | cue export --out json "$schema" host.cue > host.json |
| 124 | echo '{"operator": "operator"}' > principals.json |
| 125 | |
| 126 | mkdir -p "$out" |
| 127 | valley-web-publish --instance-repo "$TMPDIR/srv/valley.git" --instance valley-host --destination example.org \ |
| 128 | --host "$TMPDIR/host.json" --state "$TMPDIR/publisher" --principals "$TMPDIR/principals.json" --out "$out/published" |
| 129 | cp publisher/verifier "$out/verifier" |