Repository navigation
Conversation
Add property-based tests for CertPool using hegel-go: a filter/dedup/ ordering oracle for bundles of generated certificates interleaved with junk text, a strictness property rejecting non-certificate, headered and unparseable PEM blocks, and a never-panic/fixed-point property over arbitrary bytes. The replaced table rows all instantiated these rules; the generated inputs cover the same fixtures (headered certificate, corrupt DER, private key, expired and non-CA certificates) and many more combinations. The properties also document that AddCertsFromPEM does not return an error for a bundle containing no certificates, despite its doc comment claiming otherwise. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Add a property test that encodes any non-empty subset of generated certificates with any password/profile configuration and decodes the result with the same library: JKS entries must match the pool exactly (alias, DER content, NotBefore creation time) and PKCS#12 trust stores must decode to the pool's certificates in order. The property also asserts byte-for-byte determinism for JKS and passwordless PKCS#12; password-protected PKCS#12 uses random salts, so no assertion there. This replaces Test_Encoder_Deterministic (six example rows) and Test_encodeJKSAliases (subsumed by the alias round trip). Test_certAlias stays as an alias-stability pin, and the Java interop tests stay as external-tool checks. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Add properties for the bundle status helpers: setBundleCondition must preserve LastTransitionTime exactly when an existing condition has the same type and status, replace in place or append in the patch list while leaving other entries untouched, and leave a state bundleHasCondition can find; bundleHasCondition must match on type, status, reason, message and observed generation, ignoring LastTransitionTime; and setBundleStatusDefaultCAVersion must leave the status equal to the required ID and report whether that changed anything. The replaced tables in util_test.go instantiated exactly these rules. Condition types are drawn unique per list, matching the API's listType=map / listMapKey=type markers on the conditions field. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Not for merge as-is — this is the trust-manager instalment of the property-based-testing trial previously run on cert-manager (cert-manager/cert-manager#9149, which describes how candidates are chosen) and approver-policy (cert-manager/approver-policy#989). If maintainers want any of it, it should be split per package, and the new test-only dependency (hegel-go, a Hypothesis-style property-testing library with a native shrinking engine, pulled in via
hegel.dev/go/hegel+purego) needs discussing first.What's here
Three commits, each replacing example/table tests with properties where the rows merely instantiate a recomputable rule, and keeping the tests that pin external bytes or interop:
pkg/utilCertPool — the trust boundary that keeps private keys and stray material out of distributed bundles.PEM()a byte-identical fixed point andPEMSplit()consistent with it.CERTIFICATEblock, any PEM headers, or unparseable DER anywhere in the bundle rejects the whole bundle.pem_test.goandcert_pool_test.go; the generated adversarial blocks cover the old fixtures (headered cert, corrupt base64, private key) and more.pkg/bundle/internal/truststore— encode→decode oracle: any non-empty subset of certificates, any password/profile; JKS decoded with keystore-go must contain exactly one entry per certificate with thecertAliasalias, the DER content and theNotBeforecreation time; PKCS#12 decoded withpkcs12.DecodeTrustStoremust return the pool in order. Determinism asserted byte-for-byte for JKS and passwordless PKCS#12 (password-protected PKCS#12 uses random salts). ReplacesTest_Encoder_DeterministicandTest_encodeJKSAliases; keepsTest_certAlias(stability pin) and the Java interop tests.pkg/bundlecondition helpers —setBundleConditionpreservesLastTransitionTimeexactly when type+status are unchanged, replaces in place or appends, and leaves other entries untouched;bundleHasConditionmatches on all fields exceptLastTransitionTime;setBundleStatusDefaultCAVersionalways leaves the status equal to the required ID and returns whether that changed. Replaces the three tables inutil_test.go.Not attempted: the v1alpha1↔v1alpha2 conversion round trip —
TestFuzzyConversionalready covers that law with apimachinery'sFuzzTestFuncand careful custom fuzzers, which is exactly the property-shaped prior art this trial looks for. Webhook validation was skipped for the same reason as in approver-policy (the error list is the spec; a property would restate it).What it found
No behavioural bugs — but one stale doc comment with a history:
AddCertsFromPEM's doc comment still says "if the input PEM bundle contains no non-expired certificates, an error is returned". That was true when 1bbbe3b added theokflag, but CertPool should not error when input adds no certificates #624 (3870706, "CertPool should not error when input adds no certificates") deliberately removed the error and left the sentence behind. The property documents the actual behaviour; the comment deserves a one-line follow-up fix.The strictness property hammered the private-key/header rejection path with ~2,000 adversarial bundles per run and it held throughout — worth having as a permanent regression net given what leaks through that boundary would mean.
Coverage (main → branch,
go test -coverprofile)pkg/utilpkg/bundle/internal/truststorepkg/bundleZero previously covered blocks lost; the gains are the nil-input branch, all of
PEMSplit,setBundleCondition's replace-in-place branch and a PKCS#12 profile case.Note:
make test-unitcurrently fails on my machine on cleanmainwith a toolchain mismatch (compile: version "go1.26.0" does not match go tool version "go1.25.5") — unrelated to this branch; all suites pass withgo test ./cmd/... ./pkg/..., thetestnegativeserialonvariant and the trust-packages module directly.with claude fable-5