@@ -18,6 +18,7 @@ import (
1818 "github.com/mbland/hmacauth"
1919 "github.com/pusher/oauth2_proxy/providers"
2020 "github.com/stretchr/testify/assert"
21+ "github.com/stretchr/testify/require"
2122)
2223
2324func init() {
@@ -837,3 +838,36 @@ func TestRequestSignaturePostRequest(t *testing.T) {
837838 assert.Equal(t, 200, st.rw.Code)
838839 assert.Equal(t, st.rw.Body.String(), "signatures match")
839840}
841+
842+func TestGetRedirect(t *testing.T) {
843+ options := NewOptions()
844+ _ = options.Validate()
845+ require.NotEmpty(t, options.ProxyPrefix)
846+ proxy := NewOAuthProxy(options, func(s string) bool { return false })
847+
848+ tests := []struct {
849+ name string
850+ url string
851+ expectedRedirect string
852+ }{
853+ {
854+ name: "request outside of ProxyPrefix redirects to original URL",
855+ url: "/foo/bar",
856+ expectedRedirect: "/foo/bar",
857+ },
858+ {
859+ name: "request under ProxyPrefix redirects to root",
860+ url: proxy.ProxyPrefix + "/foo/bar",
861+ expectedRedirect: "/",
862+ },
863+ }
864+ for _, tt := range tests {
865+ t.Run(tt.name, func(t *testing.T) {
866+ req, _ := http.NewRequest("GET", tt.url, nil)
867+ redirect, err := proxy.GetRedirect(req)
868+
869+ assert.NoError(t, err)
870+ assert.Equal(t, tt.expectedRedirect, redirect)
871+ })
872+ }
873+}