mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 05:24:22 +01:00
feat(config): update rule validation (#1466)
This commit is contained in:
1 parent
6dfcf5e949
commit
1aae66d564
4 files changed
+64
-26
No files matched your search
+20
-13
@@ -89,7 +89,12 @@ func TestTranslate(t *testing.T) {
|
||||
{
|
||||
cfgName: "missing_id",
|
||||
cfg: Config{},
|
||||
wantError: fmt.Errorf("rule ID is missing or empty, regex: (?i)(discord[a-z0-9_ .\\-,]{0,25})(=|>|:=|\\|\\|:|<=|=>|:).{0,5}['\\\"]([a-h0-9]{64})['\\\"]"),
|
||||
wantError: fmt.Errorf("rule |id| is missing or empty, regex: (?i)(discord[a-z0-9_ .\\-,]{0,25})(=|>|:=|\\|\\|:|<=|=>|:).{0,5}['\\\"]([a-h0-9]{64})['\\\"]"),
|
||||
},
|
||||
{
|
||||
cfgName: "no_regex_or_path",
|
||||
cfg: Config{},
|
||||
wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
|
||||
},
|
||||
{
|
||||
cfgName: "bad_entropy_group",
|
||||
@@ -127,18 +132,20 @@ func TestTranslate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
viper.Reset()
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName(tt.cfgName)
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
t.Run(tt.cfgName, func(t *testing.T) {
|
||||
viper.Reset()
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName(tt.cfgName)
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
var vc ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, err := vc.Translate()
|
||||
assert.Equal(t, tt.wantError, err)
|
||||
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
||||
var vc ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, err := vc.Translate()
|
||||
assert.Equal(t, tt.wantError, err)
|
||||
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user