mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 04:34:46 +01:00
Add line number to report plus some other things (#409)
* Init refactor * think i got it working * we got em * Updating tests * fixing tests * Better comments, more test fixing * Bumping to v5 * Fixing golint messages * Replacing usage of audit with scan in comments * bumping go-git * Updating to v5 in some other spots
This commit is contained in:
1 parent
cfbb600fcb
commit
6ca7a11d88
50 files changed
+1483
-1167
No files matched your search
+12
-10
@@ -14,8 +14,8 @@ import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v4/config"
|
||||
"github.com/zricethezav/gitleaks/v4/options"
|
||||
"github.com/zricethezav/gitleaks/v5/config"
|
||||
"github.com/zricethezav/gitleaks/v5/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/hako/durafmt"
|
||||
@@ -48,6 +48,7 @@ type Manager struct {
|
||||
// sensitive information as determined by the rules set in a gitleaks config
|
||||
type Leak struct {
|
||||
Line string `json:"line"`
|
||||
LineNumber int `json:"lineNumber"`
|
||||
Offender string `json:"offender"`
|
||||
Commit string `json:"commit"`
|
||||
Repo string `json:"repo"`
|
||||
@@ -58,13 +59,14 @@ type Leak struct {
|
||||
File string `json:"file"`
|
||||
Date time.Time `json:"date"`
|
||||
Tags string `json:"tags"`
|
||||
Operation string `json:"operation"`
|
||||
lookupHash string
|
||||
}
|
||||
|
||||
// AuditTime is a type used to determine total audit time
|
||||
// AuditTime is a type used to determine total scan time
|
||||
type AuditTime int64
|
||||
|
||||
// PatchTime is a type used to determine total patch time during an audit
|
||||
// PatchTime is a type used to determine total patch time during an scan
|
||||
type PatchTime int64
|
||||
|
||||
// CloneTime is a type used to determine total clone time
|
||||
@@ -78,7 +80,7 @@ type RegexTime struct {
|
||||
Regex string
|
||||
}
|
||||
|
||||
// Metadata is a struct used to communicate metadata about an audit like timings and total commit counts.
|
||||
// Metadata is a struct used to communicate metadata about an scan like timings and total commit counts.
|
||||
type Metadata struct {
|
||||
mux *sync.Mutex
|
||||
data map[string]interface{}
|
||||
@@ -147,7 +149,7 @@ func (manager *Manager) GetLeaks() []Leak {
|
||||
return manager.leaks
|
||||
}
|
||||
|
||||
// SendLeaks accepts a leak and is used by the audit pkg. This is the public function
|
||||
// SendLeaks accepts a leak and is used by the scan pkg. This is the public function
|
||||
// that allows other packages to send leaks to the manager.
|
||||
func (manager *Manager) SendLeaks(l Leak) {
|
||||
if len(l.Line) > maxLineLen {
|
||||
@@ -157,7 +159,7 @@ func (manager *Manager) SendLeaks(l Leak) {
|
||||
l.Offender = l.Offender[0:maxLineLen-1] + "..."
|
||||
}
|
||||
h := sha1.New()
|
||||
h.Write([]byte(l.Commit + l.Offender + l.File + l.Line))
|
||||
h.Write([]byte(l.Commit + l.Offender + l.File + l.Line + string(l.LineNumber)))
|
||||
l.lookupHash = hex.EncodeToString(h.Sum(nil))
|
||||
if manager.Opts.Redact {
|
||||
l.Line = strings.ReplaceAll(l.Line, l.Offender, "REDACTED")
|
||||
@@ -223,7 +225,7 @@ func (manager *Manager) receiveMetadata() {
|
||||
}
|
||||
}
|
||||
|
||||
// IncrementCommits increments total commits during an audit by i.
|
||||
// IncrementCommits increments total commits during an scan by i.
|
||||
func (manager *Manager) IncrementCommits(i int) {
|
||||
manager.metadata.mux.Lock()
|
||||
manager.metadata.Commits += i
|
||||
@@ -236,7 +238,7 @@ func (manager *Manager) RecordTime(t interface{}) {
|
||||
manager.metadata.timings <- t
|
||||
}
|
||||
|
||||
// DebugOutput logs metadata and other messages that occurred during a gitleaks audit
|
||||
// DebugOutput logs metadata and other messages that occurred during a gitleaks scan
|
||||
func (manager *Manager) DebugOutput() {
|
||||
log.Debugf("-------------------------\n")
|
||||
log.Debugf("| Times and Commit Counts|\n")
|
||||
@@ -308,6 +310,6 @@ func (manager *Manager) receiveInterrupt() {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
log.Info("gitleaks received interrupt, stopping audit")
|
||||
log.Info("gitleaks received interrupt, stopping scan")
|
||||
os.Exit(options.ErrorEncountered)
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package manager
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"github.com/zricethezav/gitleaks/v4/config"
|
||||
"github.com/zricethezav/gitleaks/v4/options"
|
||||
"github.com/zricethezav/gitleaks/v5/config"
|
||||
"github.com/zricethezav/gitleaks/v5/options"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
@@ -45,14 +45,14 @@ func TestSendReceiveLeaks(t *testing.T) {
|
||||
|
||||
func TestSendReceiveMeta(t *testing.T) {
|
||||
tests := []struct {
|
||||
auditTime int64
|
||||
scanTime int64
|
||||
patchTime int64
|
||||
cloneTime int64
|
||||
regexTime int64
|
||||
iterations int
|
||||
}{
|
||||
{
|
||||
auditTime: 1000,
|
||||
scanTime: 1000,
|
||||
patchTime: 1000,
|
||||
cloneTime: 1000,
|
||||
regexTime: 1000,
|
||||
@@ -65,7 +65,7 @@ func TestSendReceiveMeta(t *testing.T) {
|
||||
m, _ := NewManager(opts, cfg)
|
||||
|
||||
for i := 0; i < test.iterations; i++ {
|
||||
m.RecordTime(AuditTime(test.auditTime))
|
||||
m.RecordTime(AuditTime(test.scanTime))
|
||||
m.RecordTime(PatchTime(test.patchTime))
|
||||
m.RecordTime(CloneTime(test.cloneTime))
|
||||
m.RecordTime(RegexTime{
|
||||
@@ -82,9 +82,9 @@ func TestSendReceiveMeta(t *testing.T) {
|
||||
t.Errorf("clone time mismatch, got %d, wanted %d",
|
||||
md.cloneTime, test.cloneTime*int64(test.iterations))
|
||||
}
|
||||
if md.AuditTime != test.auditTime*int64(test.iterations) {
|
||||
t.Errorf("audit time mismatch, got %d, wanted %d",
|
||||
md.AuditTime, test.auditTime*int64(test.iterations))
|
||||
if md.AuditTime != test.scanTime*int64(test.iterations) {
|
||||
t.Errorf("scan time mismatch, got %d, wanted %d",
|
||||
md.AuditTime, test.scanTime*int64(test.iterations))
|
||||
}
|
||||
if md.patchTime != test.patchTime*int64(test.iterations) {
|
||||
t.Errorf("clone time mismatch, got %d, wanted %d",
|
||||
|
||||
Reference in new issue
Block a user