Skip to content

test(localca): add unit tests#74

Open
jbpratt wants to merge 1 commit into
agent-substrate:mainfrom
jbpratt:tests/unit-localca
Open

test(localca): add unit tests#74
jbpratt wants to merge 1 commit into
agent-substrate:mainfrom
jbpratt:tests/unit-localca

Conversation

@jbpratt
Copy link
Copy Markdown

@jbpratt jbpratt commented May 24, 2026

add GenerateED25519CA, Marshal/Unmarshal round trip, unmarshaling errors
and intermediate cert unmarshaling unit tests

Signed-off-by: Brady Pratt bpratt@redhat.com
Assisted by Claude 🤖

  • Tests pass
  • Appropriate changes to documentation are included in the PR

add GenerateED25519CA, Marshal/Unmarshal round trip, unmarshaling errors
and intermediate cert unmarshaling unit tests

Signed-off-by: Brady Pratt <bpratt@redhat.com>
@ahmedtd Taahir Ahmed (ahmedtd) self-requested a review May 26, 2026 23:22
@BenTheElder Benjamin Elder (BenTheElder) added the area/tests Enhancing / fixing test coverage. label May 28, 2026
@a4-a4s1
Copy link
Copy Markdown

a4-a4s1 Bot commented May 28, 2026

Skim — solid coverage. The sign-with-deserialized-key check in TestMarshalUnmarshalRoundTrip (verifying the unmarshaled private key matches the cert's public key, not just byte-equality) is the test I'd most want here.

One observation worth raising before this lands:

  • Round-trip tests don't pin the wire format. The package doc says state "can be stored in a local file or Kubernetes secret" — i.e. the JSON written by version-A is read back by version-B (possibly weeks later, after a binary upgrade). The current tests prove "in-process Marshal → Unmarshal returns equal" but a rename of SigningKeyPKCS8PKCS8Key (or any serializedCA field) silently round-trips clean while breaking every persisted CA. PKCS#8 + DER are version-stable, but the JSON envelope around them is the load-bearing contract.
  • Cheapest fix: one extra test that Marshals a Pool built from a fixture PKCS#8 + DER (checked-in bytes, no rand.Reader) and asserts the resulting JSON contains the four expected top-level CA keys (ID, SigningKeyPKCS8, RootCertificateDER, IntermediateCertificatesDER). Doesn't have to be a byte-equal golden — a json.Unmarshal into map[string]json.RawMessage + key-set assertion is enough to catch field renames.
  • Optional, but related: Marshal(&Pool{CAs: nil}) currently produces {"CAs":null}; Unmarshal of that returns Pool{CAs: nil} (test passes implicitly, but neither end is exercised). A 2-line empty-pool round-trip would lock that edge if it matters for the "empty K8s secret" startup case.

Q: is wire-format stability a concern for the local-file/K8s-secret use case (i.e. is there a sustained tail of persisted CAs you need to keep readable across binary upgrades), or is the expectation that CA state is short-lived and re-generated on every fresh install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tests Enhancing / fixing test coverage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants