Search in sources :

Example 26 with Collaborator

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());
}
Also used : SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 27 with Collaborator

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());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Test(org.junit.Test)

Example 28 with Collaborator

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"));
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Collaborator (org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)28 Test (org.junit.Test)24 HashSet (java.util.HashSet)10 UserBuilder (org.eclipse.vorto.repository.services.UserBuilder)5 Sets (com.google.common.collect.Sets)2 ModelId (org.eclipse.vorto.model.ModelId)2 ModelType (org.eclipse.vorto.model.ModelType)2 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 MediaType (org.springframework.http.MediaType)2 SecurityMockMvcRequestPostProcessors (org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors)2 MockMvcResultMatchers.content (org.springframework.test.web.servlet.result.MockMvcResultMatchers.content)2 MockMvcResultMatchers.status (org.springframework.test.web.servlet.result.MockMvcResultMatchers.status)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1