Skip to content

Commit

Permalink
AYS-487 | Added exception handling for AysUserNotSuperAdminException …
Browse files Browse the repository at this point in the history
…class (#381)

Co-authored-by: agitrubard <[email protected]>
  • Loading branch information
suhakopan and agitrubard authored Sep 28, 2024
1 parent c6b1cd4 commit 34e83b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.ays.auth.util.exception;

import org.ays.common.util.exception.AysBadRequestException;
import org.springframework.security.access.AccessDeniedException;

import java.io.Serial;

/**
* Exception to be thrown when a user is not a super admin but tries to perform an action that requires super admin privileges.
*/
public final class AysUserNotSuperAdminException extends AysBadRequestException {
public final class AysUserNotSuperAdminException extends AccessDeniedException {

/**
* Unique identifier for serialization.
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void givenValidRoleCreateRequest_whenRoleCreated_thenReturnSuccess() throws Exce
}

@Test
void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnBadRequestError() throws Exception {
void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnForbiddenError() throws Exception {

// Initialize
List<AysPermission> permissions = permissionReadPort.findAll();
Expand All @@ -392,11 +392,11 @@ void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, adminToken.getAccessToken(), createRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST;
AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.FORBIDDEN;

aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.isForbidden())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.doesNotHaveJsonPath());

Expand Down Expand Up @@ -514,7 +514,7 @@ void givenValidRoleUpdateRequest_whenRoleUpdated_thenReturnSuccess() throws Exce
}

@Test
void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnBadRequestError() throws Exception {
void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnForbiddenError() throws Exception {

// Initialize
List<AysPermission> permissions = permissionReadPort.findAll();
Expand Down Expand Up @@ -543,11 +543,11 @@ void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNot
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.put(endpoint, adminToken.getAccessToken(), updateRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST;
AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.FORBIDDEN;

aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.isForbidden())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.doesNotHaveJsonPath());

Expand Down

0 comments on commit 34e83b6

Please sign in to comment.