-
Notifications
You must be signed in to change notification settings - Fork 14
/
cert_test.go
49 lines (44 loc) · 1.14 KB
/
cert_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
package executor
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIfReturnsErrorWhenNoValidCertificateFound(t *testing.T) {
testCases := []struct {
err string
env []string
}{
{"missing certificate", nil},
{"missing certificate", []string{
"ALLEGRO_PKI_SENSITIVE_VAR=xxx",
"NOT_SENSITIVE=xxx",
}},
{"missing certificate data", []string{
"ALLEGRO_PKI_SENSITIVE_VAR=xxx",
"CERTIFICATE=xxx",
"NOT_SENSITIVE=xxx",
}},
}
for _, tc := range testCases {
t.Run(tc.err, func(t *testing.T) {
cert, err := GetCertFromEnvVariables(tc.env)
assert.Nil(t, cert)
assert.EqualError(t, err, tc.err)
})
}
}
func TestIfReturnscertificateFromArgs(t *testing.T) {
pemCert, err := ioutil.ReadFile("testdata/cert.pem")
require.NoError(t, err)
cert, err := GetCertFromEnvVariables([]string{
"ALLEGRO_PKI_SENSITIVE_VAR=xxx",
"CERTIFICATE=" + string(pemCert),
"CERTIFICATE=yy",
"NOT_SENSITIVE=xxx",
})
assert.NoError(t, err)
assert.Equal(t, "Vault CA5", cert.Issuer.CommonName)
assert.Equal(t, "2017-06-13 13:53:05 +0000 UTC", cert.NotAfter.String())
}