-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathintegration_test.go
56 lines (45 loc) · 1.3 KB
/
integration_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
// +build integration
package finto
import (
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/stretchr/testify/assert"
)
func setupIntegrationTest() (rc *RoleSet) {
client := sts.New(
session.New(),
&aws.Config{Credentials: credentials.NewEnvCredentials()},
)
rc = NewRoleSet(client)
rc.SetRole("valid", os.Getenv("FINTO_VALID_ARN"))
rc.SetRole("invalid", os.Getenv("FINTO_INVALID_ARN"))
return
}
func TestSTSClientAssumeRole(t *testing.T) {
rc := setupIntegrationTest()
role, err := rc.Role("valid")
if assert.NoError(t, err) {
creds, _ := role.Credentials()
assert.NotEmpty(t, creds.AccessKeyId)
assert.NotEmpty(t, creds.Expiration)
assert.NotEmpty(t, creds.SecretAccessKey)
assert.NotEmpty(t, creds.SessionToken)
assert.False(t, creds.IsExpired(), "Fresh credentials should not be expired")
}
}
func TestSTSClientAssumeRoleFailure(t *testing.T) {
rc := setupIntegrationTest()
role, err := rc.Role("invalid")
creds, err := role.Credentials()
if assert.Error(t, err) {
assert.Empty(t, creds.AccessKeyId)
assert.Equal(t, time.Time{}, creds.Expiration)
assert.Empty(t, creds.SecretAccessKey)
assert.Empty(t, creds.SessionToken)
}
}