Search in sources :

Example 6 with Collaborator

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

the class NamespaceControllerIntegrationTest method testRemoveExistingUserFromNamespace.

/**
 * Tests that removing an existing user from a namespace works if the user has been added previously
 * and the user removing it has the rights to do so.
 *
 * @throws Exception
 */
@Test
public void testRemoveExistingUserFromNamespace() throws Exception {
    // first, creates the namespace for the admin user
    createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
    // then, add the creator user
    Collaborator userModelCreatorCollaborator = new Collaborator();
    // you would think a user called "userModelCreator" has a username called "userModelCreator", but
    // the way it has been mapped to in the parent class is "user3" instead
    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"));
    // now removes the user
    repositoryServer.perform(delete(String.format("/rest/namespaces/myAdminNamespace/users/%s", USER_MODEL_CREATOR_NAME)).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 7 with Collaborator

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

the class NamespaceControllerIntegrationTest method updateCollaboratorNoSubject.

@Test
public void updateCollaboratorNoSubject() throws Exception {
    // creates the collaborator payload and the existing user
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, GITHUB, null, Lists.newArrayList("model_viewer", "model_creator"));
    userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
    repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 8 with Collaborator

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

the class NamespaceControllerIntegrationTest method testFindAllAccessibleNamespacesByPartial.

// newer tests
/**
 * Verifies that the set of namespaces retrieved by searching for all accessible namespaces by a
 * partial substring of the name for a given user returns both all public namespaces with partial
 * matches, and all private namespaces with partial matches (where the user has at least one role).<br/>
 * This is used by the "request access to namespace" form.
 *
 * @throws Exception
 */
@Test
public void testFindAllAccessibleNamespacesByPartial() throws Exception {
    // creates a public namespace as sysadmin and adds userModelCreator as collaborator
    String publicNamespaceName = "org.publicnamespace.abcd";
    createNamespaceSuccessfully(publicNamespaceName, userSysadmin);
    Collaborator collaborator = new Collaborator("userModelCreator", "GITHUB", null, Lists.newArrayList("model_viewer", "model_creator"));
    repositoryServer.perform(put(String.format("/rest/namespaces/%s/users", publicNamespaceName)).content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
    // creates a private namespace where the searched name would match, but the userModelCreator has
    // no role
    createNamespaceSuccessfully("vorto.private.sysadmin.abcd", userSysadmin);
    // creates a private namespace for userModelCreator
    String privateNamespaceName = "vorto.private.mynamespace.abcd";
    createNamespaceSuccessfully(privateNamespaceName, userModelCreator);
    // now compares expected namespaces to appear in search with REST endpoint outcome
    // note that users and admins in returned DTOs are empty here by design
    // also note that the namespaces are sorted by name
    List<NamespaceDto> expectedNamespaces = Arrays.asList(new NamespaceDto(publicNamespaceName, Collections.emptyList(), Collections.emptyList()), new NamespaceDto(privateNamespaceName, Collections.emptyList(), Collections.emptyList()));
    repositoryServer.perform(get("/rest/namespaces/search/abcd").with(userModelCreator)).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) Test(org.junit.Test)

Example 9 with Collaborator

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

the class NamespaceControllerIntegrationTest method testHasRoleOnNamespace.

/**
 * Tests that checking whether the logged on user has a given role on a given namespace works as
 * expected.<br/>
 * The endpoint is a simplification of the former TenantService.js all deferred to the back-end,
 * and is used contextually to verifying whether a user can modify a model.
 *
 * @throws Exception
 */
@Test
public void testHasRoleOnNamespace() 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"));
    // now checks whether the user has model_viewer role
    repositoryServer.perform(get("/rest/namespaces/model_viewer/myAdminNamespace").with(userModelCreator)).andExpect(status().isOk()).andExpect(content().string("true"));
    // finally, checks whether the user has model_creator role, which they haven't
    repositoryServer.perform(get("/rest/namespaces/model_creator/myAdminNamespace").with(userModelCreator)).andExpect(status().isOk()).andExpect(content().string("false"));
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Collaborator

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

the class NamespaceControllerIntegrationTest method updateCollaboratorWithoutPermissions.

@Test
public void updateCollaboratorWithoutPermissions() throws Exception {
    // creates user and collaborator to add
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, GITHUB, null, Lists.newArrayList("model_viewer", "model_creator"));
    userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
    // tries to add other user as yet another user, who has no rights to that namespace
    repositoryServer.perform(put(String.format("/rest/namespaces/%s/users", "com.mycompany")).content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userModelViewer)).andExpect(status().isForbidden());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) 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