oidc: add test case to reproduce #203
Running the tests will always result in a nil pointer dereference on UserInfoAddress.
This commit is contained in:
parent
fca6cf9433
commit
f4a7c7e4ad
1 changed files with 32 additions and 0 deletions
|
@ -81,3 +81,35 @@ func TestUserInfoEmailVerifiedUnmarshal(t *testing.T) {
|
||||||
}, uie)
|
}, uie)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 203 test case.
|
||||||
|
func Test_userinfo_GetAddress_issue_203(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
data string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "with address",
|
||||||
|
data: `{"address":{"street_address":"Test 789\nPostfach 2"},"email":"test","email_verified":true,"name":"Test","phone_number":"0791234567","phone_number_verified":true,"private_claim":"test","sub":"test"}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "without address",
|
||||||
|
data: `{"email":"test","email_verified":true,"name":"Test","phone_number":"0791234567","phone_number_verified":true,"private_claim":"test","sub":"test"}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "null address",
|
||||||
|
data: `{"address":null,"email":"test","email_verified":true,"name":"Test","phone_number":"0791234567","phone_number_verified":true,"private_claim":"test","sub":"test"}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
info := &userinfo{}
|
||||||
|
if err := json.Unmarshal([]byte(tt.data), info); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
info.GetAddress().GetCountry() //<- used to panic
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue