2022-02-15 12:43:55 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-03-03 09:40:07 +00:00
|
|
|
"goauthentik.io/api/v3"
|
2022-02-15 12:43:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckRedirectParam(t *testing.T) {
|
|
|
|
a := newTestApplication()
|
|
|
|
req, _ := http.NewRequest("GET", "/outpost.goauthentik.io/auth/start", nil)
|
|
|
|
|
|
|
|
rd, ok := a.checkRedirectParam(req)
|
|
|
|
|
|
|
|
assert.Equal(t, false, ok)
|
|
|
|
assert.Equal(t, "", rd)
|
|
|
|
|
|
|
|
req, _ = http.NewRequest("GET", "/outpost.goauthentik.io/auth/start?rd=https://google.com", nil)
|
|
|
|
|
|
|
|
rd, ok = a.checkRedirectParam(req)
|
|
|
|
|
|
|
|
assert.Equal(t, false, ok)
|
|
|
|
assert.Equal(t, "", rd)
|
|
|
|
|
2022-03-07 21:03:36 +00:00
|
|
|
req, _ = http.NewRequest("GET", "/outpost.goauthentik.io/auth/start?rd=https://ext.t.goauthentik.io/test?foo", nil)
|
2022-02-15 12:43:55 +00:00
|
|
|
|
|
|
|
rd, ok = a.checkRedirectParam(req)
|
|
|
|
|
|
|
|
assert.Equal(t, true, ok)
|
2022-03-07 21:03:36 +00:00
|
|
|
assert.Equal(t, "https://ext.t.goauthentik.io/test?foo", rd)
|
2022-02-15 12:43:55 +00:00
|
|
|
}
|
2022-02-15 13:58:19 +00:00
|
|
|
|
|
|
|
func TestCheckRedirectParam_Domain(t *testing.T) {
|
|
|
|
a := newTestApplication()
|
2023-04-01 16:10:52 +00:00
|
|
|
a.proxyConfig.Mode = api.PROXYMODE_FORWARD_DOMAIN.Ptr()
|
2022-02-15 13:58:19 +00:00
|
|
|
a.proxyConfig.CookieDomain = api.PtrString("t.goauthentik.io")
|
|
|
|
req, _ := http.NewRequest("GET", "https://a.t.goauthentik.io/outpost.goauthentik.io/auth/start", nil)
|
|
|
|
|
|
|
|
rd, ok := a.checkRedirectParam(req)
|
|
|
|
|
|
|
|
assert.Equal(t, false, ok)
|
|
|
|
assert.Equal(t, "", rd)
|
|
|
|
req, _ = http.NewRequest("GET", "/outpost.goauthentik.io/auth/start?rd=https://ext.t.goauthentik.io/test", nil)
|
|
|
|
|
|
|
|
rd, ok = a.checkRedirectParam(req)
|
|
|
|
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
assert.Equal(t, "https://ext.t.goauthentik.io/test", rd)
|
|
|
|
}
|