Repository navigation
fix: isolate tests from the user's Helm config, harden JAR download - #464
Conversation
The Java and Go tests wrote registry logins, repository indexes and lock files into the developer's own Helm config, cache and temp directory, and the remote native JAR download could hang forever or cache a truncated JAR. - Java tests: Surefire points the Helm and Docker homes at target/helm-home, drops the HELM_* overrides, and seeds the registry configs so logins never reach an OS credential store - Go tests: TestMain cleanup actually runs, repositories.yaml files live in t.TempDir() (test.RepositoryConfig), registry configs are seeded - RepoServerStop/StopAll now shut the test OCI servers down - RemoteJarLoader: connect/read timeouts, rejects downloads shorter than their Content-Length, downloads to a .part file and moves it into place - Go repo-server fixtures without goroutines or sleeps, bounded HTTP clients in the fixture tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Nuri <marc@marcnuri.com>
Follow-ups from the review of the test isolation change: - RemoteJarLoader opens the downloaded .part file as a ZIP before moving it into place, so a truncated chunked or close-delimited response (no Content-Length) is no longer cached as complete - RemoteJarLoaderTest covers that, the cache-hit path, and keeping the cached JAR with forceUpdate when the download fails - the excluded HELM_* variables (Surefire and the Go TestMain) are every one Helm reads that redirects files or changes behavior, and the two lists match - the registry config seeds are test resources, so IDE runs on a clean target/ get them too (no extra Maven execution) - SetupIsolatedEnv fails when it can't write the seeds Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Nuri <marc@marcnuri.com>
manusa
left a comment
There was a problem hiding this comment.
Review of #464
Verdict: approve. It's posted as a comment only because this is my own PR. Two review rounds found no Critical or Important issues. Round 1's minors 1 to 5 and the description update are addressed in c4c06dc. The rest are follow-ups, listed below.
CI on 7970ee6
All three jobs passed:
- Linux (Java 8): the Go
nativeandinternal/helmsuites, envtest included. Java ran 166 tests with 0 failures, including:NativeLibraryTest4/4, with real downloads from Maven Central;HelmKubernetesTest55/55 on KinD with the isolatedDOCKER_CONFIG.
- Windows: 112 tests, 0 failures.
NativeLibraryTest, plus the Registry, Push and Show tests with the seeded configs. - macOS: green.
CI runs again on c4c06dc, which changes RemoteJarLoader and the seed location.
Isolation
- Helm paths: every Helm path the tests use resolves through
helmpath/cli.New()in Helm v3.22.1.registry.NewClientdefaults tohelmpath.ConfigPath("registry/config.json"), so excludingHELM_REGISTRY_CONFIGis purely defensive. - Excluded variables: the 19 excluded
HELM_*variables are complete and match between Surefire andenv.go:- every variable in
pkg/cli/environment.go; HELM_DRIVER;HELM_DRIVER_SQL_CONNECTION_STRING.
- every variable in
- Credential-store seed: the placeholder
authsentry is what makes oras-go v2.6.2'sIsAuthConfiguredskip native credential-store detection. To check it, a fakedocker-credential-secretservicewas put onPATH, after aclean:- with the seeds, it was never called;
- without them, it was called on every login, and
credsStorewas written.
- Seed location: the seeds now come from test resources, so IDE runs get them too. The large repository indexes stay in
target/helm-home, outsidetest-classes. - OCI servers:
Registry.Shutdownhas no race with a server that hasn't started serving yet. Removing it fails both Go stop tests. - Go
TestMain: the exit and cleanup ordering is correct. Noos.CreateTemp("", "repositories.yaml")is left.
RemoteJarLoader
-
Timeouts, the Content-Length check, and the atomic
.part+ move behave correctly with redirects, chunked or unknown lengths,file:URLs, the cache-hit path,forceUpdate, and 32 concurrent downloads to the same target. It uses Java 8 APIs only, and the cached JAR's permissions are unchanged. -
ZIP validation before the move, tested on Java 8 and 21:
- every truncation length of a 6-entry JAR fails;
- about 8,900 truncation points of the real 29.8 MB
linux-amd64JAR fail, including every byte of the last 8 KiB; - a zip64 JAR with 70,000 entries still opens.
The release note was narrowed to "truncated or not a valid ZIP": entry data and CRCs aren't checked.
-
New tests cover the cache hit,
forceUpdatekeeping the old JAR when a download fails, and a truncated chunked response. Mutations of the ZIP check, the length check, delete-first, and the timeouts are each caught. -
Windows move fallback: covered by review only.
Follow-ups (not blocking)
- Security, not introduced here: the remote JAR is cached at a predictable path in a shared
java.io.tmpdirand loaded on a cache hit without verification. A separate PR will add.sha1verification and a per-user cache. - Error reporting: download failures surface to users only as "No NativeLibrary implementation found". The cause should be kept or logged.
- Orphaned
.partfiles: they're left behind when a JVM is killed mid-download. - Eclipse/m2e: it may not apply Surefire's environment variables, so Eclipse runs would use the real Helm config, as before this PR.
RemoteJarLoader swallowed every download and metadata failure, so a timeout, an HTTP 404 or a truncated download all surfaced only as "No NativeLibrary implementation found, please add one of the supported dependencies to your project", with no hint of the cause. - remoteJar() now throws the IOException (XML errors in the snapshot metadata are wrapped with its URL); it still returns null when the remote JAR is disabled or the platform is unknown - NativeLibrary.getInstance() keeps its message and attaches that failure as the cause - RemoteJarLoaderTest covers the release and snapshot lookups and the failures through a package-private remoteJar(...) seam Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Nuri <marc@marcnuri.com>
Test hygiene follow-ups to #463 (context: #409). The Java and Go tests wrote registry logins, repository indexes and lock files into the developer's own Helm config, cache and temp directory. The test OCI servers were never stopped. The remote native JAR download could hang forever, or cache a truncated JAR.
Changes
helm-java/pom.xml)HELM_CACHE_HOMEandHELM_DATA_HOMEathelm-java/target/helm-home/(thehelm.test.homeproperty). It pointsHELM_CONFIG_HOMEandDOCKER_CONFIGathelm-java/target/test-classes/helm-home/.src/test/resources/helm-home/), so Maven and IDEs both copy them. They hold a placeholder entry. Without one, Helm's registry client (oras-goDetectDefaultNativeStore) stores logins in the OS credential store: Keychain, Credential Manager,passor Secret Service.excludedEnvironmentVariablesdrops everyHELM_*variable Helm v3.22.1 reads that would redirect its files or change its behaviour: those inpkg/cli/environment.go, plusHELM_DRIVER(read bynative/internal/helm/helm.go) andHELM_DRIVER_SQL_CONNECTION_STRING(pkg/action/action.go). That list is the same as innative/internal/test/env.go.HelmPackageTest.withoutChartpackages an empty temp directory instead of the working directory. The working directory now holds the cached repository indexes, which are over Helm's 5 MiB file limit.AGENTS.mddocuments all of this, including the trade-off: Testcontainers' KinD and Ryuk image pulls are anonymous.native/internal/test)TestMains now really run their cleanup. Before,os.Exitskipped the deferred cleanup and left ahelm-test-*directory behind on every run.test.RepositoryConfig(t, content)putsrepositories.yamlint.TempDir(). Withos.CreateTemp("", "repositories.yaml"),RepoAddleft a shared$TMPDIR/repositories.lockbehind.HELM_*list matches the Java one.RepoServerStop/RepoServerStopAllcall distribution'sRegistry.Shutdownwith a bounded context. The strayos.RemoveAll(server.id), which ran on a relative path in the working directory, is gone.HelmRegistryTestandHelmShowTeststop their servers in@AfterEach, asHelmPushTestdoes.RemoteJarLoaderContent-Length, a cheap first check;.partfile and moves it into place atomically, so no JVM sees or deletes another one's partial file.IllegalStateExceptionfromNativeLibrary.getInstance()keeps its message and now carries the download or metadata failure as its cause, for example a timeout, an HTTP 404 or a truncated download. This addresses the review comment about swallowed download failures.RepoServerStartdirectly, with no goroutines, busy-polling or fixed sleeps, and use an HTTP client with a timeout.HelmTestServerTestsets connection timeouts.Release notes
RemoteJarLoader(the fallback that downloads the platform JAR when none is on the classpath):Content-Length, or one that doesn't open as a valid ZIP (its end record and central directory; entry data isn't checked).com.marcnuri.jkube-helm.forceUpdate, the previously cached JAR is kept when the new download fails. Before, it was deleted first.No NativeLibrary implementation founderror now includes the underlying download failure as its cause.Testing
CI on
7970ee6(this PR's first commit) passed on Linux, macOS and Windows, including the envtest suite,HelmKubernetesTest(KinD, with the isolatedDOCKER_CONFIG) andNativeLibraryTest. The follow-up commits changeRemoteJarLoaderand the seed location, and only CI exercises the real Maven Central download and the macOS/Windows paths, so CI runs again on them. Onc4c06dc, macOS failed onlyNativeLibraryTest.getSnapshotInstanceFromRemoteJar, with the generic message. The snapshot JAR it fetched is complete (its Content-Length matches, andunzip -tpasses), so it was most likely a network failure. The swallowed exception hid the reason, which is why the error now carries it.Locally, on Java 8 (linux/amd64), in a sandbox where
~/.config/helmand~/.cache/helmare read-only, so passing tests can't have written there:lib/api: 51/51.RemoteJarLoaderTestruns against a localHttpServer, with no mocks. It covers the release and snapshot (maven-metadata.xml) lookups, and that a missing JAR, missing metadata or invalid metadata surfaces as an exception naming the URL.NativeLibraryTest: the offline cases pass, and with the remote JAR disabled the error has no cause, as before. The remote cases can't reach Maven Central from the sandbox, and their failure now shows the cause (UnknownHostException: repo1.maven.org) instead of only the generic message.helm-java: Install, Template, Search, Repo, Registry, Push, Show, Package, Dependency, TestServer and SignalHandler all pass, 91/91, after aclean, with only the chart hosts reachable.HelmSearchTestran beforeHelmPackageTest.target/helm-home, not intarget/test-classes.~/.local/share/kubebuilder-envtest. Norepositories*file orhelm-test-*directory is left in$TMPDIR.HELM_REGISTRY_CONFIG,HELM_REPOSITORY_CACHEandHELM_REPOSITORY_CONFIGset to bogus paths, the tests passed and used the isolated homes.Controls and mutations, each of which fails without the fix:
withoutChartfails once a large index is cached.HELM_REPOSITORY_CACHEbreaksHelmInstallTest.clean, a fakedocker-credential-secretserviceonPATHreceives every login andcredsStoregets written. With them it is never called, after acleanor on a re-run.repositories.lockand ahelm-test-*directory behind.Shutdownfails both Go stop tests.RemoteJarLoaderTestcatches each of these:forceUpdate;The Windows move fallback can't be triggered on Linux without root, so it is covered by review only.