add controller test + fix check method

This commit is contained in:
ggmaleva 2021-03-05 14:43:32 +03:00
parent e177a2a275
commit a88353e54d
2 changed files with 15 additions and 1 deletions

View File

@ -144,7 +144,7 @@ public class OrgsController implements OrgsApi {
String userId,
MemberRole body) {
log.info("Assign member role: requestId={}, orgId={}, payload={}", xRequestID, orgId, body);
resourceAccessService.checkRoleRights(orgId, body);
resourceAccessService.checkMemberRoleRights(orgId, userId, body);
return organizationService.assignMemberRole(orgId, userId, body);
}

View File

@ -97,6 +97,20 @@ public class OrgsControllerTest extends AbstractControllerTest {
.andExpect(status().isForbidden());
}
@Test
public void assignMemberRoleWithoutAccess() throws Exception {
MemberRole memberRole = TestData.buildMemberRole();
doThrow(new AccessDeniedException("Access denied")).when(resourceAccessService)
.checkMemberRoleRights(ORGANIZATION_ID, MEMBER_ID, memberRole);
mockMvc.perform(put(String.format("/orgs/%s/members/%s/roles", ORGANIZATION_ID, MEMBER_ID))
.contentType("application/json")
.content(objectMapper.writeValueAsString(memberRole))
.header("Authorization", "Bearer " + generateRBKadminJwt())
.header("X-Request-ID", "testRequestId"))
.andExpect(status().isForbidden());
}
@Test
public void assignMemberRoleTest() throws Exception {
MemberRole memberRole = TestData.buildMemberRole();