mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 23:17:33 +00:00

# Which Problems Are Solved The OIDC session endpoint allows to pass a `id_token_hint` to identify the session to terminate. In case the application is not able to pass that, e.g. Console currently allows multiple sessions to be open, but will only store the id_token of the current session, allowing to pass the `logout_hint` to identify the user adds some new possibilities. # How the Problems Are Solved In case the end_session_endpoint is called with no `id_token_hint`, but a `logout_hint` and the v2 login UI is configured, the information is passed to the login UI also as `login_hint` parameter to allow the login UI to determine the session to be terminated, resp. let the user decide. # Additional Changes Also added the `ui_locales` as parameter to handle and pass to the V2 login UI. # Dependencies ⚠️ ~These changes depend on https://github.com/zitadel/oidc/pull/774~ # Additional Context closes #9847 --------- Co-authored-by: Marco Ardizzone <marco@zitadel.com>
99 lines
2.5 KiB
Go
99 lines
2.5 KiB
Go
package oidc
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
func TestBuildLoginV2LogoutURL(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tt := []struct {
|
|
testName string
|
|
logoutURIStr string
|
|
redirectURI string
|
|
logoutHint string
|
|
uiLocales []language.Tag
|
|
expectedParams map[string]string
|
|
}{
|
|
{
|
|
testName: "basic with only redirectURI",
|
|
logoutURIStr: "https://example.com/logout",
|
|
redirectURI: "https://client/cb",
|
|
expectedParams: map[string]string{
|
|
"post_logout_redirect": "https://client/cb",
|
|
},
|
|
},
|
|
{
|
|
testName: "with logout hint",
|
|
logoutURIStr: "https://example.com/logout",
|
|
redirectURI: "https://client/cb",
|
|
logoutHint: "user@example.com",
|
|
expectedParams: map[string]string{
|
|
"post_logout_redirect": "https://client/cb",
|
|
"logout_hint": "user@example.com",
|
|
},
|
|
},
|
|
{
|
|
testName: "with ui_locales",
|
|
logoutURIStr: "https://example.com/logout",
|
|
redirectURI: "https://client/cb",
|
|
uiLocales: []language.Tag{language.English, language.Italian},
|
|
expectedParams: map[string]string{
|
|
"post_logout_redirect": "https://client/cb",
|
|
"ui_locales": "en it",
|
|
},
|
|
},
|
|
{
|
|
testName: "with all params",
|
|
logoutURIStr: "https://example.com/logout",
|
|
redirectURI: "https://client/cb",
|
|
logoutHint: "logoutme",
|
|
uiLocales: []language.Tag{language.Make("de-CH"), language.Make("fr")},
|
|
expectedParams: map[string]string{
|
|
"post_logout_redirect": "https://client/cb",
|
|
"logout_hint": "logoutme",
|
|
"ui_locales": "de-CH fr",
|
|
},
|
|
},
|
|
{
|
|
testName: "base with trailing slash",
|
|
logoutURIStr: "https://example.com/logout/",
|
|
redirectURI: "https://client/cb",
|
|
expectedParams: map[string]string{
|
|
"post_logout_redirect": "https://client/cb",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.testName, func(t *testing.T) {
|
|
// t.Parallel()
|
|
|
|
// Given
|
|
logoutURI, err := url.Parse(tc.logoutURIStr)
|
|
require.NoError(t, err)
|
|
|
|
// When
|
|
got := buildLoginV2LogoutURL(logoutURI, tc.redirectURI, tc.logoutHint, tc.uiLocales)
|
|
|
|
// Then
|
|
gotURL, err := url.Parse(got)
|
|
require.NoError(t, err)
|
|
require.NotContains(t, gotURL.String(), "/logout/")
|
|
|
|
q := gotURL.Query()
|
|
// Ensure no unexpected params
|
|
require.Len(t, q, len(tc.expectedParams))
|
|
|
|
for k, v := range tc.expectedParams {
|
|
assert.Equal(t, v, q.Get(k))
|
|
}
|
|
})
|
|
}
|
|
}
|