test(cmd): build the tests that need no block on a block-free base (S04-A required encryption block plan: 10/16)

Summary

Six cmd/artifact-registry tests check what happens when a config has no encryption block. They read testdata/valid_config.yaml as is. That works only because the shared configs have no block today. Step 11 gives them one.

Two helpers also append a block to validBaseConfigYAML. Once the base has its own block, the config has two. Two blocks that both set local fail to load.

This MR builds all of them on a block-free base:

  • wire_iam_test.go gets two block-free bases. blockFreeEnforcingBaseConfigYAML holds the old enforcingBaseConfigYAML text, and blockFreeValidBaseConfigYAML adds the authorization.unenforced opt-in to it. enforcingBaseConfigYAML and validBaseConfigYAML are built on them, so a block added to a base cannot reach its twin.
  • The six tests load blockFreeValidBaseConfigYAML from a temp file. Their assertions do not change.
  • writeEncryptionConfigWithTTL and writeWarnLevelEncryptionConfig append their block to blockFreeValidBaseConfigYAML.

The bases have no block yet, so today the twins equal them. No production code changes. This is Step 10 of the S04-A required encryption block plan.

Plan and spec amendments

Review replaced the plan's stripping helper with composition (thread). 3ab55ab0bc corrects the plan at every site that named the stripper:

  • Approach: "Build "no block" at test time" becomes "Compose "no block" from a block-free base", with composition as the reason.
  • Step 10's title, in the graph, the dependency table and the Status table: "on a stripped base" becomes "on a block-free base".
  • Step 10's Scope, Files and Shared seams. The seams now name the overlap with !2969 (merged).
  • Step 11's Depends on, Scope and Files: the bases get the block, and their twins do not.
  • Step 12: "Six tests run on a stripped config" becomes "on a block-free base".
  • Naming Conventions: the two block-free bases replace stripEncryptionBlock and writeConfigWithoutEncryption.

No spec clause changes.

Governing ADRs

None. ./scripts/adr-freshness.sh reports one upstream commit not yet synced, to ADR-003 (the upload-session cap). It does not touch this change. No ADR decides how cmd tests build their configs.

Testing

Today a block-free base and its base are the same text, so the six tests cannot tell them apart. What makes a wrong twin visible:

  • With an encryption block added to blockFreeValidBaseConfigYAML, all six tests fail. So do three users of the append helpers: TestWireEncryption_PresentBlockActivates, TestRunOperator_StoreCooldownIgnoresTheLoadedTTL and TestRunOperator_LoggerHonorsConfiguredLevel.
  • Step 11 rehearsal: with a block appended to enforcingBaseConfigYAML and validBaseConfigYAML, and added right after version in testdata/valid_config.yaml, the six tests, those three, and every TestRunOperator_, TestReEncryptCommand_ and TestRetireKeyVersionCommand_ test pass. Then, one at a time:
    • writeEncryptionConfigWithTTL on validBaseConfigYAML fails TestWireEncryption_PresentBlockActivates and TestRunOperator_StoreCooldownIgnoresTheLoadedTTL.
    • writeWarnLevelEncryptionConfig on validBaseConfigYAML fails TestRunOperator_LoggerHonorsConfiguredLevel.
    • TestWiring_CryptoCounterRegisteredWithoutEncryption on validConfigFixture fails.

The six tests used to read the fixture file. They now read the constant, which has the same keys and values.

Checked at 3ab55ab0bc: go test ./cmd/artifact-registry/ passes, and the touched tests pass under -race. The mutations above ran on the code of b562005360, which 3ab55ab0bc leaves unchanged.

No production code changes, so no e2e row or user doc is affected.

Merge order

  • This step depends on nothing. Step 11 opens after it merges.
  • !2969 (merged) rewrites enforcingBaseConfigYAML and validBaseConfigYAML in wire_iam_test.go, the two constants this MR splits. So the two MRs conflict in that file. Either can merge first. The second rebases and keeps both sides: the block-free twins take !2969 (merged)'s text, and the bases stay built on them. The plan's Rebasing over S34 sets that rule.
  • !2969 (merged) also edits wiring_metrics_test.go, in a different test (TestWiring_BodySizeCounterAccrues). That file merges cleanly in either order.

Spec coverage

Spec: S04-A. This step adds no product assertion. It only changes the config some tests read.

Rule Tests
No block: startup fails, naming it (AC-28, E-1) Step 12 asserts it. Until then the six tests check today's no-block behavior on a block-free base
The block-free base carries no block The six tests: a block in blockFreeValidBaseConfigYAML fails all of them
Missing or malformed root key (E-2 to E-4) Existing TestWireEncryption_SecretReadFailureFailsBoot and TestWireEncryption_MalformedSecretFailsBoot, unchanged

Every other acceptance criterion, error case and security consideration is outside this step. AC-25 (-race) holds for the touched tests.

Closes https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1486

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading