Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fs/fshttp: fix TestCertificates leaking client cert/key onto global config - #9843

Merged
ncw merged 1 commit into
rclone:masterfrom
halindrome:fix/testcertificates-cleanup-leak
Sep 5, 2026
Merged

fs/fshttp: fix TestCertificates leaking client cert/key onto global config#9843
ncw merged 1 commit into
rclone:masterfrom
halindrome:fix/testcertificates-cleanup-leak

Conversation

@halindrome

Copy link
Copy Markdown

Split out from the discussion in #9841, per @ncw's request there.

TestCertificates sets ci.ClientCert/ci.ClientKey on the process-global ConfigInfo (the test's ctx carries no override) to a path under t.TempDir(), and never resets them. Go removes t.TempDir() on test cleanup, so any later test in fs/fshttp that builds a client via NewTransportCustom fails trying to load a cert file that no longer exists.

Harmless on its own -- it only surfaces once something else in the same test binary calls NewClient/NewTransportCustom after TestCertificates runs, since go test executes tests within a package in source order by default. I hit it while adding a new test to this package for #9841.

One-line fix: reset both fields in a defer, same pattern used elsewhere in this file.

@halindrome
halindrome requested a review from ncw as a code owner August 30, 2026 14:16

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this up

I thought of a neater way of doing this - see inline

Comment thread fs/fshttp/http_test.go Outdated
@@ -177,6 +177,14 @@ func TestCertificates(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better fix would be to to use fs.AddConfig here which makes a private config just for this test.

PS No need for a massive comment :-)

@halindrome
halindrome force-pushed the fix/testcertificates-cleanup-leak branch from 8a75eda to b7e6c41 Compare September 3, 2026 18:43
@halindrome

Copy link
Copy Markdown
Author

Thanks - fs.AddConfig is much better, and the comment is gone. Pushed: the whole diff is now

// Use a private config so the cert paths don't leak into other tests
ctx, ci := fs.AddConfig(context.TODO())

Verified the leak is actually fixed rather than just moved: a throwaway test placed after TestCertificates in the package sees a clean global config with this change, and fails with global config leaked: cert="/tmp/TestCertificates.../001client.cert" when reverted. go test ./fs/fshttp/, go vet and gofmt all clean.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect - thank you :-)

@ncw
ncw force-pushed the fix/testcertificates-cleanup-leak branch from 557491c to ffb10d0 Compare September 5, 2026 10:58
@ncw
ncw requested a review from nielash as a code owner September 5, 2026 10:58
…onfig

This was fixed in this commit in an inelegant way

399bc6a fshttp: don't send --header values to other hosts on redirect

The current commit fixes it properly with AddConfig.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants