Skip to content

fix(secparse): replace panic in MustParse with testing.TB.Fatalf#3420

Merged
dominikschulz merged 1 commit intogopasspw:masterfrom
dimension-zero:fix/secparse-panic
May 4, 2026
Merged

fix(secparse): replace panic in MustParse with testing.TB.Fatalf#3420
dominikschulz merged 1 commit intogopasspw:masterfrom
dimension-zero:fix/secparse-panic

Conversation

@dimension-zero
Copy link
Copy Markdown
Contributor

Summary

secparse.MustParse was exported from a public package (pkg/gopass/secrets/secparse) and contained a panic(err) that fires on a *secrets.PermanentError from 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.

  • Replace panic(err) with tb.Fatalf(...), using a testing.TB parameter
  • Add tb.Helper() so test failure lines point to the call site, not inside MustParse
  • Update the three call sites in pkg/otp/otp_test.go to pass t

The testing.TB parameter type-enforces test-only use: production code cannot call this function without a testing.TB value, making the intent structurally clear rather than just a comment.

Test plan

  • go build ./pkg/gopass/secrets/secparse/... — clean
  • go test ./pkg/otp/... — passes
  • go test ./pkg/gopass/secrets/... — passes

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.
Copy link
Copy Markdown
Member

@dominikschulz dominikschulz left a comment

Choose a reason for hiding this comment

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

Nice!

@dominikschulz dominikschulz merged commit d978513 into gopasspw:master May 4, 2026
9 of 10 checks passed
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.

2 participants