refactor(openid/config): extract getter for ingresses

This commit is contained in:
Trong Huu Nguyen
2022-09-02 15:17:36 +02:00
parent 9144056e28
commit c8f48335d4
11 changed files with 53 additions and 54 deletions
+7
View File
@@ -10,6 +10,7 @@ import (
"github.com/nais/wonderwall/pkg/crypto"
"github.com/nais/wonderwall/pkg/handler/autologin"
"github.com/nais/wonderwall/pkg/handler/reverseproxy"
"github.com/nais/wonderwall/pkg/ingress"
"github.com/nais/wonderwall/pkg/loginstatus"
"github.com/nais/wonderwall/pkg/openid/client"
openidconfig "github.com/nais/wonderwall/pkg/openid/config"
@@ -46,12 +47,18 @@ func NewHandler(
return nil, err
}
ingresses, err := ingress.ParseIngresses(cfg)
if err != nil {
return nil, err
}
return &StandardHandler{
autoLogin: autoLogin,
client: openidClient,
config: cfg,
cookieOptions: cookieOpts,
crypter: crypter,
ingresses: ingresses,
loginstatus: loginstatus.NewClient(cfg.Loginstatus, httpClient),
openidConfig: openidConfig,
provider: openidProvider,
+6 -1
View File
@@ -34,6 +34,7 @@ type StandardHandler struct {
config *config.Config
cookieOptions cookie.Options
crypter crypto.Crypter
ingresses *ingress.Ingresses
loginstatus loginstatus.Loginstatus
openidConfig openidconfig.Config
provider provider.Provider
@@ -71,7 +72,11 @@ func (s *StandardHandler) GetErrorRedirectURI() string {
}
func (s *StandardHandler) GetIngresses() *ingress.Ingresses {
return s.openidConfig.Client().Ingresses()
return s.ingresses
}
func (s *StandardHandler) SetIngresses(ingresses *ingress.Ingresses) {
s.ingresses = ingresses
}
func (s *StandardHandler) GetLoginstatus() loginstatus.Loginstatus {
+4 -4
View File
@@ -195,7 +195,7 @@ func TestLoginCallbackURL(t *testing.T) {
"https://nav.no/dagpenger",
"https://nav.no/dagpenger/soknad",
}
openidConfig := mock.NewTestConfiguration(cfg)
ingresses := mock.Ingresses(cfg)
for _, test := range []struct {
input string
@@ -224,7 +224,7 @@ func TestLoginCallbackURL(t *testing.T) {
},
} {
t.Run(test.input, func(t *testing.T) {
req := mock.NewGetRequest(test.input, openidConfig)
req := mock.NewGetRequest(test.input, ingresses)
actual, err := urlpkg.LoginCallbackURL(req)
if test.err != nil {
@@ -245,7 +245,7 @@ func TestLogoutCallbackURL(t *testing.T) {
"https://nav.no/dagpenger",
"https://nav.no/dagpenger/soknad",
}
openidConfig := mock.NewTestConfiguration(cfg)
ingresses := mock.Ingresses(cfg)
for _, test := range []struct {
input string
@@ -274,7 +274,7 @@ func TestLogoutCallbackURL(t *testing.T) {
},
} {
t.Run(test.input, func(t *testing.T) {
req := mock.NewGetRequest(test.input, openidConfig)
req := mock.NewGetRequest(test.input, ingresses)
actual, err := urlpkg.LogoutCallbackURL(req)
if test.err != nil {