-
Notifications
You must be signed in to change notification settings - Fork 563
/
saml_test.go
97 lines (73 loc) · 2.23 KB
/
saml_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
92
93
94
95
96
97
package saml2aws
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestExtractAwsRoles(t *testing.T) {
data, err := os.ReadFile("testdata/assertion.xml")
assert.Nil(t, err)
roles, err := ExtractAwsRoles(data)
assert.Nil(t, err)
assert.Len(t, roles, 2)
}
func TestExtractAwsRolesFail(t *testing.T) {
data, err := os.ReadFile("testdata/notxml.xml")
assert.Nil(t, err)
_, err = ExtractAwsRoles(data)
assert.Error(t, err)
}
func TestExtractSessionDuration(t *testing.T) {
data, err := os.ReadFile("testdata/assertion.xml")
assert.Nil(t, err)
duration, err := ExtractSessionDuration(data)
assert.Nil(t, err)
assert.Equal(t, int64(28800), duration)
}
func TestExtractSessionDurationFail(t *testing.T) {
data, err := os.ReadFile("testdata/notxml.xml")
assert.Nil(t, err)
_, err = ExtractSessionDuration(data)
assert.Error(t, err)
}
func TestExtractDestinationURL(t *testing.T) {
data, err := os.ReadFile("testdata/assertion.xml")
assert.Nil(t, err)
destination, err := ExtractDestinationURL(data)
assert.Nil(t, err)
assert.Equal(t, "https://signin.aws.amazon.com/saml", destination)
}
func TestExtractDestinationURLFail(t *testing.T) {
data, err := os.ReadFile("testdata/notxml.xml")
assert.Nil(t, err)
_, err = ExtractDestinationURL(data)
assert.Error(t, err)
}
func TestExtractDestinationURL2(t *testing.T) {
data, err := os.ReadFile("testdata/assertion_no_destination.xml")
assert.Nil(t, err)
destination, err := ExtractDestinationURL(data)
assert.Nil(t, err)
assert.Equal(t, "https://signin.aws.amazon.com/saml", destination)
}
func TestExtractMFATokenDuration(t *testing.T) {
data, err := os.ReadFile("testdata/assertion.xml")
assert.Nil(t, err)
timeObject, err := ExtractMFATokenExpiryTime(data)
assert.Nil(t, err)
assert.Equal(t, "2016-09-10T02:59:39Z", timeObject.Format(time.RFC3339))
}
func TestExtractMFATokenDurationFail(t *testing.T) {
data, err := os.ReadFile("testdata/notxml.xml")
assert.Nil(t, err)
_, err = ExtractMFATokenExpiryTime(data)
assert.Error(t, err)
}
func TestExtractMFATokenDuration2(t *testing.T) {
data, err := os.ReadFile("testdata/assertion_invalid_date.xml")
assert.Nil(t, err)
_, err = ExtractMFATokenExpiryTime(data)
t.Log(err)
assert.NotNil(t, err)
}