This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cred-filter_test.go
90 lines (71 loc) · 2.91 KB
/
cred-filter_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main_test
import (
"os/exec"
"strings"
"github.com/onsi/gomega/gexec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("CredFilter", func() {
Context("Output to stderr instead", func() {
It("sends output to stderr instead", func() {
command := exec.Command(path, "-stderr")
command.Env = []string{"BORING=boring"}
command.Stdin = strings.NewReader("boring text")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(session.Out.Contents()).To(BeEmpty())
Expect(string(session.Err.Contents())).To(Equal("[redacted BORING] text"))
})
})
Context("No sensitive credentials available", func() {
It("outputs as is", func() {
command := exec.Command(path)
command.Env = []string{}
command.Stdin = strings.NewReader("boring text")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal("boring text"))
Expect(session.Err.Contents()).To(BeEmpty())
})
})
Context("Sensitive credentials available", func() {
It("filters out those credentials", func() {
command := exec.Command(path)
command.Env = []string{"SECRET=secret", "INFO=info"}
command.Stdin = strings.NewReader("super secret info\nnew line")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal("super [redacted SECRET] [redacted INFO]\nnew line"))
Expect(session.Err.Contents()).To(BeEmpty())
})
Context("sensitive credential env var is whitelisted", func() {
It("filters out non-white-listed credentials", func() {
command := exec.Command(path)
command.Env = []string{"SECRET=secret", "INFO=info", "CREDENTIAL_FILTER_WHITELIST=OTHER1,INFO,OTHER2"}
command.Stdin = strings.NewReader("super secret info")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal("super [redacted SECRET] info"))
Expect(session.Err.Contents()).To(BeEmpty())
})
})
Context("the buffer can handle a 256k string", func() {
It("doesn't crash", func() {
command := exec.Command(path)
command.Env = []string{"SECRET=secret", "INFO=info", "CREDENTIAL_FILTER_WHITELIST=OTHER1,INFO,OTHER2"}
input := string(make([]byte, 256*1024))
command.Stdin = strings.NewReader(input)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(input))
Expect(session.Err.Contents()).To(BeEmpty())
})
})
})
})