use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class RoleControllerUnitTest method testAddWithInvalidCodeAndName.
@Test
public void testAddWithInvalidCodeAndName() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ObjectMapper mapper = new ObjectMapper();
RoleRequest request = new RoleRequest();
request.setCode(StringUtils.repeat("a", 100));
request.setName(StringUtils.repeat("b", 100));
// request.setCode(code);
String payload = mapper.writeValueAsString(request);
ResultActions result = mockMvc.perform(post("/roles").contentType(MediaType.APPLICATION_JSON_VALUE).content(payload).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerDeleteAuthoritiesIntegrationTest method testDeleteAuthorities.
@Test
public void testDeleteAuthorities() throws Exception {
String accessToken = "ok";
when(apiOAuth2TokenManager.readAccessToken(Mockito.anyString())).thenReturn(OAuth2TestUtils.getOAuth2Token("admin", "ok"));
String username = "valid.username_ok";
String password = "valid.123_ok";
String groupName = "coach";
String roleName = "pageManager";
try {
this.addUserWithAuthorization(username, password, groupName, roleName);
UserDetails targetUser = this.authenticationProviderManager.getUser(username);
boolean hasAuthorities = this.authorizationManager.isAuthOnGroupAndRole(targetUser, groupName, roleName, false);
assertThat(hasAuthorities, is(true));
ResultActions result = this.executeDeleteUserAuthorities(username, accessToken);
result.andExpect(status().isOk());
targetUser = this.authenticationProviderManager.getUser(username);
hasAuthorities = this.authorizationManager.isAuthOnGroupAndRole(targetUser, groupName, roleName, false);
assertThat(hasAuthorities, is(false));
} catch (Throwable e) {
throw e;
} finally {
this.authorizationManager.deleteUserAuthorizations(username);
this.userManager.removeUser(username);
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerDeleteAuthoritiesIntegrationTest method testDeleteAuthoritiesSameUser.
@Test
public void testDeleteAuthoritiesSameUser() throws Exception {
String currentUserName = "admin";
String accessToken = "ok";
when(apiOAuth2TokenManager.readAccessToken(Mockito.anyString())).thenReturn(OAuth2TestUtils.getOAuth2Token(currentUserName, "ok"));
try {
ResultActions result = this.executeDeleteUserAuthorities(currentUserName, accessToken);
result.andExpect(status().isForbidden());
String response = result.andReturn().getResponse().getContentAsString();
System.out.println("resp:" + response);
result.andExpect(jsonPath("$.errors[0].code", is(UserValidator.ERRCODE_SELF_UPDATE)));
assertThat(this.authorizationManager.getUserAuthorizations(currentUserName).size(), is(Matchers.greaterThanOrEqualTo(1)));
} catch (Throwable e) {
throw e;
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class RoleControllerIntegrationTest method testGetRoleNotFound.
@Test
public void testGetRoleNotFound() throws Exception {
String code = "this_role_has_no_name";
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/roles/{rolecode}", code).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isNotFound());
// result.andExpect(jsonPath("$.payload.permissions.length()", greaterThan(0)));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class RoleControllerIntegrationTest method testGetRolesFilterByCode.
@Test
public void testGetRolesFilterByCode() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/roles").param("filter[0].attribute", "code").param("filter[0].value", "admin").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.length()", is(1)));
}
Aggregations