Files
wonderwall/pkg/openid/client/logout_callback_test.go
Trong Huu Nguyen 66cf08e602 refactor(openid/logout): simplify logout logic
As we already clear any local sessions before redirecting to the
Identity Provider, and the callback always redirects to a pre-configured URL,
there isn't really any need to maintain and verify state in the logout
callback.

In other words, the logout callback handler is simply a redirect handler.
2022-07-12 15:09:49 +02:00

41 lines
1.1 KiB
Go

package client_test
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/nais/wonderwall/pkg/mock"
"github.com/nais/wonderwall/pkg/openid/client"
)
func TestLogoutCallback_PostLogoutRedirectURI(t *testing.T) {
t.Run("happy path", func(t *testing.T) {
lc, cfg := newLogoutCallback(t)
cfg.ClientConfig.PostLogoutRedirectURI = "http://some-fancy-logout-page"
uri := lc.PostLogoutRedirectURI()
assert.NotEmpty(t, uri)
assert.Equal(t, "http://some-fancy-logout-page", uri)
})
t.Run("empty preconfigured post-logout redirect uri", func(t *testing.T) {
lc, cfg := newLogoutCallback(t)
cfg.ClientConfig.PostLogoutRedirectURI = ""
cfg.WonderwallConfig.Ingress = "http://wonderwall"
uri := lc.PostLogoutRedirectURI()
assert.NotEmpty(t, uri)
assert.Equal(t, "http://wonderwall", uri)
})
}
func newLogoutCallback(t *testing.T) (client.LogoutCallback, mock.Configuration) {
req, err := http.NewRequest("GET", "http://wonderwall/oauth2/logout/callback", nil)
assert.NoError(t, err)
cfg := mock.NewTestConfiguration(mock.Config())
return newTestClientWithConfig(cfg).LogoutCallback(req), cfg
}