* reproduce #406 * fix: don't error on invalid i18n tags in discovery This changes the use of `[]language.Tag` to `oidc.Locales` in `DiscoveryConfig`. This should be compatible with callers that use the `[]language.Tag` . Locales now implements the `json.Unmarshaler` interface. With support for json arrays or space seperated strings. The latter because `UnmarshalText` might have been implicetely called by the json library before we added UnmarshalJSON. Fixes: #406
54 lines
1 KiB
Go
54 lines
1 KiB
Go
package client
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDiscover(t *testing.T) {
|
|
type wantFields struct {
|
|
UILocalesSupported bool
|
|
}
|
|
|
|
type args struct {
|
|
issuer string
|
|
wellKnownUrl []string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantFields *wantFields
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "spotify", // https://github.com/zitadel/oidc/issues/406
|
|
args: args{
|
|
issuer: "https://accounts.spotify.com",
|
|
},
|
|
wantFields: &wantFields{
|
|
UILocalesSupported: true,
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := Discover(tt.args.issuer, http.DefaultClient, tt.args.wellKnownUrl...)
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
if tt.wantFields == nil {
|
|
return
|
|
}
|
|
assert.Equal(t, tt.args.issuer, got.Issuer)
|
|
if tt.wantFields.UILocalesSupported {
|
|
assert.NotEmpty(t, got.UILocalesSupported)
|
|
}
|
|
})
|
|
}
|
|
}
|