-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_test.go
More file actions
63 lines (51 loc) · 1.79 KB
/
Copy pathexample_test.go
File metadata and controls
63 lines (51 loc) · 1.79 KB
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
package portcullis_test
import (
"fmt"
"github.com/docker/portcullis"
)
// ghpFixture is a syntactically valid GitHub PAT (correct CRC32 over the
// 30-char body), built at runtime so the literal token never appears on a
// single source line — push protection would otherwise reject the push.
var ghpFixture = "ghp_" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "0uCPlr"
func ExampleRedact() {
log := "Run this with token=" + ghpFixture + " please."
fmt.Println(portcullis.Redact(log))
// Output:
// Run this with token=[REDACTED] please.
}
func ExampleRedact_connectionString() {
// Connection-string rules redact only the password span so the
// surrounding URL stays useful for log readers.
uri := "postgresql://app:hunter2supersecret@db.internal:5432/orders"
fmt.Println(portcullis.Redact(uri))
// Output:
// postgresql://app:[REDACTED]@db.internal:5432/orders
}
func ExampleRedact_multipleSecrets() {
other := "ghp_" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "1rpRcy"
in := "first " + ghpFixture + " and second " + other + " end"
fmt.Println(portcullis.Redact(in))
// Output:
// first [REDACTED] and second [REDACTED] end
}
func ExampleContains() {
fmt.Println(portcullis.Contains("hello world"))
fmt.Println(portcullis.Contains("token=" + ghpFixture))
// Output:
// false
// true
}
func ExampleFind() {
// Demonstrated with an AWS access key + a Postgres password so the
// expected-output comment doesn't have to contain a checksum-valid
// GitHub PAT (which push protection would block).
awsKey := "AKIA" + "RZPUZDIKQEXAMPLE"
in := "first " + awsKey + " then " +
"postgresql://app:hunter2supersecret@db.internal/orders"
for _, m := range portcullis.Find(in) {
fmt.Printf("%d-%d: %s\n", m.Start, m.End, m.Value)
}
// Output:
// 6-26: AKIARZPUZDIKQEXAMPLE
// 49-67: hunter2supersecret
}