You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-11-29 22:48:19 +02:00
Feature: Allowing relative redirect url though an option (#2183)
* Adding relative redirect url option * Updating CHANGELOG.md * tests: adding unit test for getOAuthRedirectURI --------- Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
@@ -3257,3 +3257,90 @@ func TestAuthOnlyAllowedEmails(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOAuthRedirectURI(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setupOpts func(*options.Options) *options.Options
|
||||
req *http.Request
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "redirect with https schema",
|
||||
setupOpts: func(baseOpts *options.Options) *options.Options {
|
||||
return baseOpts
|
||||
},
|
||||
req: &http.Request{
|
||||
Host: "example",
|
||||
URL: &url.URL{
|
||||
Scheme: schemeHTTPS,
|
||||
},
|
||||
},
|
||||
want: "https://example/oauth2/callback",
|
||||
},
|
||||
{
|
||||
name: "redirect with http schema",
|
||||
setupOpts: func(baseOpts *options.Options) *options.Options {
|
||||
baseOpts.Cookie.Secure = false
|
||||
return baseOpts
|
||||
},
|
||||
req: &http.Request{
|
||||
Host: "example",
|
||||
URL: &url.URL{
|
||||
Scheme: schemeHTTP,
|
||||
},
|
||||
},
|
||||
want: "http://example/oauth2/callback",
|
||||
},
|
||||
{
|
||||
name: "relative redirect url",
|
||||
setupOpts: func(baseOpts *options.Options) *options.Options {
|
||||
baseOpts.RelativeRedirectURL = true
|
||||
return baseOpts
|
||||
},
|
||||
req: &http.Request{},
|
||||
want: "/oauth2/callback",
|
||||
},
|
||||
{
|
||||
name: "proxy prefix",
|
||||
setupOpts: func(baseOpts *options.Options) *options.Options {
|
||||
baseOpts.ProxyPrefix = "/prefix"
|
||||
return baseOpts
|
||||
},
|
||||
req: &http.Request{
|
||||
Host: "example",
|
||||
URL: &url.URL{
|
||||
Scheme: schemeHTTP,
|
||||
},
|
||||
},
|
||||
want: "https://example/prefix/callback",
|
||||
},
|
||||
{
|
||||
name: "proxy prefix with relative redirect",
|
||||
setupOpts: func(baseOpts *options.Options) *options.Options {
|
||||
baseOpts.ProxyPrefix = "/prefix"
|
||||
baseOpts.RelativeRedirectURL = true
|
||||
return baseOpts
|
||||
},
|
||||
req: &http.Request{
|
||||
Host: "example",
|
||||
URL: &url.URL{
|
||||
Scheme: schemeHTTP,
|
||||
},
|
||||
},
|
||||
want: "/prefix/callback",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseOpts := baseTestOptions()
|
||||
err := validation.Validate(baseOpts)
|
||||
assert.NoError(t, err)
|
||||
|
||||
proxy, err := NewOAuthProxy(tt.setupOpts(baseOpts), func(string) bool { return true })
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equalf(t, tt.want, proxy.getOAuthRedirectURI(tt.req), "getOAuthRedirectURI(%v)", tt.req)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user