add unit tests for oidc.Userinfo

- Add get methods for Address fields to handle nil pointers as we used to
This commit is contained in:
Tim Möhlmann 2023-03-02 17:35:06 +02:00
parent 72a108a33b
commit d41f4b5d21
6 changed files with 52 additions and 5 deletions

View file

@ -35,7 +35,7 @@ type IntrospectionResponse struct {
// GetUserInfo copies all user related fields into a new UserInfo.
func (i *IntrospectionResponse) GetUserInfo() *UserInfo {
return &UserInfo{
Address: i.Address,
Address: gu.PtrCopy(i.Address),
Subject: i.Subject,
UserInfoProfile: i.UserInfoProfile,
UserInfoEmail: i.UserInfoEmail,
@ -49,7 +49,7 @@ func (i *IntrospectionResponse) GetUserInfo() *UserInfo {
func (i *IntrospectionResponse) SetUserInfo(u *UserInfo) {
i.Subject = u.Subject
i.Username = u.PreferredUsername
i.Address = u.Address
i.Address = gu.PtrCopy(u.Address)
i.UserInfoProfile = u.UserInfoProfile
i.UserInfoEmail = u.UserInfoEmail
i.UserInfoPhone = u.UserInfoPhone
@ -60,6 +60,15 @@ func (i *IntrospectionResponse) SetUserInfo(u *UserInfo) {
}
}
// GetAddress is a safe getter that takes
// care of a possible nil value.
func (i *IntrospectionResponse) GetAddress() *UserInfoAddress {
if i.Address == nil {
return new(UserInfoAddress)
}
return i.Address
}
// introspectionResponseAlias prevents loops on the JSON methods
type introspectionResponseAlias IntrospectionResponse