Files
trufflehog/pkg/detectors/result_test.go
Casey Tran f714bf454f
Lint / golangci-lint (push) Waiting to run
Lint / man-page-staleness (push) Waiting to run
Lint / semgrep (push) Waiting to run
Lint / checksecretparts (push) Waiting to run
Scan for secrets / test (push) Waiting to run
Test / test (push) Waiting to run
Test / test-community (push) Waiting to run
Release / mark-latest (push) Canceled after 0s
Release / Release (push) Canceled after 0s
[SCAN-177] Purge secret parts from verification cache (#5318)
This PR aims to zero out secret areas of a result before caching it.
2026-09-16 11:56:14 -05:00

32 lines
878 B
Go

package detectors
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestClearSecrets(t *testing.T) {
result := Result{
Raw: []byte("raw-secret"),
RawV2: []byte("raw-secret-v2"),
Redacted: "redacted",
SecretParts: map[string]string{"key": "raw-secret"},
ExtraData: map[string]string{"account": "123"},
}
result.SetPrimarySecretValue("secret-value")
result.SetPrimarySecretLine(12)
result.SetVerificationError(assert.AnError)
result.ClearSecrets()
assert.Nil(t, result.Raw)
assert.Nil(t, result.RawV2)
assert.Nil(t, result.SecretParts)
assert.Empty(t, result.GetPrimarySecretValue())
assert.Zero(t, result.primarySecret.Line)
assert.Equal(t, "redacted", result.Redacted)
assert.Equal(t, map[string]string{"account": "123"}, result.ExtraData)
assert.EqualError(t, result.VerificationError(), assert.AnError.Error())
}