mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
more cleaningup
This commit is contained in:
1 parent
c53e0fc98d
commit
c98afd3dec
3 files changed
+2
-53
No files matched your search
@@ -82,7 +82,6 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if noGit {
|
if noGit {
|
||||||
// TODO treat the repo as a directory
|
|
||||||
findings, err = detector.DetectFiles(source)
|
findings, err = detector.DetectFiles(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// don't exit on error, just log it
|
// don't exit on error, just log it
|
||||||
|
|||||||
@@ -115,53 +115,3 @@ func TestTranslate(t *testing.T) {
|
|||||||
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIncludeEntropy(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
rule Rule
|
|
||||||
secret string
|
|
||||||
entropy float32
|
|
||||||
include bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 3.5,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5`,
|
|
||||||
entropy: 3.7906235872459746,
|
|
||||||
include: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 4,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5`,
|
|
||||||
entropy: 3.7906235872459746,
|
|
||||||
include: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 3.0,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `ssh-keyboard-interactive`,
|
|
||||||
entropy: 0,
|
|
||||||
include: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
include, entropy := tt.rule.IncludeEntropy(tt.secret)
|
|
||||||
assert.Equal(t, true, tt.rule.EntropySet())
|
|
||||||
assert.Equal(t, tt.entropy, float32(entropy))
|
|
||||||
assert.Equal(t, tt.include, include)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -180,8 +180,8 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
|
|||||||
// NOTE: this is a goofy hack to get around the fact there golang's regex engine
|
// NOTE: this is a goofy hack to get around the fact there golang's regex engine
|
||||||
// does not support positive lookaheads. Ideally we would want to add a
|
// does not support positive lookaheads. Ideally we would want to add a
|
||||||
// restriction on generic rules regex that requires the secret match group
|
// restriction on generic rules regex that requires the secret match group
|
||||||
// contains both numbers and alphabetical characters. What this bit of code does is
|
// contains both numbers and alphabetical characters, not just alphabetical characters.
|
||||||
// check if the ruleid is prepended with "generic" and enforces the
|
// What this bit of code does is check if the ruleid is prepended with "generic" and enforces the
|
||||||
// secret contains both digits and alphabetical characters.
|
// secret contains both digits and alphabetical characters.
|
||||||
// TODO: this should be replaced with stop words
|
// TODO: this should be replaced with stop words
|
||||||
if strings.HasPrefix(rule.RuleID, "generic") {
|
if strings.HasPrefix(rule.RuleID, "generic") {
|
||||||
|
|||||||
Reference in new issue
Block a user