use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.
the class WorkflowTest method testStartReleaseModelWithReviewedDependencies.
@Test
public void testStartReleaseModelWithReviewedDependencies() throws Exception {
ModelInfo typeModel = importModel("Color.type");
workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
ModelInfo fbModel = importModel("Colorlight.fbmodel");
workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
workflow.doAction(typeModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
assertEquals("InReview", workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName()).getState());
}
use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method testRemoveExistingUserFromNamespaceWithNoPrivileges.
/**
* Tests that removing an existing user from a namespace fails if the user performing the operation
* has no "tenant admin" role for that namespace. <br/>
* In this case, we're creating a third user with tenant admin authority, who is not added as
* admin of that namespace, and will try to remove the simple user.<br/>
* Note that it might be worth thinking of the edge case where a user simply wants to be removed
* from a namespace they have been added to, regardless of their role in that namespace. <br/>
* See {@link org.eclipse.vorto.repository.web.api.v1.NamespaceController#removeUserFromNamespace(String, String)}
* for specifications on how authorization is enforced.
*
* @throws Exception
*/
@Test
public void testRemoveExistingUserFromNamespaceWithNoPrivileges() throws Exception {
// first, creates the namespace for the admin user
createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
Collaborator userModelCreatorCollaborator = new Collaborator();
userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME);
Set<String> roles = new HashSet<>();
roles.add("model_viewer");
userModelCreatorCollaborator.setRoles(roles);
// adds the collaborator with "model_viewer" roles to the namespace
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 removes the user from the namespace but with the "thirdPartyUser" who is tenant admin
// "somewhere else", which fails due to lack of tenant admin role on that given namespace
repositoryServer.perform(delete(String.format("/rest/namespaces/myAdminNamespace/users/%s", USER_MODEL_CREATOR_NAME)).with(thirdUser)).andExpect(status().isForbidden());
}
use of org.eclipse.vorto.repository.services.UserBuilder 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());
}
use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.
the class HydraTokenVerifierTest method getVerifier.
private BoschIoTSuiteOAuthProviderAuthCode getVerifier() throws InvalidUserException {
User user = new UserBuilder().withName("d758a35e-94ef-443f-9625-7f03092e2005").withAuthenticationProviderID("GITHUB").build();
DefaultUserAccountService userAccountService = Mockito.mock(DefaultUserAccountService.class);
when(userAccountService.getUser("d758a35e-94ef-443f-9625-7f03092e2005")).thenReturn(user);
UserNamespaceRoleService userNamespaceRoleService = Mockito.mock(UserNamespaceRoleService.class);
return new BoschIoTSuiteOAuthProviderAuthCode("", publicKey(), configuration, userAccountService, userNamespaceRoleService);
}
Aggregations