-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbless_test.go
78 lines (57 loc) · 1.63 KB
/
bless_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
package bless
import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/versent/bless/mocks"
)
func TestLoadPublicKey(t *testing.T) {
tfile := mustWriteTempfile("data")
data, err := LoadPublicKey(tfile.Name())
require.Nil(t, err)
require.Len(t, data, 4)
_, err = LoadPublicKey("badfile")
require.Error(t, err)
}
func TestValidatePublicKey(t *testing.T) {
data, err := ValidatePublicKey([]byte{0xa, 0xb, 0xc, 0xd})
require.Nil(t, err)
require.Len(t, data, 4)
_, err = ValidatePublicKey([]byte{})
require.Error(t, err)
}
func TestWriteCertificate(t *testing.T) {
err := WriteCertificate(fmt.Sprintf("%s/%s-%d", os.TempDir(), "abc", time.Now().Unix()), "data")
require.Nil(t, err)
err = WriteCertificate(fmt.Sprintf("nothere/%s-%d", "abc", time.Now().Unix()), "data")
require.Error(t, err)
}
func TestInvokeBlessLambda(t *testing.T) {
lambdaMock := &mocks.LambdaAPI{}
lambdaSvc = lambdaMock
result := &lambda.InvokeOutput{
StatusCode: aws.Int64(200),
Payload: []byte(`{"certificate":"data"}`),
}
lambdaMock.On("Invoke", mock.AnythingOfType("*lambda.InvokeInput")).Return(result, nil)
res, err := InvokeBlessLambda(aws.String("us-west-2"), aws.String("whatever"), []byte("whatever"))
require.Nil(t, err)
require.Len(t, res.Certificate, 4)
}
func mustWriteTempfile(data string) *os.File {
tfile, err := ioutil.TempFile(os.TempDir(), "test")
if err != nil {
panic(err)
}
_, err = tfile.WriteString("data")
if err != nil {
panic(err)
}
return tfile
}