From 6f88ff7429479d5c36c43f92269b11b6dcb644af Mon Sep 17 00:00:00 2001 From: Alvaro Iradier Date: Wed, 6 May 2020 02:02:06 +0200 Subject: [PATCH] Fix test suite and add test for userClaim Signed-off-by: Alvaro Iradier --- src/common/utils/oidc/helper_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/utils/oidc/helper_test.go b/src/common/utils/oidc/helper_test.go index 06dbac0de..96b2970ff 100644 --- a/src/common/utils/oidc/helper_test.go +++ b/src/common/utils/oidc/helper_test.go @@ -175,6 +175,7 @@ func TestUserInfoFromClaims(t *testing.T) { s := []struct { input map[string]interface{} groupClaim string + userClaim string expect *UserInfo }{ { @@ -184,6 +185,7 @@ func TestUserInfoFromClaims(t *testing.T) { "groups": []interface{}{"g1", "g2"}, }, groupClaim: "grouplist", + userClaim: "", expect: &UserInfo{ Issuer: "", Subject: "", @@ -200,6 +202,7 @@ func TestUserInfoFromClaims(t *testing.T) { "groups": []interface{}{"g1", "g2"}, }, groupClaim: "groups", + userClaim: "", expect: &UserInfo{ Issuer: "", Subject: "", @@ -218,6 +221,7 @@ func TestUserInfoFromClaims(t *testing.T) { "groupclaim": []interface{}{}, }, groupClaim: "groupclaim", + userClaim: "", expect: &UserInfo{ Issuer: "issuer", Subject: "subject000", @@ -227,9 +231,26 @@ func TestUserInfoFromClaims(t *testing.T) { hasGroupClaim: true, }, }, + { + input: map[string]interface{}{ + "name": "Alvaro", + "email": "airadier@gmail.com", + "groups": []interface{}{"g1", "g2"}, + }, + groupClaim: "grouplist", + userClaim: "email", + expect: &UserInfo{ + Issuer: "", + Subject: "", + Username: "airadier@gmail.com", + Email: "airadier@gmail.com", + Groups: []string{}, + hasGroupClaim: false, + }, + }, } for _, tc := range s { - out, err := userInfoFromClaims(&fakeClaims{tc.input}, tc.groupClaim) + out, err := userInfoFromClaims(&fakeClaims{tc.input}, tc.groupClaim, tc.userClaim) assert.Nil(t, err) assert.Equal(t, *tc.expect, *out) }