forked from aliyun/saml2alibabacloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalibabacloud_account_test.go
81 lines (65 loc) · 2.12 KB
/
alibabacloud_account_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
package saml2alibabacloud
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtractAlibabaCloudAccounts(t *testing.T) {
data, err := ioutil.ReadFile("testdata/saml.html")
assert.Nil(t, err)
accounts, err := ExtractAlibabaCloudAccounts(data)
assert.Nil(t, err)
assert.Len(t, accounts, 2)
account := accounts[0]
assert.Equal(t, account.Name, "000000000001(000000000001)")
assert.Len(t, account.Roles, 2)
role := account.Roles[0]
assert.Equal(t, role.RoleARN, "acs:ram::000000000001:role/Development")
assert.Equal(t, role.Name, "Development")
role = account.Roles[1]
assert.Equal(t, role.RoleARN, "acs:ram::000000000001:role/Production")
assert.Equal(t, role.Name, "Production")
account = accounts[1]
assert.Equal(t, account.Name, "sharedservices(000000000002)")
assert.Len(t, account.Roles, 2)
role = account.Roles[0]
assert.Equal(t, role.RoleARN, "acs:ram::000000000002:role/Development")
assert.Equal(t, role.Name, "Development")
role = account.Roles[1]
assert.Equal(t, role.RoleARN, "acs:ram::000000000002:role/Production")
assert.Equal(t, role.Name, "Production")
}
func TestAssignPrincipals(t *testing.T) {
ramRoles := []*RamRole{
{
PrincipalARN: "acs:ram::000000000001:saml-provider/test-idp",
RoleARN: "acs:ram::000000000001:role/Development",
},
}
alibabacloudAccounts := []*AlibabaCloudAccount{
{
Roles: []*RamRole{
{
RoleARN: "acs:ram::000000000001:role/Development",
},
},
},
}
AssignPrincipals(ramRoles, alibabacloudAccounts)
assert.Equal(t, "acs:ram::000000000001:saml-provider/test-idp", alibabacloudAccounts[0].Roles[0].PrincipalARN)
}
func TestLocateRole(t *testing.T) {
ramRoles := []*RamRole{
{
PrincipalARN: "acs:ram::000000000001:saml-provider/test-idp",
RoleARN: "acs:ram::000000000001:role/Development",
},
{
PrincipalARN: "acs:ram::000000000002:saml-provider/test-idp",
RoleARN: "acs:ram::000000000002:role/Development",
},
}
role, err := LocateRole(ramRoles, "acs:ram::000000000001:role/Development")
assert.Empty(t, err)
assert.Equal(t, "acs:ram::000000000001:role/Development", role.RoleARN)
}