-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig_test.go
104 lines (84 loc) · 2.81 KB
/
config_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package oidcauth
import (
"os"
"testing"
goblin "github.com/franela/goblin"
. "github.com/onsi/gomega"
)
func TestConfig(t *testing.T) {
g := goblin.Goblin(t)
//special hook for gomega
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
g.Describe("TestConfig", func() {
g.Describe("DefaultConfig", func() {
os.Setenv("OIDC_CLIENT_ID", "client-id")
os.Setenv("OIDC_CLIENT_SECRET", "client-secret")
os.Setenv("OIDC_ISSUER_URL", "issuer-url")
os.Setenv("OIDC_REDIRECT_URL", "redirect-url")
c := DefaultConfig()
g.It("should retrieve values from env", func() {
Expect(c.ClientID).To(BeEquivalentTo("client-id"))
Expect(c.ClientSecret).To(BeEquivalentTo("client-secret"))
Expect(c.IssuerURL).To(BeEquivalentTo("issuer-url"))
Expect(c.RedirectURL).To(BeEquivalentTo("redirect-url"))
})
})
g.Describe("ExampleConfigDex", func() {
c := ExampleConfigDex()
g.It("should match dex example-app config", func() {
Expect(c.ClientID).To(BeEquivalentTo("example-app"))
Expect(c.ClientSecret).To(BeEquivalentTo("ZXhhbXBsZS1hcHAtc2VjcmV0"))
Expect(c.IssuerURL).To(BeEquivalentTo("http://127.0.0.1:5556/dex"))
Expect(c.RedirectURL).To(BeEquivalentTo("http://127.0.0.1:5555/callback"))
})
})
g.Describe("ExampleConfigGoogle", func() {
os.Setenv("GOOGLE_OAUTH2_CLIENT_ID", "client-id")
os.Setenv("GOOGLE_OAUTH2_CLIENT_SECRET", "client-secret")
c := ExampleConfigGoogle()
g.It("should match example google config", func() {
Expect(c.ClientID).To(BeEquivalentTo("client-id"))
Expect(c.ClientSecret).To(BeEquivalentTo("client-secret"))
Expect(c.IssuerURL).To(BeEquivalentTo("https://accounts.google.com"))
Expect(c.RedirectURL).To(BeEquivalentTo("http://127.0.0.1:5556/auth/google/callback"))
})
})
g.Describe("Validate", func() {
c := ExampleConfigDex()
c.ClientID = ""
g.It("should error on empty ClientID", func() {
Expect(c.Validate()).ToNot(BeNil())
})
c = ExampleConfigDex()
c.ClientSecret = ""
g.It("should error on empty ClientSecret", func() {
Expect(c.Validate()).ToNot(BeNil())
})
c = ExampleConfigDex()
c.IssuerURL = ""
g.It("should error on empty IssuerURL", func() {
Expect(c.Validate()).ToNot(BeNil())
})
c = ExampleConfigDex()
c.RedirectURL = ""
g.It("should error on empty RedirectURL", func() {
Expect(c.Validate()).ToNot(BeNil())
})
})
// g.Describe("GetOidcAuth", func() {
// auth, err := GetOidcAuth(ExampleConfigDex())
// g.It("should work", func() {
// Expect(auth).NotTo(BeNil())
// Expect(err).To(BeNil())
// })
// })
// g.Describe("c.GetOidcAuth", func() {
// c := ExampleConfigDex()
// auth, err := c.GetOidcAuth()
// g.It("should work", func() {
// Expect(auth).NotTo(BeNil())
// Expect(err).To(BeNil())
// })
// })
})
}