forked from b-b3rn4rd/awscli-console-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_test.go
91 lines (82 loc) · 2.22 KB
/
console_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
91
package main
import (
"testing"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/stretchr/testify/assert"
)
func TestSigninUrl(t *testing.T) {
cmd := Console{}
tests := map[string]struct {
request struct {
credentials credentials.Value
timeout string
}
response string
err error
}{
"timeout_is_ignored_for_sts": {
response: "https://signin.aws.amazon.com/federation?Action=getSigninToken&Session=%7B%22sessionId%22%3A%22key%22%2C%22sessionKey%22%3A%22secret%22%2C%22sessionToken%22%3A%22token%22%7D",
err: nil,
request: struct {
credentials credentials.Value
timeout string
}{
credentials: credentials.Value{
AccessKeyID: "key",
SecretAccessKey: "secret",
SessionToken: "token",
},
timeout: "1",
},
},
"timeout_is_passed_for_iam_creds": {
response: "https://signin.aws.amazon.com/federation?Action=getSigninToken&Session=%7B%22sessionId%22%3A%22key%22%2C%22sessionKey%22%3A%22secret%22%2C%22sessionToken%22%3A%22%22%7D&SessionDuration=1",
err: nil,
request: struct {
credentials credentials.Value
timeout string
}{
credentials: credentials.Value{
AccessKeyID: "key",
SecretAccessKey: "secret",
},
timeout: "1",
},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
r, err := cmd.signinURL(test.request.credentials, test.request.timeout)
assert.Equal(t, test.response, r)
assert.Equal(t, test.err, err)
})
}
}
func TestConsoleUrl(t *testing.T) {
cmd := Console{}
tests := map[string]struct {
request struct {
signinToken string
destinationUrl string
}
response string
err error
}{
"siginurl_is_returned_as_expected": {
response: "https://signin.aws.amazon.com/federation?Action=login&Destination=http%3A%2F%2Fgoogle.com.au&Issuer=awscli-console-plugin&SigninToken=token",
request: struct {
signinToken string
destinationUrl string
}{
signinToken: "token",
destinationUrl: "http://google.com.au",
},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
r := cmd.consoleURL(test.request.signinToken, test.request.destinationUrl)
assert.Equal(t, test.response, r)
})
}
}