-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoauth_test.go
74 lines (70 loc) · 1.94 KB
/
oauth_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
package ngroklistener
import (
"testing"
"github.com/stretchr/testify/require"
"golang.ngrok.com/ngrok/config"
)
func TestOAuth(t *testing.T) {
cases := genericNgrokTestCases[*oauth]{
{
name: "absent",
caddyInput: `{}`,
expectUnmarshalErr: true,
},
{
name: "simple",
caddyInput: `{
provider google
}`,
expectConfig: func(t *testing.T, actual *oauth) {
require.Equal(t, actual.Provider, "google")
},
expectedOptsFunc: func(t *testing.T, actual *oauth) {
require.NotNil(t, actual.opt)
require.Equal(t,
config.HTTPEndpoint(actual.opt),
config.HTTPEndpoint(config.WithOAuth("google")),
)
},
},
{
name: "with options",
caddyInput: `{
provider google
scopes foo
scopes bar baz
allow_domains ngrok.com google.com
allow_domains github.com facebook.com
allow_emails user1@gmail.com user2@gmail.com
allow_emails user3@gmail.com
}`,
expectConfig: func(t *testing.T, actual *oauth) {
require.Equal(t, actual.Provider, "google")
require.ElementsMatch(t, actual.Scopes, []string{"foo", "bar", "baz"})
require.ElementsMatch(t, actual.AllowDomains, []string{"ngrok.com", "google.com", "github.com", "facebook.com"})
require.ElementsMatch(t, actual.AllowEmails, []string{"user1@gmail.com", "user2@gmail.com", "user3@gmail.com"})
},
expectedOptsFunc: func(t *testing.T, actual *oauth) {
require.NotNil(t, actual.opt)
require.Equal(t,
config.HTTPEndpoint(actual.opt),
config.HTTPEndpoint(
config.WithOAuth("google",
config.WithAllowOAuthDomain("ngrok.com", "google.com", "github.com", "facebook.com"),
config.WithAllowOAuthEmail("user1@gmail.com", "user2@gmail.com", "user3@gmail.com"),
config.WithOAuthScope("foo", "bar", "baz"),
),
),
)
},
},
{
name: "unsupported directive",
caddyInput: `{
directive
}`,
expectUnmarshalErr: true,
},
}
cases.runAll(t)
}