@@ -273,4 +273,57 @@ void deleteUser() throws JsonProcessingException {
273273 assertTrue (optionalUser .isEmpty ());
274274 }
275275
276+ @ Test
277+ void scopeInviteRoleToUniqueCRMRoleIdAndOrganizationId () throws JsonProcessingException {
278+ String converRoleId = "92b2b379-07e4-e811-8100-005056956c1a" ;
279+ CRMRole crmRole = new CRMRole (converRoleId , "CONVER" , "SURFconextverantwoordelijke" );
280+ String crmContactID = UUID .randomUUID ().toString ();
281+ String crmOrganisationID = UUID .randomUUID ().toString ();
282+ CRMContact crmContact = createCrmContact (crmContactID , crmOrganisationID , crmRole , "total" , "new.com" , true );
283+ //These applications are linked to the 'AAI' CRM role
284+ super .stubForManageProviderByEntityID (EntityType .OIDC10_RP , "https://cloud" );
285+ //Ignore the SCIM provisioning
286+ super .stubForManageProvisioning (List .of ());
287+
288+ String response = given ()
289+ .when ()
290+ .accept (ContentType .JSON )
291+ .header (API_KEY_HEADER , "secret" )
292+ .contentType (ContentType .JSON )
293+ .body (crmContact )
294+ .post ("/api/internal/v1/crm" )
295+ .then ()
296+ .extract ()
297+ .asString ();
298+ assertEquals ("created" , response );
299+
300+ User user = userRepository .findBySubIgnoreCase ("urn:collab:person:new.com:total" ).get ();
301+ assertEquals (1 , user .getUserRoles ().size ());
302+ //Now post the same CRMContact for a different user, but the same role. Enusure the role is not re-used
303+ String newOrganisationID = UUID .randomUUID ().toString ();
304+ crmContact .setOrganisation (new CRMOrganisation (newOrganisationID ,"abbrev" ,"name" ));
305+ crmContact .setUid ("second_user" );
306+ response = given ()
307+ .when ()
308+ .accept (ContentType .JSON )
309+ .header (API_KEY_HEADER , "secret" )
310+ .contentType (ContentType .JSON )
311+ .body (crmContact )
312+ .post ("/api/internal/v1/crm" )
313+ .then ()
314+ .extract ()
315+ .asString ();
316+ assertEquals ("created" , response );
317+
318+ user = userRepository .findBySubIgnoreCase ("urn:collab:person:new.com:total" ).get ();
319+ assertEquals (1 , user .getUserRoles ().size ());
320+
321+ user = userRepository .findBySubIgnoreCase ("urn:collab:person:new.com:second_user" ).get ();
322+ assertEquals (1 , user .getUserRoles ().size ());
323+
324+ List <Role > roles = roleRepository .findByCrmRoleId (converRoleId );
325+ assertEquals (2 , roles .size ());
326+ }
327+
328+
276329}
0 commit comments