Search in sources :

Example 16 with Collaborator

use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.

the class ModelRepositoryControllerTest method deleteModelResource.

@Test
public void deleteModelResource() throws Exception {
    String modelId = "com.test.Location:1.0.0";
    String fileName = "Location.fbmodel";
    String json = createContent("Location.fbmodel");
    // making sure the model is not there
    repositoryServer.perform(delete("/rest/models/" + modelId).with(userSysadmin)).andExpect(status().isNotFound());
    createNamespaceSuccessfully("com.test", userSysadmin);
    Collaborator collaborator = new Collaborator();
    collaborator.setTechnicalUser(false);
    collaborator.setUserId(USER_MODEL_CREATOR_NAME);
    collaborator.setRoles(Sets.newHashSet("model_creator"));
    addCollaboratorToNamespace("com.test", collaborator);
    createModel(userModelCreator, fileName, modelId);
    repositoryServer.perform(delete("/rest/models/" + modelId).with(userSysadmin)).andExpect(status().isOk());
    this.repositoryServer.perform(put("/rest/models/" + modelId).contentType(MediaType.APPLICATION_JSON).content(json).with(userSysadmin)).andExpect(status().isNotFound());
    // delete non existent model
    repositoryServer.perform(delete("/rest/models/com.test:ASDASD:0.0.1").with(userSysadmin)).andExpect(status().isNotFound());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Test(org.junit.Test)

Example 17 with Collaborator

use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method testChangeUserRolesOnNamespaceUser.

/**
 * Tests that changing roles on a namespace works for an existing user who has been previously
 * added to that namespace.
 *
 * @throws Exception
 */
@Test
public void testChangeUserRolesOnNamespaceUser() 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"));
    // 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(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with Collaborator

use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method createTechnicalCollaboratorNoSubject.

@Test
public void createTechnicalCollaboratorNoSubject() throws Exception {
    Collaborator collaborator = new Collaborator("my-technical-user", BOSCH_IOT_SUITE_AUTH, 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 19 with Collaborator

use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method testAccessibleNamespacesWithRole.

/**
 * Verifies the list of namespaces where the logged on user has a given role is correct.
 *
 * @throws Exception
 */
@Test
public void testAccessibleNamespacesWithRole() throws Exception {
    // first, creates a namespace for the userModelCreator user
    createNamespaceSuccessfully("vorto.private.myNamespace", userModelCreator2);
    // now, creates a namespace for the userModelCreator2 user
    createNamespaceSuccessfully("vorto.private.myNamespace2", userModelCreator3);
    // Now adds userModelCreator to userModelCreator2's namespace as model creator
    Collaborator userModelCreatorCollaborator = new Collaborator();
    userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME_2);
    userModelCreatorCollaborator.setAuthenticationProviderId(GITHUB);
    userModelCreatorCollaborator.setSubject("none");
    Set<String> roles = new HashSet<>();
    roles.add("model_viewer");
    roles.add("model_creator");
    userModelCreatorCollaborator.setRoles(roles);
    repositoryServer.perform(put("/rest/namespaces/vorto.private.myNamespace2/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
    // finally, lists all namespaces where userModelCreator has the model_creator role, that is, their own
    // and userModelCreator2's namespace
    // expected namespaces
    Collection<NamespaceDto> expectedNamespaces = new ArrayList<>();
    // admins and users of the userModelCreator's namespace
    Collection<Collaborator> userModelCreatorNSAdmins = new ArrayList<>();
    Collection<Collaborator> userModelCreatorNSUsers = new ArrayList<>();
    /*
    Creating set of namespace owner roles
    */
    Set<String> ownerRoles = new HashSet<>();
    ownerRoles.add("model_viewer");
    ownerRoles.add("model_creator");
    ownerRoles.add("namespace_admin");
    ownerRoles.add("model_promoter");
    ownerRoles.add("model_reviewer");
    ownerRoles.add("model_publisher");
    // creating Collaborator for userModelCreator as admin in their own namespace
    Collaborator userModelCreatorCollaboratorAsAdmin = new Collaborator();
    userModelCreatorCollaboratorAsAdmin.setUserId(USER_MODEL_CREATOR_NAME_2);
    userModelCreatorCollaboratorAsAdmin.setAuthenticationProviderId(GITHUB);
    userModelCreatorCollaboratorAsAdmin.setSubject("none");
    userModelCreatorCollaboratorAsAdmin.setRoles(ownerRoles);
    userModelCreatorNSAdmins.add(userModelCreatorCollaboratorAsAdmin);
    // creating Collaborator for userModelCreator as user in their own namespace
    Collaborator userModelCreatorCollaboratorAsUserSysadmin = new Collaborator();
    userModelCreatorCollaboratorAsUserSysadmin.setUserId(USER_MODEL_CREATOR_NAME_2);
    userModelCreatorCollaboratorAsUserSysadmin.setAuthenticationProviderId(GITHUB);
    userModelCreatorCollaboratorAsUserSysadmin.setSubject("none");
    userModelCreatorCollaboratorAsUserSysadmin.setRoles(ownerRoles);
    userModelCreatorNSUsers.add(userModelCreatorCollaboratorAsUserSysadmin);
    // creating namespace for userModelCreator
    NamespaceDto userModelCreatorNS = new NamespaceDto("vorto.private.myNamespace", userModelCreatorNSUsers, userModelCreatorNSAdmins);
    // creating userModelCreator2 as a Collaborator object
    Collaborator userModelCreator2CollaboratorAsAdmin = new Collaborator();
    userModelCreator2CollaboratorAsAdmin.setUserId(USER_MODEL_CREATOR_NAME_3);
    userModelCreator2CollaboratorAsAdmin.setAuthenticationProviderId(GITHUB);
    userModelCreator2CollaboratorAsAdmin.setSubject("none");
    userModelCreator2CollaboratorAsAdmin.setRoles(ownerRoles);
    Collaborator userModelCreator2CollaboratorAsUserSysadmin = new Collaborator();
    userModelCreator2CollaboratorAsUserSysadmin.setUserId(USER_MODEL_CREATOR_NAME_3);
    userModelCreator2CollaboratorAsUserSysadmin.setAuthenticationProviderId(GITHUB);
    userModelCreator2CollaboratorAsUserSysadmin.setSubject("none");
    userModelCreator2CollaboratorAsUserSysadmin.setRoles(ownerRoles);
    // adding to userModelCreator2 namespace admins
    Collection<Collaborator> userModelCreator2NSAdmins = new ArrayList<>();
    userModelCreator2NSAdmins.add(userModelCreator2CollaboratorAsAdmin);
    // adding both userModelCreator2 collaborator and userModelCreator (the non-admin collaborator from up above)
    // to the userModelCreator2 namespace users
    Collection<Collaborator> userModelCreator2NSUsers = new ArrayList<>();
    userModelCreator2NSUsers.add(userModelCreator2CollaboratorAsUserSysadmin);
    userModelCreator2NSUsers.add(userModelCreatorCollaborator);
    // creating ns for userModelCreator2
    NamespaceDto userModelCreator2NS = new NamespaceDto("vorto.private.myNamespace2", userModelCreator2NSUsers, userModelCreator2NSAdmins);
    // adding both ns to expected collection
    expectedNamespaces.add(userModelCreatorNS);
    expectedNamespaces.add(userModelCreator2NS);
    repositoryServer.perform(get("/rest/namespaces/role/model_creator").with(userModelCreator2)).andExpect(status().isOk()).andExpect(content().json(objectMapper.writeValueAsString(expectedNamespaces)));
}
Also used : NamespaceDto(org.eclipse.vorto.repository.web.api.v1.dto.NamespaceDto) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with Collaborator

use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method updateCollaboratorNamespaceDoesNotExist.

@Test
public void updateCollaboratorNamespaceDoesNotExist() throws Exception {
    Collaborator collaborator = new Collaborator("userstandard2", GITHUB, null, Lists.newArrayList("model_viewer", "model_creator"));
    repositoryServer.perform(put("/rest/namespaces/com.unknown.namespace/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isNotFound());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) 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