-
Notifications
You must be signed in to change notification settings - Fork 562
/
saml2aws_test.go
70 lines (59 loc) · 1.71 KB
/
saml2aws_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 saml2aws
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/versent/saml2aws/v2/pkg/cfg"
"github.com/versent/saml2aws/v2/pkg/creds"
)
func TestProviderList_Keys(t *testing.T) {
names := MFAsByProvider.Names()
require.Len(t, names, 19)
}
func TestProviderList_Mfas(t *testing.T) {
mfas := MFAsByProvider.Mfas("Ping")
require.Len(t, mfas, 1)
}
func TestProviderInvalid(t *testing.T) {
account := &cfg.IDPAccount{
Provider: "foo1",
}
_, err := NewSAMLClient(account)
assert.ErrorContains(t, err, "Invalid provider: foo1")
}
func TestProviderAzureADInvalidMFA(t *testing.T) {
account := &cfg.IDPAccount{
Provider: "AzureAD",
}
_, err := NewSAMLClient(account)
assert.ErrorContains(t, err, "Invalid MFA type: ")
}
func TestProviderAzureADMFA(t *testing.T) {
account := &cfg.IDPAccount{
Provider: "AzureAD",
MFA: "PhoneAppOTP",
}
client, err := NewSAMLClient(account)
assert.Nil(t, err)
loginDetails := &creds.LoginDetails{Username: "testuser", Password: "testtestlol", URL: "https://id.example.com", MFAToken: "123456"}
err = client.Validate(loginDetails)
assert.Nil(t, err)
}
func TestProviderPingNTLMInvalidMFA(t *testing.T) {
account := &cfg.IDPAccount{
Provider: "PingNTLM",
}
_, err := NewSAMLClient(account)
assert.ErrorContains(t, err, "Invalid MFA type: ")
}
func TestProviderPingNTLMMFA(t *testing.T) {
account := &cfg.IDPAccount{
Provider: "PingNTLM",
MFA: "Auto",
}
client, err := NewSAMLClient(account)
assert.Nil(t, err)
loginDetails := &creds.LoginDetails{Username: "testuser", Password: "testtestlol", URL: "https://id.example.com", MFAToken: "123456"}
err = client.Validate(loginDetails)
assert.Nil(t, err)
}