fix: don't error on invalid i18n tags in discovery (#407)
* 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
This commit is contained in:
parent
77436a2ce7
commit
d01a5c8f91
4 changed files with 185 additions and 9 deletions
54
pkg/client/client_test.go
Normal file
54
pkg/client/client_test.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue