Files
authentik/internal/outpost/proxyv2/application/test.go
Marc 'risson' Schmitt 2f70351c90 packages/client-go: init (#21139)
* packages/client-go: init

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>

* format

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* remove mod/sum

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix translate

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* no go replace

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* update rust makefile with pwd

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>

* fix build

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix docs

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* don't need a version ig?

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* exclude go client from cspell

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix main docker build

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
2026-03-25 15:26:50 +01:00

100 lines
2.5 KiB
Go

package application
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"goauthentik.io/internal/outpost/ak"
api "goauthentik.io/packages/client-go"
)
type testServer struct {
api *ak.APIController
apps []*Application
}
func newTestServer() *testServer {
return &testServer{
api: ak.MockAK(
api.Outpost{
Config: map[string]any{
"authentik_host": ak.TestSecret(),
},
},
ak.MockConfig(),
),
apps: make([]*Application, 0),
}
}
func (ts *testServer) API() *ak.APIController {
return ts.api
}
func (ts *testServer) CryptoStore() *ak.CryptoStore {
return nil
}
func (ts *testServer) Apps() []*Application {
return ts.apps
}
func (ts *testServer) SessionBackend() string {
return "filesystem"
}
func newTestApplication() *Application {
ts := newTestServer()
a, _ := NewApplication(
api.ProxyOutpostConfig{
Name: ak.TestSecret(),
ClientId: new(ak.TestSecret()),
ClientSecret: new(ak.TestSecret()),
CookieDomain: new(""),
CookieSecret: new(ak.TestSecret()),
ExternalHost: "https://ext.t.goauthentik.io",
InternalHost: new("http://backend"),
InternalHostSslValidation: new(true),
Mode: api.PROXYMODE_FORWARD_SINGLE.Ptr(),
SkipPathRegex: new("/skip.*"),
BasicAuthEnabled: new(true),
BasicAuthUserAttribute: new("username"),
BasicAuthPasswordAttribute: new("password"),
OidcConfiguration: api.OpenIDConnectConfiguration{
AuthorizationEndpoint: "http://fake-auth.t.goauthentik.io/auth",
TokenEndpoint: "http://fake-auth.t.goauthentik.io/token",
UserinfoEndpoint: "http://fake-auth.t.goauthentik.io/userinfo",
},
},
http.DefaultClient,
ts,
nil,
)
ts.apps = append(ts.apps, a)
return a
}
func (a *Application) assertState(t *testing.T, req *http.Request, response *httptest.ResponseRecorder) (*url.URL, *OAuthState) {
loc, _ := response.Result().Location()
q := loc.Query()
state := q.Get("state")
a.log.WithField("actual", state).Warning("actual state")
// modify request to set state so we can parse it
nr := req.Clone(req.Context())
nrq := nr.URL.Query()
nrq.Set("state", state)
nr.URL.RawQuery = nrq.Encode()
// parse state
parsed := a.stateFromRequest(nil, nr)
if parsed == nil {
panic("Could not parse state")
}
// Remove state from URL
q.Del("state")
loc.RawQuery = q.Encode()
return loc, parsed
}