team-keygen: a two-key manifest test (N1); name ALTA_ORIGIN and HOME_DIRECTORY_ORIGIN (N2)
Fable #102 notes. The two-assertion-key test boots the credential under each key and refuses a resolve key equal to the later-sorted one on the credential role itself, which kills the 'first key only' mutant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+50
−2
internal/home/team_keygen.go+4 −2internal/home/team_keygen_test.go+46 −0
CI failed — run details
Intent
diff --git a/internal/home/team_keygen.go b/internal/home/team_keygen.go| index eda480a..a8eb5c4 100644 |
| --- a/internal/home/team_keygen.go |
| +++ b/internal/home/team_keygen.go |
| @@ -621,8 +621,10 @@ func writeTeamEnv(w io.Writer, env teamEnv, origins Origins, keyID, subject stri |
| " carlos env set --account oficina --app " + app["directory"] + " <these lines>", |
| }, |
| teamAltaEnv: { |
| - "Alta, to match (with ALTA_HOME_CONSUMER_ID=alta and alta keygen's own lines):", |
| - " carlos env set --account oficina --app alta <these lines>", |
| + "Alta, to match, in one call with ALTA_HOME_CONSUMER_ID=alta, ALTA_ORIGIN (equal to the", |
| + "\"alta\" entry of the credential's HOME_CONSUMERS) and HOME_DIRECTORY_ORIGIN=" + origins.Directory + ",", |
| + "beside alta keygen's own lines:", |
| + " carlos env set --account oficina --app alta <these lines> ALTA_HOME_CONSUMER_ID=alta ALTA_ORIGIN=… HOME_DIRECTORY_ORIGIN=" + origins.Directory, |
| }, |
| } |
| var b strings.Builder |
diff --git a/internal/home/team_keygen_test.go b/internal/home/team_keygen_test.go| index 5f1a2e8..87016c2 100644 |
| --- a/internal/home/team_keygen_test.go |
| +++ b/internal/home/team_keygen_test.go |
| @@ -765,6 +765,52 @@ func TestTeamKeygenCheckLeavesTheEnvironmentAlone(t *testing.T) { |
| } |
| } |
| +// A manifest mid-rotation holds two assertion keys, and the credential may |
| +// sign with either: the set must boot the credential under each, and a key |
| +// equal to either one is refused on the credential role itself (the |
| +// per-key loop in checkTeamRole), not left for the directory to catch. |
| +func TestTeamKeygenTwoAssertionKeys(t *testing.T) { |
| + w := newTeamWorld(t) |
| + second, err := family.Generate() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + manifest, _ := stdjson.Marshal(map[string]string{ |
| + hexID(w.assertionKey): base64.StdEncoding.EncodeToString(w.assertionKey.SignPub()), |
| + hexID(second): base64.StdEncoding.EncodeToString(second.SignPub()), |
| + }) |
| + two := w |
| + two.manifest = string(manifest) |
| + if two.assertion, err = parseTeamAssertionKeys(two.manifest, Origins{Origin, directoryOrigin}); err != nil || len(two.assertion) != 2 { |
| + t.Fatal("two-key manifest", err) |
| + } |
| + env := two.generate(t, newAltaKeygen(t).text) |
| + two.boot(t, "directory", env) |
| + for _, signer := range []*family.Keypair{w.assertionKey, second} { |
| + as := two |
| + as.assertionPrivate, as.assertionKey = encodedKeypair(t, signer), signer |
| + as.boot(t, "credential", env) |
| + } |
| + // The resolve key equal to each assertion key in turn, the later-sorted |
| + // one included: the credential role refuses it, by its own loop. |
| + for _, k := range []*family.Keypair{w.assertionKey, second} { |
| + e := cloneTeamEnv(env) |
| + e[teamCredentialSecrets]["HOME_RESOLVE_KEY"] = encodedKeypair(t, k) |
| + e[teamDirectoryEnv]["HOME_RESOLVE_PUBLIC_KEY"] = rawURLPub(k) |
| + err := checkTeamEnv(e, Origins{Origin, directoryOrigin}, two.assertion) |
| + if err == nil || !strings.Contains(err.Error(), "credential role: Home refuses the member-resolution key") { |
| + t.Errorf("resolve key = assertion key %s…: %v", hexID(k)[:12], err) |
| + } |
| + } |
| + // And generation refuses a fresh key equal to the second assertion key. |
| + ks := ks(t, newAltaKeygen(t).text) |
| + name := "assertion key " + hexID(second)[:12] + "…" |
| + _, err = generateTeamEnv(ks, Origins{Origin, directoryOrigin}, teamSubject, two.assertion, teamKeySource{keypair: fixedKeys(second), random: defaultTeamKeySource().random}) |
| + if !namesPair(err, "the owner-seed key", name) { |
| + t.Error("owner-seed = second assertion key:", err) |
| + } |
| +} |
| + |
| // The origins flags reach every check: a preview pair generates and boots. |
| func TestTeamKeygenPreviewOrigins(t *testing.T) { |
| w := newTeamWorld(t) |