Search in sources :

Example 11 with Collaborator

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

the class NamespaceControllerIntegrationTest method updateCollaborator.

@Test
public void updateCollaborator() throws Exception {
    // creates and adds a collaborator
    Collaborator collaborator = new Collaborator(USER_MODEL_CREATOR_NAME, GITHUB, "none", Lists.newArrayList("model_viewer", "model_creator"));
    repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
    // checks the collaborator's roles are returned correctly
    checkCollaboratorRoles("com.mycompany", USER_MODEL_CREATOR_NAME, "model_viewer", "model_creator");
    // creates and adds another collaborator with different roles
    collaborator = new Collaborator(USER_MODEL_VIEWER_NAME, GITHUB, "none", Lists.newArrayList("model_viewer"));
    repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
    // checks the collaborator's roles are returned correctly
    checkCollaboratorRoles("com.mycompany", USER_MODEL_VIEWER_NAME, "model_viewer");
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Test(org.junit.Test)

Example 12 with Collaborator

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

the class NamespaceControllerIntegrationTest method updateCollaboratorUnknownProvider.

/**
 * The difference between POST and PUT operations on collaborators essentially boils down to:
 * <ul>
 *   <li>
 *     POST ops mean creating a new technical user, and therefore validate the whole collaborator
 *     payload but assume the user does not exist.
 *   </li>
 *   <li>
 *     PUT ops mean adding an existing user to the namespace, and therefore only perform minimal
 *     validation (i.e. the user name), yet assume the user exists and fail otherwise.
 *   </li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public void updateCollaboratorUnknownProvider() throws Exception {
    // creates the collaborator payload and the existing user
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, "unknownProvider", 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 13 with Collaborator

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

the class NamespaceControllerIntegrationTest method testAddNamespaceUserWithOneRole.

/**
 * Simply tests that adding an existing user to a namespace with a basic role works as intended.
 *
 * @throws Exception
 */
@Test
public void testAddNamespaceUserWithOneRole() 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"));
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with Collaborator

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

the class IntegrationTestBase method checkCollaboratorRoles.

protected void checkCollaboratorRoles(String namespaceName, String collaboratorName, String... roles) throws Exception {
    repositoryServer.perform(get(String.format("/rest/namespaces/%s/users", namespaceName)).with(userSysadmin)).andDo(handler -> {
        Collection<Collaborator> collaborators = objectMapper.readValue(handler.getResponse().getContentAsString(), new TypeReference<Collection<Collaborator>>() {
        });
        Optional<Collaborator> maybeTarget = collaborators.stream().filter(c -> c.getUserId().equals(collaboratorName)).findAny();
        assertTrue(maybeTarget.isPresent());
        if (maybeTarget.isPresent()) {
            Collaborator target = maybeTarget.get();
            assertEquals(Arrays.asList(roles), target.getRoles());
        }
    });
}
Also used : OperationResult(org.eclipse.vorto.repository.web.api.v1.dto.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) GsonBuilder(com.google.gson.GsonBuilder) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapperFactory(org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory) Gson(com.google.gson.Gson) VortoRepository(org.eclipse.vorto.repository.web.VortoRepository) SpringRunner(org.springframework.test.context.junit4.SpringRunner) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LocalServerPort(org.springframework.boot.context.embedded.LocalServerPort) MediaType(org.springframework.http.MediaType) UserService(org.eclipse.vorto.repository.services.UserService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) ModelId(org.eclipse.vorto.model.ModelId) Sql(org.springframework.test.context.jdbc.Sql) Sets(com.google.common.collect.Sets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Configuration(org.springframework.context.annotation.Configuration) IOUtils(org.apache.commons.io.IOUtils) SecurityMockMvcConfigurers.springSecurity(org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) java.util(java.util) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ClassPathResource(org.springframework.core.io.ClassPathResource) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) ModelLink(org.eclipse.vorto.repository.web.api.v1.dto.ModelLink) Value(org.springframework.beans.factory.annotation.Value) MockMvc(org.springframework.test.web.servlet.MockMvc) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Before(org.junit.Before) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) Profile(org.springframework.context.annotation.Profile) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) SecurityMockMvcRequestPostProcessors.user(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user) ModelType(org.eclipse.vorto.model.ModelType) IModelPolicyManager(org.eclipse.vorto.repository.core.IModelPolicyManager) UserRepository(org.eclipse.vorto.repository.repositories.UserRepository) ContextConfiguration(org.springframework.test.context.ContextConfiguration) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) Bean(org.springframework.context.annotation.Bean) Assert.assertEquals(org.junit.Assert.assertEquals) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)

Example 15 with Collaborator

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

the class IntegrationTestBase method userModelCreatorCollaborator.

protected Collaborator userModelCreatorCollaborator() {
    Collaborator collaborator = new Collaborator();
    collaborator.setUserId(USER_MODEL_CREATOR_NAME);
    collaborator.setRoles(Sets.newHashSet("model_creator", "model_viewer"));
    collaborator.setAuthenticationProviderId("GITHUB");
    collaborator.setTechnicalUser(false);
    return collaborator;
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)

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