Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 514c9f8e40 | |||
| 9894b14b02 |
@@ -39,6 +39,8 @@ type EndpointCustomizer interface {
|
|||||||
DefaultEndpoint() string
|
DefaultEndpoint() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Result is a secret that has been found by a Detector and optionally verified.
|
||||||
|
// It contains the raw secret identification data, redacted data, and extra data.
|
||||||
type Result struct {
|
type Result struct {
|
||||||
// DetectorType is the type of Detector.
|
// DetectorType is the type of Detector.
|
||||||
DetectorType detectorspb.DetectorType
|
DetectorType detectorspb.DetectorType
|
||||||
@@ -46,7 +48,15 @@ type Result struct {
|
|||||||
DetectorName string
|
DetectorName string
|
||||||
// DecoderType is the type of Decoder.
|
// DecoderType is the type of Decoder.
|
||||||
DecoderType detectorspb.DecoderType
|
DecoderType detectorspb.DecoderType
|
||||||
Verified bool
|
// Verified is true if the secret has been confirmed to be a valid secret.
|
||||||
|
Verified bool
|
||||||
|
// HasVerificationIndeterminate is true if the secret could NOT be verified.
|
||||||
|
// This is used to differentiate between secrets that are NOT verified and secrets that COULD NOT be verified.
|
||||||
|
// Ex: A 429 response from a service, or a timeout would set this to true.
|
||||||
|
HasVerificationIndeterminate bool
|
||||||
|
// VerificationIndeterminateError holds the error if the secret could NOT be verified.
|
||||||
|
// This is used specifically for cases that resulted in indeterminate resolution, such as a 429 or timeout.
|
||||||
|
VerificationIndeterminateError error
|
||||||
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
|
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
|
||||||
Raw []byte
|
Raw []byte
|
||||||
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
|
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
|
||||||
@@ -59,6 +69,17 @@ type Result struct {
|
|||||||
StructuredData *detectorspb.StructuredData
|
StructuredData *detectorspb.StructuredData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVerified checks if a result is guaranteed to be verified.
|
||||||
|
func (r Result) IsVerified() bool {
|
||||||
|
return r.Verified && !r.HasVerificationIndeterminate
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsUnverified checks if a result is guaranteed to be unverified.
|
||||||
|
// This is used to differentiate between secrets that are NOT verified and secrets that COULD NOT be verified.
|
||||||
|
func (r Result) IsUnverified() bool {
|
||||||
|
return !r.Verified && !r.HasVerificationIndeterminate
|
||||||
|
}
|
||||||
|
|
||||||
type ResultWithMetadata struct {
|
type ResultWithMetadata struct {
|
||||||
// SourceMetadata contains source-specific contextual information.
|
// SourceMetadata contains source-specific contextual information.
|
||||||
SourceMetadata *source_metadatapb.MetaData
|
SourceMetadata *source_metadatapb.MetaData
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
package detectors
|
package detectors
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestPrefixRegex(t *testing.T) {
|
func TestPrefixRegex(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@@ -37,3 +39,101 @@ func BenchmarkPrefixRegex(b *testing.B) {
|
|||||||
PrefixRegex(kws)
|
PrefixRegex(kws)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsVerified(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result Result
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Verified true, HasVerificationIndeterminate false",
|
||||||
|
result: Result{
|
||||||
|
Verified: true,
|
||||||
|
HasVerificationIndeterminate: false,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified false, HasVerificationIndeterminate false",
|
||||||
|
result: Result{
|
||||||
|
Verified: false,
|
||||||
|
HasVerificationIndeterminate: false,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified true, HasVerificationIndeterminate true",
|
||||||
|
result: Result{
|
||||||
|
Verified: true,
|
||||||
|
HasVerificationIndeterminate: true,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified false, HasVerificationIndeterminate true",
|
||||||
|
result: Result{
|
||||||
|
Verified: false,
|
||||||
|
HasVerificationIndeterminate: true,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := tt.result.IsVerified(); got != tt.want {
|
||||||
|
t.Errorf("IsVerified() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsUnverified(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result Result
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Verified true, HasVerificationIndeterminate false",
|
||||||
|
result: Result{
|
||||||
|
Verified: true,
|
||||||
|
HasVerificationIndeterminate: false,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified false, HasVerificationIndeterminate false",
|
||||||
|
result: Result{
|
||||||
|
Verified: false,
|
||||||
|
HasVerificationIndeterminate: false,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified true, HasVerificationIndeterminate true",
|
||||||
|
result: Result{
|
||||||
|
Verified: true,
|
||||||
|
HasVerificationIndeterminate: true,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Verified false, HasVerificationIndeterminate true",
|
||||||
|
result: Result{
|
||||||
|
Verified: false,
|
||||||
|
HasVerificationIndeterminate: true,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := tt.result.IsUnverified(); got != tt.want {
|
||||||
|
t.Errorf("IsUnverified() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user