-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
trufflehog:ignore
tag feature (#1433)
* init ignore * cleanup and add test * update readme
- Loading branch information
1 parent
0092098
commit 18a70b6
Showing
3 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package engine | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors" | ||
"github.com/trufflesecurity/trufflehog/v3/pkg/sources" | ||
) | ||
|
||
func TestFragmentLineOffset(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
chunk *sources.Chunk | ||
result *detectors.Result | ||
expectedLine int64 | ||
ignore bool | ||
}{ | ||
{ | ||
name: "ignore found on same line", | ||
chunk: &sources.Chunk{ | ||
Data: []byte("line1\nline2\nsecret here trufflehog:ignore\nline4"), | ||
}, | ||
result: &detectors.Result{ | ||
Raw: []byte("secret here"), | ||
}, | ||
expectedLine: 2, | ||
ignore: true, | ||
}, | ||
{ | ||
name: "no ignore", | ||
chunk: &sources.Chunk{ | ||
Data: []byte("line1\nline2\nsecret here\nline4"), | ||
}, | ||
result: &detectors.Result{ | ||
Raw: []byte("secret here"), | ||
}, | ||
expectedLine: 2, | ||
ignore: false, | ||
}, | ||
{ | ||
name: "ignore on different line", | ||
chunk: &sources.Chunk{ | ||
Data: []byte("line1\nline2\ntrufflehog:ignore\nline4\nsecret here\nline6"), | ||
}, | ||
result: &detectors.Result{ | ||
Raw: []byte("secret here"), | ||
}, | ||
expectedLine: 4, | ||
ignore: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
lineOffset, isIgnored := FragmentLineOffset(tt.chunk, tt.result) | ||
if lineOffset != tt.expectedLine { | ||
t.Errorf("Expected line offset to be %d, got %d", tt.expectedLine, lineOffset) | ||
} | ||
if isIgnored != tt.ignore { | ||
t.Errorf("Expected isIgnored to be %v, got %v", tt.ignore, isIgnored) | ||
} | ||
}) | ||
} | ||
} |