Merge branch 'main' into op
# Conflicts: # pkg/client/rp/relaying_party.go
This commit is contained in:
commit
cef977adc2
8 changed files with 95 additions and 11 deletions
|
@ -170,11 +170,11 @@ func NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI string, sco
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
config, err := client.Discover(rp.issuer, rp.httpClient)
|
||||
discoveryConfiguration, err := client.Discover(rp.issuer, rp.httpClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoints := GetEndpoints(config)
|
||||
endpoints := GetEndpoints(discoveryConfiguration)
|
||||
rp.oauthConfig.Endpoint = endpoints.Endpoint
|
||||
rp.endpoints = endpoints
|
||||
|
||||
|
|
|
@ -27,6 +27,14 @@ func ConcatenateJSON(first, second []byte) ([]byte, error) {
|
|||
if !bytes.HasPrefix(second, []byte{'{'}) {
|
||||
return nil, fmt.Errorf("jws: invalid JSON %s", second)
|
||||
}
|
||||
// check empty
|
||||
if len(first) == 2 {
|
||||
return second, nil
|
||||
}
|
||||
if len(second) == 2 {
|
||||
return first, nil
|
||||
}
|
||||
|
||||
first[len(first)-1] = ','
|
||||
first = append(first, second[1:]...)
|
||||
return first, nil
|
||||
|
|
|
@ -44,6 +44,36 @@ func TestConcatenateJSON(t *testing.T) {
|
|||
[]byte(`{"some": "thing","another": "thing"}`),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"first empty",
|
||||
args{
|
||||
[]byte(`{}`),
|
||||
[]byte(`{"some": "thing"}`),
|
||||
},
|
||||
|
||||
[]byte(`{"some": "thing"}`),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"second empty",
|
||||
args{
|
||||
[]byte(`{"some": "thing"}`),
|
||||
[]byte(`{}`),
|
||||
},
|
||||
|
||||
[]byte(`{"some": "thing"}`),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"both empty",
|
||||
args{
|
||||
[]byte(`{}`),
|
||||
[]byte(`{}`),
|
||||
},
|
||||
|
||||
[]byte(`{}`),
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -53,7 +83,7 @@ func TestConcatenateJSON(t *testing.T) {
|
|||
return
|
||||
}
|
||||
if !bytes.Equal(got, tt.want) {
|
||||
t.Errorf("ConcatenateJSON() got = %v, want %v", got, tt.want)
|
||||
t.Errorf("ConcatenateJSON() got = %v, want %v", string(got), tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -360,6 +360,7 @@ func (i *userinfo) MarshalJSON() ([]byte, error) {
|
|||
func (i *userinfo) UnmarshalJSON(data []byte) error {
|
||||
type Alias userinfo
|
||||
a := &struct {
|
||||
Address *userInfoAddress `json:"address,omitempty"`
|
||||
*Alias
|
||||
UpdatedAt int64 `json:"update_at,omitempty"`
|
||||
}{
|
||||
|
@ -368,7 +369,7 @@ func (i *userinfo) UnmarshalJSON(data []byte) error {
|
|||
if err := json.Unmarshal(data, &a); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Address = a.Address
|
||||
i.UpdatedAt = Time(time.Unix(a.UpdatedAt, 0).UTC())
|
||||
|
||||
if err := json.Unmarshal(data, &i.claims); err != nil {
|
||||
|
|
26
pkg/oidc/userinfo_test.go
Normal file
26
pkg/oidc/userinfo_test.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package oidc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserInfoMarshal(t *testing.T) {
|
||||
userinfo := NewUserInfo()
|
||||
userinfo.SetSubject("test")
|
||||
userinfo.SetAddress(NewUserInfoAddress("Test 789\nPostfach 2", "", "", "", "", ""))
|
||||
userinfo.SetEmail("test", true)
|
||||
userinfo.SetPhone("0791234567", true)
|
||||
userinfo.SetName("Test")
|
||||
userinfo.AppendClaims("private_claim", "test")
|
||||
|
||||
marshal, err := json.Marshal(userinfo)
|
||||
out := NewUserInfo()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, json.Unmarshal(marshal, out))
|
||||
assert.Equal(t, userinfo.GetAddress(), out.GetAddress())
|
||||
expected, err := json.Marshal(out)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, marshal)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue