host tests: one RSA key for every handoverRecoveryIdentity
The helper generated a fresh 2048-bit RSA key on each of its 38 call sites, several inside 24- and 27-way subtest loops: about 17 s of CPU in the host package. The process now makes one key. Each provider still carries its own identity document, signature and certificate map, and no test verifies one provider's evidence against another's certificates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+11
−1
internal/host/claimhandover_recovery_test.go+11 −1
diff --git a/internal/host/claimhandover_recovery_test.go b/internal/host/claimhandover_recovery_test.go| index 2559e339d..2a5064976 100644 |
| --- a/internal/host/claimhandover_recovery_test.go |
| +++ b/internal/host/claimhandover_recovery_test.go |
| @@ -17,6 +17,7 @@ import ( |
| "os" |
| "path/filepath" |
| "strings" |
| + "sync" |
| "testing" |
| "time" |
| @@ -40,9 +41,18 @@ func (e handoverRecoveryEvidence) Load(context.Context, string) ([]byte, error) |
| return e, nil |
| } |
| +// handoverRecoveryKey is the RSA key every test identity signs its document |
| +// with. Generating a 2048-bit key costs tens of milliseconds and this helper |
| +// has dozens of callers, many in loops, so the process makes one. Each |
| +// provider still carries its own document, signature and certificate map, and |
| +// no test verifies one provider's evidence against another's certificates. |
| +var handoverRecoveryKey = sync.OnceValues(func() (*rsa.PrivateKey, error) { |
| + return rsa.GenerateKey(rand.Reader, 2048) |
| +}) |
| + |
| func handoverRecoveryIdentity(t *testing.T, actor hostbox.Actor) hostbox.IdentityProvider { |
| t.Helper() |
| - key, err := rsa.GenerateKey(rand.Reader, 2048) |
| + key, err := handoverRecoveryKey() |
| if err != nil { |
| t.Fatal(err) |
| } |