Skip to content

Commit

Permalink
Fix issue where CustomSeverities are not respected in config (#459)
Browse files Browse the repository at this point in the history
Original ability was added in: #281

When trying out the functionality, it does not respect custom_severities
as documented in the README.

This patch addresses it by including the porting of custom severities
from the the same location where other config keys are copied

I've confirmed that it works both in a new test and in manual regression
testing.

Fixes: #364
  • Loading branch information
zph authored Jun 26, 2024
1 parent 9a5d30e commit 666644d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions talismanrc/talismanrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func fromPersistedRC(configFromTalismanRCFile *persistedRC, mode Mode) *Talisman
tRC.ScopeConfig = configFromTalismanRCFile.ScopeConfig
tRC.Experimental = configFromTalismanRCFile.Experimental
tRC.CustomPatterns = configFromTalismanRCFile.CustomPatterns
tRC.CustomSeverities = configFromTalismanRCFile.CustomSeverities
tRC.Experimental = configFromTalismanRCFile.Experimental
tRC.AllowedPatterns = make([]*regexp.Regexp, len(configFromTalismanRCFile.AllowedPatterns))
for i, p := range configFromTalismanRCFile.AllowedPatterns {
Expand Down
13 changes: 13 additions & 0 deletions talismanrc/talismanrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ func TestShouldConvertThresholdToValue(t *testing.T) {
assert.Equal(t, newPersistedRC(talismanRCContents).Threshold, severity.High)
}

func TestObeysCustomSeverityLevelsAndThreshold(t *testing.T) {
talismanRCContents := []byte(`threshold: high
custom_severities:
- detector: Base64Content
severity: low
`)
persistedRC := newPersistedRC(talismanRCContents)
talismanRC := fromPersistedRC(persistedRC, ScanMode)
assert.Equal(t, newPersistedRC(talismanRCContents).Threshold, severity.High)
assert.Equal(t, len(newPersistedRC(talismanRCContents).CustomSeverities), 1)
assert.Equal(t, persistedRC.CustomSeverities, talismanRC.CustomSeverities)
}

func TestDirectoryPatterns(t *testing.T) {
assertAccepts("foo/", "", "bar", t)
assertAccepts("foo/", "", "foo", t)
Expand Down

0 comments on commit 666644d

Please sign in to comment.