Files
wonderwall/pkg/mock/client.go
Trong Huu Nguyen 5a50ba7c3a feat: support multiple ingresses
Replace hardcoded callback URLs with dynamic generation
of URLs based on incoming requests. These are validated against
a pre-registered list of ingresses for which Wonderwall is considered
authorative for.

We also preserve the cookie behaviour; the most specific ingress path
and domain is used for the cookies.

The `url` package has been moved to the `handler` package, and its
implementation refactored slightly for readability and DRY.
2022-08-17 20:43:56 +02:00

84 lines
1.8 KiB
Go

package mock
import (
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/nais/wonderwall/pkg/config"
"github.com/nais/wonderwall/pkg/crypto"
"github.com/nais/wonderwall/pkg/ingress"
"github.com/nais/wonderwall/pkg/openid/scopes"
)
type TestClientConfiguration struct {
*config.Config
clientJwk jwk.Key
ingresses *ingress.Ingresses
}
func (c *TestClientConfiguration) ACRValues() string {
return c.Config.OpenID.ACRValues
}
func (c *TestClientConfiguration) ClientID() string {
return c.Config.OpenID.ClientID
}
func (c *TestClientConfiguration) ClientJWK() jwk.Key {
return c.clientJwk
}
func (c *TestClientConfiguration) Ingresses() *ingress.Ingresses {
return c.ingresses
}
func (c *TestClientConfiguration) SetIngresses(ingresses ...string) {
c.Config.Ingresses = ingresses
parsed, err := ingress.ParseIngresses(c.Config)
if err != nil {
panic(err)
}
c.ingresses = parsed
}
func (c *TestClientConfiguration) SetPostLogoutRedirectURI(uri string) {
c.Config.OpenID.PostLogoutRedirectURI = uri
}
func (c *TestClientConfiguration) PostLogoutRedirectURI() string {
return c.Config.OpenID.PostLogoutRedirectURI
}
func (c *TestClientConfiguration) Scopes() scopes.Scopes {
return scopes.DefaultScopes().WithAdditional(c.Config.OpenID.Scopes...)
}
func (c *TestClientConfiguration) UILocales() string {
return c.Config.OpenID.UILocales
}
func (c *TestClientConfiguration) WellKnownURL() string {
return c.Config.OpenID.WellKnownURL
}
func (c *TestClientConfiguration) Print() {}
func clientConfiguration(cfg *config.Config) *TestClientConfiguration {
key, err := crypto.NewJwk()
if err != nil {
panic(err)
}
ingresses, err := ingress.ParseIngresses(cfg)
if err != nil {
panic(err)
}
return &TestClientConfiguration{
Config: cfg,
clientJwk: key,
ingresses: ingresses,
}
}