@@ -3257,3 +3257,90 @@ func TestAuthOnlyAllowedEmails(t *testing.T) {
32573257 })
32583258 }
32593259}
3260+
3261+func TestGetOAuthRedirectURI(t *testing.T) {
3262+ tests := []struct {
3263+ name string
3264+ setupOpts func(*options.Options) *options.Options
3265+ req *http.Request
3266+ want string
3267+ }{
3268+ {
3269+ name: "redirect with https schema",
3270+ setupOpts: func(baseOpts *options.Options) *options.Options {
3271+ return baseOpts
3272+ },
3273+ req: &http.Request{
3274+ Host: "example",
3275+ URL: &url.URL{
3276+ Scheme: schemeHTTPS,
3277+ },
3278+ },
3279+ want: "https://example/oauth2/callback",
3280+ },
3281+ {
3282+ name: "redirect with http schema",
3283+ setupOpts: func(baseOpts *options.Options) *options.Options {
3284+ baseOpts.Cookie.Secure = false
3285+ return baseOpts
3286+ },
3287+ req: &http.Request{
3288+ Host: "example",
3289+ URL: &url.URL{
3290+ Scheme: schemeHTTP,
3291+ },
3292+ },
3293+ want: "http://example/oauth2/callback",
3294+ },
3295+ {
3296+ name: "relative redirect url",
3297+ setupOpts: func(baseOpts *options.Options) *options.Options {
3298+ baseOpts.RelativeRedirectURL = true
3299+ return baseOpts
3300+ },
3301+ req: &http.Request{},
3302+ want: "/oauth2/callback",
3303+ },
3304+ {
3305+ name: "proxy prefix",
3306+ setupOpts: func(baseOpts *options.Options) *options.Options {
3307+ baseOpts.ProxyPrefix = "/prefix"
3308+ return baseOpts
3309+ },
3310+ req: &http.Request{
3311+ Host: "example",
3312+ URL: &url.URL{
3313+ Scheme: schemeHTTP,
3314+ },
3315+ },
3316+ want: "https://example/prefix/callback",
3317+ },
3318+ {
3319+ name: "proxy prefix with relative redirect",
3320+ setupOpts: func(baseOpts *options.Options) *options.Options {
3321+ baseOpts.ProxyPrefix = "/prefix"
3322+ baseOpts.RelativeRedirectURL = true
3323+ return baseOpts
3324+ },
3325+ req: &http.Request{
3326+ Host: "example",
3327+ URL: &url.URL{
3328+ Scheme: schemeHTTP,
3329+ },
3330+ },
3331+ want: "/prefix/callback",
3332+ },
3333+ }
3334+ for _, tt := range tests {
3335+ t.Run(tt.name, func(t *testing.T) {
3336+ baseOpts := baseTestOptions()
3337+ err := validation.Validate(baseOpts)
3338+ assert.NoError(t, err)
3339+
3340+ proxy, err := NewOAuthProxy(tt.setupOpts(baseOpts), func(string) bool { return true })
3341+ assert.NoError(t, err)
3342+
3343+ assert.Equalf(t, tt.want, proxy.getOAuthRedirectURI(tt.req), "getOAuthRedirectURI(%v)", tt.req)
3344+ })
3345+ }
3346+}