@@ -1047,6 +1047,91 @@ func TestCreateOrGetUser(t *testing.T) {
10471047 assert .Equal (t , true , got .Emails [0 ].Primary )
10481048 assert .Equal (t , true , got .Active )
10491049 })
1050+
1051+ t .Run ("should not panic when existing user has no emails and fields changed" , func (t * testing.T ) {
1052+ CreateUserResponseConflictFile := "testdata/CreateUserResponse_Conflict.json"
1053+ ListUserResponseFile := "testdata/ListUserResponse_no_emails.json"
1054+ PutUserResponseFile := "testdata/PutUserResponse.json"
1055+
1056+ mockHTTPClient := mocks .NewMockHTTPClient (mockCtrl )
1057+ jsonRespConflict := ReadJSONFileAsString (t , CreateUserResponseConflictFile )
1058+ jsonListRespOK := ReadJSONFileAsString (t , ListUserResponseFile )
1059+ jsonPutUserRespOK := ReadJSONFileAsString (t , PutUserResponseFile )
1060+
1061+ httpRespConflict := & http.Response {
1062+ Status : "409 Conflict" ,
1063+ StatusCode : http .StatusConflict ,
1064+ Header : http.Header {
1065+ "Date" : []string {"Fri, 18 Mar 2022 10:57:08 GMT" },
1066+ "Content-Type" : []string {"application/json" },
1067+ "x-amzn-RequestId" : []string {"81abca44-4ee3-47fa-b4d9-729908ef1dd9" },
1068+ },
1069+ Proto : "HTTP/1.1" ,
1070+ Body : io .NopCloser (strings .NewReader (jsonRespConflict )),
1071+ ContentLength : int64 (len (jsonRespConflict )),
1072+ }
1073+
1074+ ListRespOK := & http.Response {
1075+ Status : "200 OK" ,
1076+ StatusCode : http .StatusOK ,
1077+ Header : http.Header {
1078+ "Date" : []string {"Tue, 31 Mar 2020 02:36:15 GMT" },
1079+ "Content-Type" : []string {"application/json" },
1080+ "x-amzn-RequestId" : []string {"abbf9e53-9ecc-46d2-8efe-104a66ff128f" },
1081+ },
1082+ Proto : "HTTP/1.1" ,
1083+ Body : io .NopCloser (strings .NewReader (jsonListRespOK )),
1084+ ContentLength : int64 (len (jsonListRespOK )),
1085+ }
1086+
1087+ PutUserRespOK := & http.Response {
1088+ Status : "200 OK" ,
1089+ StatusCode : http .StatusOK ,
1090+ Header : http.Header {
1091+ "Date" : []string {"Tue, 31 Mar 2020 02:36:15 GMT" },
1092+ "Content-Type" : []string {"application/json" },
1093+ "x-amzn-RequestId" : []string {"abbf9e53-9ecc-46d2-8efe-104a66ff128f" },
1094+ },
1095+ Proto : "HTTP/1.1" ,
1096+ Body : io .NopCloser (strings .NewReader (jsonPutUserRespOK )),
1097+ ContentLength : int64 (len (jsonPutUserRespOK )),
1098+ }
1099+
1100+ mockHTTPClient .EXPECT ().Do (gomock .Any ()).Return (httpRespConflict , nil ).Times (1 )
1101+ mockHTTPClient .EXPECT ().Do (gomock .Any ()).Return (ListRespOK , nil ).Times (1 )
1102+ mockHTTPClient .EXPECT ().Do (gomock .Any ()).Return (PutUserRespOK , nil ).Times (1 )
1103+
1104+ service , err := NewSCIMService (mockHTTPClient , endpoint , "MyToken" )
1105+ assert .NoError (t , err )
1106+ assert .NotNil (t , service )
1107+
1108+ usrr := & CreateUserRequest {
1109+ ID : "90677c608a-7afcdc23-0bd4-4fb7-b2ff-10ccffdff447" ,
1110+ ExternalID : "702135" ,
1111+ UserName : "mjack" ,
1112+ Name : & Name {
1113+ FamilyName : "Jackson" ,
1114+ GivenName : "Mark" ,
1115+ },
1116+ DisplayName : "Mark Jackson" ,
1117+ Emails : []Email {
1118+ {
1119+ Value : "mjack@example.com" ,
1120+ Type : "work" ,
1121+ Primary : true ,
1122+ },
1123+ },
1124+ Active : true ,
1125+ }
1126+
1127+ var got * CreateUserResponse
1128+ assert .NotPanics (t , func () {
1129+ var callErr error
1130+ got , callErr = service .CreateOrGetUser (context .Background (), usrr )
1131+ assert .NoError (t , callErr )
1132+ })
1133+ assert .NotNil (t , got )
1134+ })
10501135}
10511136
10521137func TestDeleteUser (t * testing.T ) {
0 commit comments