-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathauth_test.go
70 lines (61 loc) · 1.31 KB
/
auth_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
package auth
import (
"os"
"testing"
)
func TestAuthResolver(t *testing.T) {
strategies := []string{
"azurecert",
"azurecreds",
"device",
"addin",
"adfs",
"fba",
"ntlm",
"saml",
"tmg",
}
for _, strategy := range strategies {
t.Run(strategy, func(t *testing.T) {
cnfg, err := NewAuthByStrategy(strategy)
if err != nil {
t.Error(err)
}
if cnfg.GetStrategy() != strategy {
t.Errorf("strategy should be %s, but %s", strategy, cnfg.GetStrategy())
}
})
}
}
func TestAuthResolverError(t *testing.T) {
_, err := NewAuthByStrategy("unknown")
if err == nil {
t.Error("should return an error")
}
}
func TestAuthFileResolver(t *testing.T) {
// Create temp file with auth config
file, err := os.CreateTemp("", "private.json")
if err != nil {
t.Error(err)
}
defer os.Remove(file.Name())
// Write auth config to the file
_, err = file.Write([]byte(`{
"strategy": "saml",
"siteUrl": "https://contoso.sharepoint.com",
"username": "[email protected]",
"password": "00000000-0000-0000-0000-000000000000"
}`))
if err != nil {
t.Error(err)
}
// Resolve auth config from the file
cnfg, err := NewAuthFromFile(file.Name())
if err != nil {
t.Error(err)
}
if cnfg.GetStrategy() != "saml" {
t.Errorf("strategy should be saml, but %s", cnfg.GetStrategy())
}
}