Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix extra log messages (#1253)
Zachary Rice458c79165af9
diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.goindex 14f552fcc..7fb3e0e0d 100644--- a/pkg/gitparse/gitparse.go+++ b/pkg/gitparse/gitparse.go@@ -193,6 +193,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan choutReader := bufio.NewReader(stdOut)var currentCommit *Commitvar currentDiff *Diff+ var recentlyPassedAuthor booldefer common.RecoverWithExit(ctx)defer close(commitChan)@@ -225,6 +226,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch}case isAuthorLine(line):currentCommit.Author = strings.TrimRight(string(line[8:]), "\n")+ recentlyPassedAuthor = truecase isDateLine(line):date, err := time.Parse(c.dateFormat, strings.TrimSpace(string(line[6:])))if err != nil {@@ -261,6 +263,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chcase isModeLine(line):// NoOpcase isIndexLine(line):+ recentlyPassedAuthor = false// NoOpcase isPlusFileLine(line):currentDiff.PathB = strings.TrimRight(strings.TrimRight(string(line[6:]), "\n"), "\t") // Trim the newline and tab characters. https://github.com/trufflesecurity/trufflehog/issues/1060@@ -271,7 +274,9 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chcase isMinusDiffLine(line):// NoOp. We only care about additions.case isMessageLine(line):- currentCommit.Message.Write(line[4:])+ if recentlyPassedAuthor {+ currentCommit.Message.Write(line[4:])+ }case isContextDiffLine(line):currentDiff.Content.Write([]byte("\n"))case isBinaryLine(line):diff --git a/pkg/gitparse/gitparse_test.go b/pkg/gitparse/gitparse_test.goindex 220587bf7..fb4071821 100644--- a/pkg/gitparse/gitparse_test.go+++ b/pkg/gitparse/gitparse_test.go@@ -2,6 +2,7 @@ package gitparseimport ("bytes"+ "fmt""strings""testing""time"@@ -228,6 +229,38 @@ func TestMaxCommitSize(t *testing.T) {}+func TestMessageParsing(t *testing.T) {+ r := bytes.NewReader([]byte(fmt.Sprintf(singleCommitTabbedContent, ` `)))+ commitChan := make(chan Commit)+ parser := NewParser()+ expectedMessage := singleCommitSingleDiffMessage++ go func() {+ parser.FromReader(context.TODO(), r, commitChan)+ }()+ for commit := range commitChan {+ if commit.Message.String() != expectedMessage {+ t.Errorf("Message does not match. Got:\n%s\nexpected:\n%s", commit.Message.String(), expectedMessage)+ }+ }+}++const singleCommitTabbedContent = `commit 70001020fab32b1fcf2f1f0e5c66424eae649826 (HEAD -> master, origin/master, origin/HEAD)+Author: Dustin Decker <[email protected]>+Date: Mon Mar 15 23:27:16 2021 -0700++ Update aws++diff --git a/aws b/aws+index 2ee133b..12b4843 100644+--- a/aws++++ b/aws+@@ -1,7 +1,5 @@++[default]+%saws_access_key_id = AKIAXYZDQCEN4B6JSJQI++aws_secret_access_key = Tg0pz8Jii8hkLx4+PnUisM8GmKs3a2DK+9qz/lie+`+const singleCommitSingleDiff = `commit 70001020fab32b1fcf2f1f0e5c66424eae649826 (HEAD -> master, origin/master, origin/HEAD)Author: Dustin Decker <[email protected]>Date: Mon Mar 15 23:27:16 2021 -0700