Skip to content

Commit 46e5fd8

Browse files
committed
add authority configuration tests
1 parent d3672b6 commit 46e5fd8

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

authority_configuration_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package entraid
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestAuthorityConfiguration(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
authorityType string
13+
tenantID string
14+
authority string
15+
expected string
16+
expectError bool
17+
}{
18+
{
19+
name: "Default Authority",
20+
authorityType: AuthorityTypeDefault,
21+
expected: "https://login.microsoftonline.com/common",
22+
expectError: false,
23+
},
24+
{
25+
name: "Multi-Tenant Authority",
26+
authorityType: AuthorityTypeMultiTenant,
27+
tenantID: "12345",
28+
expected: "https://login.microsoftonline.com/12345",
29+
expectError: false,
30+
},
31+
{
32+
name: "Custom Authority",
33+
authorityType: AuthorityTypeCustom,
34+
authority: "https://custom-authority.com",
35+
expected: "https://custom-authority.com",
36+
expectError: false,
37+
},
38+
}
39+
40+
for _, test := range tests {
41+
t.Run(test.name, func(t *testing.T) {
42+
ac := AuthorityConfiguration{
43+
AuthorityType: test.authorityType,
44+
TenantID: test.tenantID,
45+
Authority: test.authority,
46+
}
47+
result, err := ac.getAuthority()
48+
if test.expectError {
49+
assert.Error(t, err)
50+
} else {
51+
assert.NoError(t, err)
52+
assert.Equal(t, test.expected, result)
53+
}
54+
})
55+
}
56+
}
57+
58+
func TestAuthorityConfigurationDefault(t *testing.T) {
59+
ac := AuthorityConfiguration{}
60+
result, err := ac.getAuthority()
61+
assert.NoError(t, err)
62+
assert.Equal(t, "https://login.microsoftonline.com/common", result)
63+
}
64+
65+
func TestAuthorityConfigurationMultiTenant(t *testing.T) {
66+
ac := AuthorityConfiguration{
67+
AuthorityType: AuthorityTypeMultiTenant,
68+
TenantID: "12345",
69+
}
70+
result, err := ac.getAuthority()
71+
assert.NoError(t, err)
72+
assert.Equal(t, "https://login.microsoftonline.com/12345", result)
73+
}
74+
75+
func TestAuthorityConfigurationCustom(t *testing.T) {
76+
ac := AuthorityConfiguration{
77+
AuthorityType: AuthorityTypeCustom,
78+
Authority: "https://custom-authority.com",
79+
}
80+
result, err := ac.getAuthority()
81+
assert.NoError(t, err)
82+
assert.Equal(t, "https://custom-authority.com", result)
83+
}
84+
85+
func TestAuthorityConfigurationInvalid(t *testing.T) {
86+
ac := AuthorityConfiguration{
87+
AuthorityType: "invalid",
88+
}
89+
result, err := ac.getAuthority()
90+
assert.Error(t, err)
91+
assert.Equal(t, "", result)
92+
}
93+
94+
func TestAuthorityConfigurationMissingTenantID(t *testing.T) {
95+
ac := AuthorityConfiguration{
96+
AuthorityType: AuthorityTypeMultiTenant,
97+
}
98+
result, err := ac.getAuthority()
99+
assert.Error(t, err)
100+
assert.Equal(t, "", result)
101+
}
102+
103+
func TestAuthorityConfigurationMissingAuthority(t *testing.T) {
104+
ac := AuthorityConfiguration{
105+
AuthorityType: AuthorityTypeCustom,
106+
}
107+
result, err := ac.getAuthority()
108+
assert.Error(t, err)
109+
assert.Equal(t, "", result)
110+
}
111+
112+
func TestAuthorityConfigurationDefaultAuthorityType(t *testing.T) {
113+
ac := AuthorityConfiguration{
114+
TenantID: "12345",
115+
}
116+
result, err := ac.getAuthority()
117+
assert.NoError(t, err)
118+
assert.Equal(t, "https://login.microsoftonline.com/common", result)
119+
}
120+
121+
func TestAuthorityConfigurationDefaultAuthorityTypeWithTenantID(t *testing.T) {
122+
ac := AuthorityConfiguration{
123+
AuthorityType: AuthorityTypeDefault,
124+
TenantID: "12345",
125+
}
126+
result, err := ac.getAuthority()
127+
assert.NoError(t, err)
128+
assert.Equal(t, "https://login.microsoftonline.com/common", result)
129+
}

0 commit comments

Comments
 (0)