Repository navigation
Conversation
…n tests An application whose CI has no CipherStash credentials could not run any test that reaches an encrypting write path: encrypt.Cipher is concrete, Decrypter takes internal types, and the only credential-free client was NewDeterministicClient in export_test.go, out of reach outside the module (#1696). encrypttest.NewClient(t) returns a real *encrypt.Client over the deterministic-kms test build of the guest, so generated code, keysets, Scope, Bind and Decrypter all work unchanged. stack-kms's DeterministicSource derives each data key from a seed and the descriptor and refuses a tag from another descriptor as ZeroKMS's 403, so a wrong context still fails with ErrForbidden and a foreign keyset with ErrForeignKeyset. Every keyset exists, by name or id, with nothing to provision. The default seed is fixed, so fixture loaders and readers in separate test processes share keys; WithSeed chooses another. The constructor needs encrypt's unexported instance, and encrypttest imports encrypt, so encrypt registers it with internal/testclient on init, following the eqlguest pattern. No public function builds a client over a caller-chosen guest, and the production guests refuse a bare seed as malformed config (TestAProductionGuestRefusesASeed). NewClient picks the EQL test build when package eql is linked, as embeddedGuest does, and fails the test outside a test binary (testing.Testing). The test builds move from encrypt/testdata to encrypt/encrypttest/wasm, one location for the package's embed and the hermetic tests, and the Go release now builds, hashes and commits them with the production guests.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
Mutation testing (cargo-mutants,
|
Code review (
|
- WithSeed's doc no longer promises isolation between tests: search terms depend on the keyset alone, so tests that share a table isolate by keyset name. The README says the same. - One build selector. encrypt.selectBuild picks the production build in embeddedGuest and the test build in the encrypttest constructor, which now takes both test builds, so the two cannot drift apart. - Each test build is read once (sync.OnceValues): embed.FS copies on every read, and an application may call NewClient in every test. - The NewClient tests move to encrypttest/internal/witheql, beside withouteql. encrypttest's own test binary no longer links package eql, so its Contexts tests run against the plain guest again, unchanged. - TestAProductionGuestRefusesASeed checks each production build in its own subtest, so an absent EQL build is a visible skip. - go-binding-test.sh checks for the two test builds up front and names their tasks, since encrypttest's tests fail without them; the go:test description lists all five builds. - The release hashes the production guests before the test builds run and checks them after, so a task that copied a seeded build over a production guest stops the release. - go.mod's pgx comment names the new PostgreSQL test.
Review fixes (
|
Summary
A Go application can now test its encrypted read and write paths in CI with no CipherStash credentials and no network.
encrypttest.NewClient(t)returns a real*encrypt.Client. It runs the same engine and the same generated code as production. Only the key source differs: each key comes from a seed, not from ZeroKMS (CipherStash's key service). EQL v4 columns in PostgreSQL accept what it writes, and its search terms match. (EQL is the SQL extension that stores and queries encrypted values.)Before this, the only client that needed no credentials was a helper in the SDK's own
_test.gofiles, so no application could reach it.Changes
New API, in the existing
encrypt/encrypttestpackageNewClient(tb, ...ClientOption) *encrypt.Client. It closes the client when the test ends. It fails the test, and never skips it, when the client cannot start. It also fails outside a test binary (testing.Testing()).WithSeed([32]byte). Every client with the default seed opens what another sealed, in any process, so a test that loads fixtures and a test that reads them share keys. The default seed never changes.encrypt/eql, asencrypt.NewClientpicks the production build.How it reaches the engine
encrypt/testclient.goandencrypt/internal/testclient.encrypttestimportsencrypt, soencryptregisters the constructor in an internal package on init, the same pattern aseqlguest. The constructor picks the test build withencrypt.selectBuild, the same functionembeddedGuestuses for the production builds. No public function builds a client over a guest the caller chooses. The constructor already existed asdeterministicClientinexport_test.goand has moved.DeterministicSource. Each key comes from the seed and the value's context. A key asked for under another context is refused with ZeroKMS's 403. So a wrong context still fails withErrForbidden, and another keyset's value withErrForeignKeyset.Where the test builds live, and the release
encrypt/testdata/toencrypt/encrypttest/wasm/. The package embeds them from there, and the SDK's own tests read them from there. I updated every path: the mise tasks,tests-golang.yml, the conformance scripts and their tests,.gitignore, and two Go test helpers.release-golang.ymladds both test builds toGUESTS. It builds them before the hash, so the tag commits them with the three production guests andverifychecks them in the module zip. Before running them, it hashes the production guests, and checks those hashes again afterwards, so a test build can never be tagged as a production guest. The two test builds add about 5.8 MB (2.3 MB and 3.5 MB) to every module download.go:test:postgresalso runsTestEncryptTestClientInPostgres.scripts/go-binding-test.shchecks for the two test builds up front, becauseencrypttest's tests fail without them.Docs
encrypt/README.mdhas a new "Testing your application" section. TheCHANGELOG.mdentry is under Unreleased.encrypttest, which only_test.gofiles should import. These are inCargo.toml,deterministic.rs,eql/guest.goand the wasm READMEs.AGENTS.md(the Go module entry and the guest count) andSECURITY.md. SECURITY.md now says the test builds' keys are not secret by design, and that a production client loading a test build is in scope.Verification
scripts/go-binding-test.sh languages/golang: gofmt, vet and the full module test suite against freshly built guests. Passed, all 15 packages, with no skips.golangci-lint run ./...(2.14.0): 0 issues.TextEqvalue and its query term match;KeysetName("default")is the default keyset;ErrForeignKeyset;ErrForbidden, and a context field mismatch withErrContextMismatch;ErrForbidden;eqlis not linked (encrypttest/internal/withouteql). The tests that linkeqllive inencrypttest/internal/witheql, soencrypttest's own tests keep a binary without it;TestAProductionGuestRefusesASeed).TestEncryptTestClientInPostgresruns the issue's five steps: create the client, encrypt, insert into aneql_v4_text_eqcolumn, query it witheql_v4.query_text_eq, and decrypt. It passed against a throwaway PostgreSQL 17 with the rc.5eql-v4-install.sql(eql_v4.version()=go-0.1.0-rc.5).TestEQLTypesRoundTripAndQueryInPostgresandTestQueriesRunAgainstPostgrespassed in the same run.go-release-artifact, the exchange and lifecycle conformance tests,crates-ci,go-release-version,workflow-publish-permissions,lint-no-workflow-cachingandffi-binding-step-orderpass.test:scriptsrun had 3 files that would not load:bench-index-expressions,check-auth-npm-changesetandmigration-fixture-client. They need packages that were missing from the localnode_modulesI ran with, and this PR does not touch them.Related
Closes #1696
Review notes
Base is
next, notmain.v0.1.0-rc.5was cut fromnext, and the EQL v4 support the issue asks for is only onnext.Where to look first:
encrypt/encrypttest/client.go, thenencrypt/testclient.goandencrypt/internal/testclient.What a test cannot see:
ErrNotFoundfor a missing keyset, orErrForbiddenfor a keyset with no grant;ErrUnauthorized.NewClient's doc comment lists these.Open decision: module size. The test builds add about 5.8 MB to every
go get, including for programs that never importencrypttest. A nestedencrypttestmodule would avoid that, at the cost of a second tag in the release. See the review reply.Deferred: making search terms depend on the seed.
DeterministicSourcetakes its index key fromFakeDataKeySource, which uses only the keyset id. Changing that would move terms pinned by existing tests and fixtures. The doc comment says terms do not depend on the seed.Import guard: Go cannot stop a non-test file importing
encrypttest. Thetesting.Testing()check makes that fail at the firstNewClientcall, not silently.