From f4a7c7e4ad867478769ab8ca138f419c87634c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 16 Sep 2022 15:31:42 +0300 Subject: [PATCH] oidc: add test case to reproduce #203 Running the tests will always result in a nil pointer dereference on UserInfoAddress. --- pkg/oidc/userinfo_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/oidc/userinfo_test.go b/pkg/oidc/userinfo_test.go index f42ff3d..924b97a 100644 --- a/pkg/oidc/userinfo_test.go +++ b/pkg/oidc/userinfo_test.go @@ -81,3 +81,35 @@ func TestUserInfoEmailVerifiedUnmarshal(t *testing.T) { }, 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 + }) + } +}