forked from gitleaks/gitleaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_test.go
68 lines (61 loc) · 1.33 KB
/
repo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"os"
"testing"
)
func TestNewRepo(t *testing.T) {
// local mode
r := newRepo("repo", "", "some/repo")
if r.name != "repo" || r.path != "some/repo" {
t.Error()
}
// repo/owner mode
r = newRepo("repo", "github.com/owner/repo", "some/repo")
if r.name != "repo" || r.path != "some/repo" {
t.Error()
}
}
func TestWriteReport(t *testing.T) {
opts, _ = defaultOptions()
r := newRepo("fakerepo", "github.com", "")
r.leaks = []Leak{*sampleLeak(), *sampleLeak()}
r.writeReport(r.leaks)
if _, err := os.Stat("fakerepo_leaks.json"); os.IsNotExist(err) {
t.Error()
} else {
os.Remove("fakerepo_leaks.json")
}
}
func TestAudit(t *testing.T) {
opts, _ = defaultOptions()
opts.RepoMode = true
opts.Tmp = true
opts.URL = "https://github.com/zricethezav/gronit"
owner := newOwner()
r := newRepo("gronit", opts.URL, owner.path)
leaksPst, _ := r.audit()
if !leaksPst {
// TODO setup actual test repo
t.Error()
}
// new owner
opts.URL = "https://github.com/kelseyhightower/nocode"
owner = newOwner()
r = newRepo("nocode", opts.URL, owner.path)
leaksPst, _ = r.audit()
if leaksPst {
t.Error()
}
}
func sampleLeak() *Leak {
return &Leak{
Line: "yoo",
Commit: "mycommit",
Offender: "oh boy",
Reason: "hello",
Msg: "msg",
Time: "time",
Author: "lol",
RepoURL: "yooo",
}
}