Skip to content

Commit d7e9625

Browse files
Remove unused hasher
Authored-by: Owen Nelson <[email protected]>
1 parent 8b425eb commit d7e9625

File tree

8 files changed

+30
-43
lines changed

8 files changed

+30
-43
lines changed

detector/chain.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ import (
1515
log "github.com/sirupsen/logrus"
1616
)
1717

18-
//Chain represents a chain of Detectors.
19-
//It is itself a detector.
18+
// Chain represents a chain of Detectors.
19+
// It is itself a detector.
2020
type Chain struct {
2121
detectors []detector.Detector
2222
mode string
2323
}
2424

25-
//NewChain returns an empty DetectorChain
26-
//It is itself a detector, but it tests nothing.
25+
// NewChain returns an empty DetectorChain
26+
// It is itself a detector, but it tests nothing.
2727
func NewChain(hooktype string) *Chain {
2828
result := Chain{[]detector.Detector{}, hooktype}
2929
return &result
3030
}
3131

32-
//DefaultChain returns a DetectorChain with pre-configured detectors
32+
// DefaultChain returns a DetectorChain with pre-configured detectors
3333
func DefaultChain(tRC *talismanrc.TalismanRC, runMode string) *Chain {
3434
chain := NewChain(runMode)
3535
chain.AddDetector(filename.DefaultFileNameDetector(tRC.Threshold))
@@ -38,21 +38,21 @@ func DefaultChain(tRC *talismanrc.TalismanRC, runMode string) *Chain {
3838
return chain
3939
}
4040

41-
//AddDetector adds the detector that is passed in to the chain
41+
// AddDetector adds the detector that is passed in to the chain
4242
func (dc *Chain) AddDetector(d detector.Detector) *Chain {
4343
dc.detectors = append(dc.detectors, d)
4444
return dc
4545
}
4646

47-
//Test validates the additions against each detector in the chain.
48-
//The results are passed in from detector to detector and thus collect all errors from all detectors
47+
// Test validates the additions against each detector in the chain.
48+
// The results are passed in from detector to detector and thus collect all errors from all detectors
4949
func (dc *Chain) Test(currentAdditions []gitrepo.Addition, talismanRC *talismanrc.TalismanRC, result *helpers.DetectionResults) {
5050
wd, _ := os.Getwd()
5151
repo := gitrepo.RepoLocatedAt(wd)
5252
allAdditions := repo.TrackedFilesAsAdditions()
5353
hasher := utility.MakeHasher(dc.mode, wd)
5454
calculator := checksumcalculator.NewChecksumCalculator(hasher, append(allAdditions, currentAdditions...))
55-
cc := helpers.NewChecksumCompare(calculator, hasher, talismanRC)
55+
cc := helpers.NewChecksumCompare(calculator, talismanRC)
5656
log.Printf("Number of files to scan: %d\n", len(currentAdditions))
5757
log.Printf("Number of detectors: %d\n", len(dc.detectors))
5858
total := len(currentAdditions) * len(dc.detectors)

detector/filecontent/base64_aggressive_detector_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package filecontent
22

33
import (
44
"talisman/detector/helpers"
5-
"talisman/utility"
65
"testing"
76

87
"talisman/gitrepo"
@@ -23,7 +22,7 @@ func TestShouldFlagPotentialAWSAccessKeysInAggressiveMode(t *testing.T) {
2322

2423
aggressiveModeFileContentDetector.
2524
Test(
26-
helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), _blankTalismanRC),
25+
helpers.NewChecksumCompare(nil, _blankTalismanRC),
2726
additions,
2827
_blankTalismanRC,
2928
results,
@@ -40,7 +39,7 @@ func TestShouldFlagPotentialAWSAccessKeysAtPropertyDefinitionInAggressiveMode(t
4039

4140
aggressiveModeFileContentDetector.
4241
Test(
43-
helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), _blankTalismanRC),
42+
helpers.NewChecksumCompare(nil, _blankTalismanRC),
4443
additions,
4544
_blankTalismanRC,
4645
results,
@@ -62,7 +61,7 @@ func TestShouldNotFlagPotentialSecretsWithinSafeJavaCodeEvenInAggressiveMode(t *
6261

6362
aggressiveModeFileContentDetector.
6463
Test(
65-
helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), _blankTalismanRC),
64+
helpers.NewChecksumCompare(nil, _blankTalismanRC),
6665
additions,
6766
_blankTalismanRC,
6867
results,

detector/filecontent/filecontent_detector_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"talisman/gitrepo"
1010
mock "talisman/internal/mock/checksumcalculator"
1111
"talisman/talismanrc"
12-
"talisman/utility"
1312
"testing"
1413

1514
"github.com/golang/mock/gomock"
@@ -18,8 +17,7 @@ import (
1817
)
1918

2019
var emptyTalismanRC = &talismanrc.TalismanRC{IgnoreConfigs: []talismanrc.IgnoreConfig{}}
21-
var defaultChecksumCompareUtility = helpers.
22-
NewChecksumCompare(nil, utility.MakeHasher("default", "."), emptyTalismanRC)
20+
var defaultChecksumCompareUtility = helpers.NewChecksumCompare(nil, emptyTalismanRC)
2321
var dummyCallback = func() {}
2422
var filename = "filename"
2523

@@ -44,8 +42,7 @@ func TestShouldIgnoreFileIfNeeded(t *testing.T) {
4442
mockChecksumCalculator.EXPECT().
4543
CalculateCollectiveChecksumForPattern("filename").
4644
Return("mock-checksum-for-filename")
47-
checksumCompare := helpers.
48-
NewChecksumCompare(mockChecksumCalculator, utility.MakeHasher("default", "."), talismanRCIWithFilenameIgnore)
45+
checksumCompare := helpers.NewChecksumCompare(mockChecksumCalculator, talismanRCIWithFilenameIgnore)
4946

5047
NewFileContentDetector(talismanRCIWithFilenameIgnore).
5148
Test(checksumCompare, additions, talismanRCIWithFilenameIgnore, results, dummyCallback)
@@ -191,8 +188,7 @@ func TestShouldNotFlagPotentialCreditCardNumberIfAboveThreshold(t *testing.T) {
191188
results := helpers.NewDetectionResults(talismanrc.HookMode)
192189
additions := []gitrepo.Addition{gitrepo.NewAddition(filename, []byte(creditCardNumber))}
193190
talismanRCWithThreshold := &talismanrc.TalismanRC{Threshold: severity.High}
194-
checksumCompareWithThreshold := helpers.
195-
NewChecksumCompare(nil, utility.MakeHasher("default", "."), talismanRCWithThreshold)
191+
checksumCompareWithThreshold := helpers.NewChecksumCompare(nil, talismanRCWithThreshold)
196192

197193
NewFileContentDetector(emptyTalismanRC).
198194
Test(checksumCompareWithThreshold, additions, talismanRCWithThreshold, results, dummyCallback)
@@ -221,18 +217,17 @@ func TestResultsShouldNotFlagCreditCardNumberIfSpecifiedInFileIgnores(t *testing
221217
AllowedPatterns: []string{creditCardNumber},
222218
}
223219
talismanRCWithFileIgnore := &talismanrc.TalismanRC{
224-
IgnoreConfigs: []talismanrc.IgnoreConfig{fileIgnoreConfig},
220+
IgnoreConfigs: []talismanrc.IgnoreConfig{fileIgnoreConfig},
225221
}
226222
additions := []gitrepo.Addition{gitrepo.NewAddition(filename, []byte(creditCardNumber))}
227223

228224
NewFileContentDetector(emptyTalismanRC).
229225
Test(defaultChecksumCompareUtility, additions, talismanRCWithFileIgnore, results, dummyCallback)
230-
226+
231227
assert.False(t, results.HasFailures(), "Expected the creditcard number to be ignored based on talisman RC")
232228

233229
}
234230

235-
236231
func TestResultsShouldContainHexTextsIfHexAndBase64ExistInFile(t *testing.T) {
237232
const hex string = "68656C6C6F20776F726C6421"
238233
const base64 string = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

detector/filename/filename_detector_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"regexp"
88
"talisman/detector/helpers"
99
"talisman/detector/severity"
10-
"talisman/utility"
1110
"testing"
1211

1312
"talisman/gitrepo"
@@ -17,7 +16,7 @@ import (
1716
)
1817

1918
var talismanRC = &talismanrc.TalismanRC{}
20-
var defaultChecksumCompareUtility = helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), talismanRC)
19+
var defaultChecksumCompareUtility = helpers.NewChecksumCompare(nil, talismanRC)
2120

2221
func TestShouldFlagPotentialSSHPrivateKeys(t *testing.T) {
2322
shouldFail("id_rsa", "^.+_rsa$", severity.Low, t)

detector/filesize/filesize_detector_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package filesize
33
import (
44
"talisman/detector/helpers"
55
"talisman/detector/severity"
6-
"talisman/utility"
76
"testing"
87

98
"talisman/gitrepo"
@@ -13,13 +12,12 @@ import (
1312
)
1413

1514
var talismanRC = &talismanrc.TalismanRC{}
16-
var defaultHasher = utility.MakeHasher("default", ".")
1715

1816
func TestShouldFlagLargeFiles(t *testing.T) {
1917
results := helpers.NewDetectionResults(talismanrc.HookMode)
2018
content := []byte("more than one byte")
2119
additions := []gitrepo.Addition{gitrepo.NewAddition("filename", content)}
22-
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, defaultHasher, talismanRC), additions, talismanRC, results, func() {})
20+
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, talismanRC), additions, talismanRC, results, func() {})
2321
assert.True(t, results.HasFailures(), "Expected file to fail the check against file size detector.")
2422
}
2523

@@ -28,7 +26,7 @@ func TestShouldNotFlagLargeFilesIfThresholdIsBelowSeverity(t *testing.T) {
2826
content := []byte("more than one byte")
2927
talismanRCWithThreshold := &talismanrc.TalismanRC{Threshold: severity.High}
3028
additions := []gitrepo.Addition{gitrepo.NewAddition("filename", content)}
31-
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, defaultHasher, talismanRCWithThreshold), additions, talismanRCWithThreshold, results, func() {})
29+
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, talismanRCWithThreshold), additions, talismanRCWithThreshold, results, func() {})
3230
assert.False(t, results.HasFailures(), "Expected file to not fail the check against file size detector.")
3331
assert.True(t, results.HasWarnings(), "Expected file to have warnings against file size detector.")
3432
}
@@ -37,7 +35,7 @@ func TestShouldNotFlagSmallFiles(t *testing.T) {
3735
results := helpers.NewDetectionResults(talismanrc.HookMode)
3836
content := []byte("m")
3937
additions := []gitrepo.Addition{gitrepo.NewAddition("filename", content)}
40-
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, defaultHasher, talismanRC), additions, talismanRC, results, func() {})
38+
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, talismanRC), additions, talismanRC, results, func() {})
4139
assert.False(t, results.HasFailures(), "Expected file to not fail the check against file size detector.")
4240
}
4341

@@ -55,6 +53,6 @@ func TestShouldNotFlagIgnoredLargeFiles(t *testing.T) {
5553
talismanRC.IgnoreConfigs[0] = fileIgnoreConfig
5654

5755
additions := []gitrepo.Addition{gitrepo.NewAddition(filename, content)}
58-
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, defaultHasher, talismanRC), additions, talismanRC, results, func() {})
56+
NewFileSizeDetector(2).Test(helpers.NewChecksumCompare(nil, talismanRC), additions, talismanRC, results, func() {})
5957
assert.True(t, results.Successful(), "expected file %s to be ignored by file size detector", filename)
6058
}

detector/helpers/checksum_compare.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ import (
44
"talisman/checksumcalculator"
55
"talisman/gitrepo"
66
"talisman/talismanrc"
7-
"talisman/utility"
87
)
98

109
type ChecksumCompare struct {
1110
calculator checksumcalculator.ChecksumCalculator
12-
hasher utility.SHA256Hasher
1311
talismanRC *talismanrc.TalismanRC
1412
}
1513

1614
// NewChecksumCompare returns new instance of the ChecksumCompare
17-
func NewChecksumCompare(calculator checksumcalculator.ChecksumCalculator, hasher utility.SHA256Hasher, talismanRCConfig *talismanrc.TalismanRC) ChecksumCompare {
18-
return ChecksumCompare{calculator: calculator, hasher: hasher, talismanRC: talismanRCConfig}
15+
func NewChecksumCompare(calculator checksumcalculator.ChecksumCalculator, talismanRCConfig *talismanrc.TalismanRC) ChecksumCompare {
16+
return ChecksumCompare{calculator: calculator, talismanRC: talismanRCConfig}
1917
}
2018

2119
func (cc *ChecksumCompare) IsScanNotRequired(addition gitrepo.Addition) bool {

detector/helpers/checksum_compare_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"talisman/gitrepo"
66
mockchecksumcalculator "talisman/internal/mock/checksumcalculator"
77
"talisman/talismanrc"
8-
"talisman/utility"
98

109
"github.com/golang/mock/gomock"
1110
logr "github.com/sirupsen/logrus"
@@ -23,7 +22,7 @@ func TestChecksumCompare_IsScanNotRequired(t *testing.T) {
2322
ignoreConfig := &talismanrc.TalismanRC{
2423
IgnoreConfigs: []talismanrc.IgnoreConfig{},
2524
}
26-
cc := NewChecksumCompare(nil, utility.MakeHasher("default", "."), ignoreConfig)
25+
cc := NewChecksumCompare(nil, ignoreConfig)
2726
addition := gitrepo.Addition{Path: "some.txt"}
2827

2928
required := cc.IsScanNotRequired(addition)
@@ -43,7 +42,7 @@ func TestChecksumCompare_IsScanNotRequired(t *testing.T) {
4342
},
4443
},
4544
}
46-
cc := NewChecksumCompare(checksumCalculator, utility.MakeHasher("default", "."), &ignoreConfig)
45+
cc := NewChecksumCompare(checksumCalculator, &ignoreConfig)
4746
addition := gitrepo.Addition{Name: "some.txt"}
4847
checksumCalculator.EXPECT().CalculateCollectiveChecksumForPattern("some.txt").Return("sha1")
4948

detector/pattern/pattern_detector_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import (
77
"talisman/detector/severity"
88
"talisman/gitrepo"
99
"talisman/talismanrc"
10-
"talisman/utility"
1110
"testing"
1211

1312
"github.com/stretchr/testify/assert"
1413
)
1514

1615
var talismanRC = &talismanrc.TalismanRC{}
17-
var defaultChecksumCompare = helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), talismanRC)
16+
var defaultChecksumCompare = helpers.NewChecksumCompare(nil, talismanRC)
1817
var dummyCallback = func() {}
1918

2019
var (
@@ -30,8 +29,8 @@ func TestShouldDetectPasswordPatterns(t *testing.T) {
3029
shouldPassDetectionOfSecretPattern(filename, []byte("."+values[i]+"=randomStringGoesHere}"), t)
3130
shouldPassDetectionOfSecretPattern(filename, []byte(":"+values[i]+" randomStringGoesHere"), t)
3231
shouldPassDetectionOfSecretPattern(filename, []byte(values[i]+" ,\"randomStringGoesHere\""), t)
33-
shouldPassDetectionOfSecretPattern(filename, []byte("'" + values[i]+"' ,\"randomStringGoesHere\""), t)
34-
shouldPassDetectionOfSecretPattern(filename, []byte("\"" + values[i]+"\" ,\"randomStringGoesHere\""), t)
32+
shouldPassDetectionOfSecretPattern(filename, []byte("'"+values[i]+"' ,\"randomStringGoesHere\""), t)
33+
shouldPassDetectionOfSecretPattern(filename, []byte("\""+values[i]+"\" ,\"randomStringGoesHere\""), t)
3534
shouldPassDetectionOfSecretPattern(filename,
3635
[]byte("\"SERVER_"+strings.ToUpper(values[i])+"\" : UnsafeString"),
3736
t)
@@ -104,7 +103,7 @@ func TestShouldOnlyWarnSecretPatternIfBelowThreshold(t *testing.T) {
104103
filename := "secret.txt"
105104
additions := []gitrepo.Addition{gitrepo.NewAddition(filename, content)}
106105
talismanRCWithThreshold := &talismanrc.TalismanRC{Threshold: severity.High}
107-
checksumCompare := helpers.NewChecksumCompare(nil, utility.MakeHasher("default", "."), talismanRCWithThreshold)
106+
checksumCompare := helpers.NewChecksumCompare(nil, talismanRCWithThreshold)
108107

109108
NewPatternDetector(customPatterns).Test(checksumCompare, additions, talismanRCWithThreshold, results, dummyCallback)
110109

0 commit comments

Comments
 (0)