mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
fix: format dates in log in a portable way (#735)
The output of time.String() depends on the runtime environment and should only be used for debugging. This commit ensures that a well-defined UTC time is written to the report.
This commit is contained in:
1 parent
98d5648f6e
commit
106897fdf0
2 files changed
+5
-2
No files matched your search
+2
-1
@@ -3,6 +3,7 @@ package detect
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -70,7 +71,7 @@ func FromGit(files <-chan *gitdiff.File, cfg config.Config, outputOptions Option
|
|||||||
fi.Author = f.PatchHeader.Author.Name
|
fi.Author = f.PatchHeader.Author.Name
|
||||||
fi.Email = f.PatchHeader.Author.Email
|
fi.Email = f.PatchHeader.Author.Email
|
||||||
}
|
}
|
||||||
fi.Date = f.PatchHeader.AuthorDate.String()
|
fi.Date = f.PatchHeader.AuthorDate.UTC().Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
|
|
||||||
if outputOptions.Redact {
|
if outputOptions.Redact {
|
||||||
|
|||||||
+3
-1
@@ -42,6 +42,7 @@ func TestFromGit(t *testing.T) {
|
|||||||
Secret: "AKIALALEMEL33243OLIA",
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
File: "main.go",
|
File: "main.go",
|
||||||
// Line: "\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
// Line: "\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||||
|
Date: "2021-11-02T23:37:53Z",
|
||||||
Commit: "1b6da43b82b22e4eaa10bcf8ee591e91abbfc587",
|
Commit: "1b6da43b82b22e4eaa10bcf8ee591e91abbfc587",
|
||||||
Author: "Zachary Rice",
|
Author: "Zachary Rice",
|
||||||
Email: "zricer@protonmail.com",
|
Email: "zricer@protonmail.com",
|
||||||
@@ -58,6 +59,7 @@ func TestFromGit(t *testing.T) {
|
|||||||
Secret: "AKIALALEMEL33243OLIA",
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
File: "foo/foo.go",
|
File: "foo/foo.go",
|
||||||
// Line: "\taws_token := \"AKIALALEMEL33243OLIA\"",
|
// Line: "\taws_token := \"AKIALALEMEL33243OLIA\"",
|
||||||
|
Date: "2021-11-02T23:48:06Z",
|
||||||
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
||||||
Author: "Zach Rice",
|
Author: "Zach Rice",
|
||||||
Email: "zricer@protonmail.com",
|
Email: "zricer@protonmail.com",
|
||||||
@@ -81,6 +83,7 @@ func TestFromGit(t *testing.T) {
|
|||||||
EndColumn: 36,
|
EndColumn: 36,
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
// Line: "\taws_token := \"AKIALALEMEL33243OLIA\"",
|
// Line: "\taws_token := \"AKIALALEMEL33243OLIA\"",
|
||||||
|
Date: "2021-11-02T23:48:06Z",
|
||||||
File: "foo/foo.go",
|
File: "foo/foo.go",
|
||||||
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
||||||
Author: "Zach Rice",
|
Author: "Zach Rice",
|
||||||
@@ -120,7 +123,6 @@ func TestFromGit(t *testing.T) {
|
|||||||
findings := FromGit(files, cfg, tt.opts)
|
findings := FromGit(files, cfg, tt.opts)
|
||||||
for _, f := range findings {
|
for _, f := range findings {
|
||||||
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
||||||
f.Date = ""
|
|
||||||
}
|
}
|
||||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user