use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method testChangeUserRolesOnNamespaceUserWithExtraneousUser.
/**
* Tests that changing a user's roles on a namespace from a user who's tenant admin, but not on
* that namespace, fails.
*
* @throws Exception
*/
@Test
public void testChangeUserRolesOnNamespaceUserWithExtraneousUser() throws Exception {
// first, creates the namespace for the admin user
createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
// then, add the creator user
Collaborator userModelCreatorCollaborator = new Collaborator();
userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME);
Set<String> roles = new HashSet<>();
roles.add("model_viewer");
userModelCreatorCollaborator.setRoles(roles);
repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
// creates a user with tenant admin privileges but no access to the namespace in question
SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor thirdUser = user("thirdPartyUser").password("pass");
userRepository.save(new UserBuilder().withAuthenticationProviderID(GITHUB).withName("thirdPartyUser").build());
// finally, change the user roles on the DTO and PUT again
roles.add("model_creator");
userModelCreatorCollaborator.setRoles(roles);
repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(thirdUser)).andExpect(status().isForbidden());
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method createTechnicalCollaboratorNoProvider.
@Test
public void createTechnicalCollaboratorNoProvider() throws Exception {
// creates the collaborator payload and the existing user
String otherUser = "userstandard2";
Collaborator collaborator = new Collaborator(otherUser, null, null, Lists.newArrayList("model_viewer", "model_creator"));
collaborator.setTechnicalUser(true);
repositoryServer.perform(post("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isBadRequest());
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method testAddNamespaceNonExistingUser.
/**
* Tests that adding an non-existing user to a namespace fails
*
* @throws Exception
*/
@Test
public void testAddNamespaceNonExistingUser() throws Exception {
// first, creates the namespace for the admin user
createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
// then, add the non-existing user
Collaborator nonExistingCollaborator = new Collaborator();
nonExistingCollaborator.setUserId("toto");
Set<String> roles = new HashSet<>();
roles.add("model_viewer");
nonExistingCollaborator.setRoles(roles);
repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(nonExistingCollaborator)).with(userSysadmin)).andExpect(status().isNotFound()).andExpect(content().string("false"));
}
Aggregations