11 "github.com/stretchr/testify/assert"
14func testOptions() *Options {
16 o.Upstreams = append(o.Upstreams, "http://127.0.0.1:8080/")
17 o.CookieSecret = "foobar"
18 o.ClientID = "bazquux"
19 o.ClientSecret = "xyzzyplugh"
20 o.EmailDomains = []string{"*"}
24func errorMsg(msgs []string) string {
25 result := make([]string, 0)
26 result = append(result, "Invalid configuration:")
27 result = append(result, msgs...)
28 return strings.Join(result, "\n ")
31func TestNewOptions(t *testing.T) {
33 o.EmailDomains = []string{"*"}
35 assert.NotEqual(t, nil, err)
37 expected := errorMsg([]string{
38 "missing setting: cookie-secret",
39 "missing setting: client-id",
40 "missing setting: client-secret"})
41 assert.Equal(t, expected, err.Error())
44func TestGoogleGroupOptions(t *testing.T) {
46 o.GoogleGroups = []string{"googlegroup"}
48 assert.NotEqual(t, nil, err)
50 expected := errorMsg([]string{
51 "missing setting: google-admin-email",
52 "missing setting: google-service-account-json"})
53 assert.Equal(t, expected, err.Error())
56func TestGoogleGroupInvalidFile(t *testing.T) {
58 o.GoogleGroups = []string{"test_group"}
59 o.GoogleAdminEmail = "admin@example.com"
60 o.GoogleServiceAccountJSON = "file_doesnt_exist.json"
62 assert.NotEqual(t, nil, err)
64 expected := errorMsg([]string{
65 "invalid Google credentials file: file_doesnt_exist.json",
67 assert.Equal(t, expected, err.Error())
70func TestInitializedOptions(t *testing.T) {
72 assert.Equal(t, nil, o.Validate())
75// Note that it's not worth testing nonparseable URLs, since url.Parse()
76// seems to parse damn near anything.
77func TestRedirectURL(t *testing.T) {
79 o.RedirectURL = "https://myhost.com/oauth2/callback"
80 assert.Equal(t, nil, o.Validate())
82 Scheme: "https", Host: "myhost.com", Path: "/oauth2/callback"}
83 assert.Equal(t, expected, o.redirectURL)
86func TestProxyURLs(t *testing.T) {
88 o.Upstreams = append(o.Upstreams, "http://127.0.0.1:8081")
89 assert.Equal(t, nil, o.Validate())
90 expected := []*url.URL{
91 {Scheme: "http", Host: "127.0.0.1:8080", Path: "/"},
92 // note the '/' was added
93 {Scheme: "http", Host: "127.0.0.1:8081", Path: "/"},
95 assert.Equal(t, expected, o.proxyURLs)
98func TestProxyURLsError(t *testing.T) {
100 o.Upstreams = append(o.Upstreams, "127.0.0.1:8081")
102 assert.NotEqual(t, nil, err)
104 expected := errorMsg([]string{
105 "error parsing upstream: parse 127.0.0.1:8081: " +
106 "first path segment in URL cannot contain colon"})
107 assert.Equal(t, expected, err.Error())
110func TestCompiledRegex(t *testing.T) {
112 regexps := []string{"/foo/.*", "/ba[rz]/quux"}
113 o.SkipAuthRegex = regexps
114 assert.Equal(t, nil, o.Validate())
115 actual := make([]string, 0)
116 for _, regex := range o.CompiledRegex {
117 actual = append(actual, regex.String())
119 assert.Equal(t, regexps, actual)
122func TestCompiledRegexError(t *testing.T) {
124 o.SkipAuthRegex = []string{"(foobaz", "barquux)"}
126 assert.NotEqual(t, nil, err)
128 expected := errorMsg([]string{
129 "error compiling regex=\"(foobaz\" error parsing regexp: " +
130 "missing closing ): `(foobaz`",
131 "error compiling regex=\"barquux)\" error parsing regexp: " +
132 "unexpected ): `barquux)`"})
133 assert.Equal(t, expected, err.Error())
135 o.SkipAuthRegex = []string{"foobaz", "barquux)"}
137 assert.NotEqual(t, nil, err)
139 expected = errorMsg([]string{
140 "error compiling regex=\"barquux)\" error parsing regexp: " +
141 "unexpected ): `barquux)`"})
142 assert.Equal(t, expected, err.Error())
145func TestDefaultProviderApiSettings(t *testing.T) {
147 assert.Equal(t, nil, o.Validate())
148 p := o.provider.Data()
149 assert.Equal(t, "https://accounts.google.com/o/oauth2/auth?access_type=offline",
151 assert.Equal(t, "https://www.googleapis.com/oauth2/v3/token",
152 p.RedeemURL.String())
153 assert.Equal(t, "", p.ProfileURL.String())
154 assert.Equal(t, "profile email", p.Scope)
157func TestPassAccessTokenRequiresSpecificCookieSecretLengths(t *testing.T) {
159 assert.Equal(t, nil, o.Validate())
161 assert.Equal(t, false, o.PassAccessToken)
162 o.PassAccessToken = true
163 o.CookieSecret = "cookie of invalid length-"
164 assert.NotEqual(t, nil, o.Validate())
166 o.PassAccessToken = false
167 o.CookieRefresh = time.Duration(24) * time.Hour
168 assert.NotEqual(t, nil, o.Validate())
170 o.CookieSecret = "16 bytes AES-128"
171 assert.Equal(t, nil, o.Validate())
173 o.CookieSecret = "24 byte secret AES-192--"
174 assert.Equal(t, nil, o.Validate())
176 o.CookieSecret = "32 byte secret for AES-256------"
177 assert.Equal(t, nil, o.Validate())
180func TestCookieRefreshMustBeLessThanCookieExpire(t *testing.T) {
182 assert.Equal(t, nil, o.Validate())
184 o.CookieSecret = "0123456789abcdefabcd"
185 o.CookieRefresh = o.CookieExpire
186 assert.NotEqual(t, nil, o.Validate())
188 o.CookieRefresh -= time.Duration(1)
189 assert.Equal(t, nil, o.Validate())
192func TestBase64CookieSecret(t *testing.T) {
194 assert.Equal(t, nil, o.Validate())
196 // 32 byte, base64 (urlsafe) encoded key
197 o.CookieSecret = "yHBw2lh2Cvo6aI_jn_qMTr-pRAjtq0nzVgDJNb36jgQ="
198 assert.Equal(t, nil, o.Validate())
200 // 32 byte, base64 (urlsafe) encoded key, w/o padding
201 o.CookieSecret = "yHBw2lh2Cvo6aI_jn_qMTr-pRAjtq0nzVgDJNb36jgQ"
202 assert.Equal(t, nil, o.Validate())
204 // 24 byte, base64 (urlsafe) encoded key
205 o.CookieSecret = "Kp33Gj-GQmYtz4zZUyUDdqQKx5_Hgkv3"
206 assert.Equal(t, nil, o.Validate())
208 // 16 byte, base64 (urlsafe) encoded key
209 o.CookieSecret = "LFEqZYvYUwKwzn0tEuTpLA=="
210 assert.Equal(t, nil, o.Validate())
212 // 16 byte, base64 (urlsafe) encoded key, w/o padding
213 o.CookieSecret = "LFEqZYvYUwKwzn0tEuTpLA"
214 assert.Equal(t, nil, o.Validate())
217func TestValidateSignatureKey(t *testing.T) {
219 o.SignatureKey = "sha1:secret"
220 assert.Equal(t, nil, o.Validate())
221 assert.Equal(t, o.signatureData.hash, crypto.SHA1)
222 assert.Equal(t, o.signatureData.key, "secret")
225func TestValidateSignatureKeyInvalidSpec(t *testing.T) {
227 o.SignatureKey = "invalid spec"
229 assert.Equal(t, err.Error(), "Invalid configuration:\n"+
230 " invalid signature hash:key spec: "+o.SignatureKey)
233func TestValidateSignatureKeyUnsupportedAlgorithm(t *testing.T) {
235 o.SignatureKey = "unsupported:default secret"
237 assert.Equal(t, err.Error(), "Invalid configuration:\n"+
238 " unsupported signature hash algorithm: "+o.SignatureKey)
241func TestValidateCookie(t *testing.T) {
243 o.CookieName = "_valid_cookie_name"
244 assert.Equal(t, nil, o.Validate())
247func TestValidateCookieBadName(t *testing.T) {
249 o.CookieName = "_bad_cookie_name{}"
251 assert.Equal(t, err.Error(), "Invalid configuration:\n"+
252 fmt.Sprintf(" invalid cookie name: %q", o.CookieName))
255func TestSkipOIDCDiscovery(t *testing.T) {
258 o.OIDCIssuerURL = "https://login.microsoftonline.com/fabrikamb2c.onmicrosoft.com/v2.0/"
259 o.SkipOIDCDiscovery = true
262 assert.Equal(t, "Invalid configuration:\n"+
263 fmt.Sprintf(" missing setting: login-url\n missing setting: redeem-url\n missing setting: oidc-jwks-url"), err.Error())
265 o.LoginURL = "https://login.microsoftonline.com/fabrikamb2c.onmicrosoft.com/oauth2/v2.0/authorize?p=b2c_1_sign_in"
266 o.RedeemURL = "https://login.microsoftonline.com/fabrikamb2c.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_sign_in"
267 o.OIDCJwksURL = "https://login.microsoftonline.com/fabrikamb2c.onmicrosoft.com/discovery/v2.0/keys"
269 assert.Equal(t, nil, o.Validate())
272func TestGCPHealthcheck(t *testing.T) {
274 o.GCPHealthChecks = true
275 assert.Equal(t, nil, o.Validate())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list