fix(secparse): replace panic in MustParse with testing.TB.Fatalf#3420
Merged
dominikschulz merged 1 commit intogopasspw:masterfrom May 4, 2026
Merged
Conversation
MustParse was exported from a public package and could panic on a PermanentError from malformed MIME input. Accepting testing.TB ties the function to the test framework at the type level, making non-test use structurally obvious and replacing the panic with a controlled test failure. Callers in pkg/otp/otp_test.go updated to pass t.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
secparse.MustParsewas exported from a public package (pkg/gopass/secrets/secparse) and contained apanic(err)that fires on a*secrets.PermanentErrorfrom malformed MIME input. Although the function was documented as test-only, the panic was reachable from any caller — including non-test code that imports the package.panic(err)withtb.Fatalf(...), using atesting.TBparametertb.Helper()so test failure lines point to the call site, not insideMustParsepkg/otp/otp_test.goto passtThe
testing.TBparameter type-enforces test-only use: production code cannot call this function without atesting.TBvalue, making the intent structurally clear rather than just a comment.Test plan
go build ./pkg/gopass/secrets/secparse/...— cleango test ./pkg/otp/...— passesgo test ./pkg/gopass/secrets/...— passes