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"));
}
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());
}
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)));
}
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"));
}
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());
}
Aggregations