Skip to content

Commit

Permalink
feat: added error handling for missing kc user (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored Dec 3, 2024
1 parent 549d9ce commit af165dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tkit.onecx.permission.bff.rs.mappers.AssignmentMapper;
import org.tkit.onecx.permission.bff.rs.mappers.ExceptionMapper;
import org.tkit.onecx.permission.bff.rs.mappers.UserMapper;
Expand All @@ -34,6 +36,7 @@
@LogService
public class AssignmentRestController implements AssignmentApiService {

private static final Logger log = LoggerFactory.getLogger(AssignmentRestController.class);
@RestClient
@Inject
AssignmentInternalApi assignmentClient;
Expand Down Expand Up @@ -162,6 +165,9 @@ public Response searchUserAssignments(AssignmentUserSearchCriteriaDTO assignment
if (roleResponse.getRoles() != null) {
roles = roleResponse.getRoles().stream().map(RoleIamV1::getName).toList();
}
} catch (ClientWebApplicationException exception) {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
.entity(exceptionMapper.exception("400", "USER_NOT_FOUND")).build();
}
if (roles.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).build();
Expand Down
2 changes: 2 additions & 0 deletions src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ components:
type: integer
AssignmentUserSearchCriteria:
type: object
required:
- userId
properties:
userId:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,31 @@ void searchUsersAssignmentsByCriteria_No_Roles_Test() {
mockServerClient.clear("MOCK_IAM_KC");
}

@Test
void searchUsersAssignmentsByCriteria_KC_SVC_ROLES_NOT_FOUND_Test() {

// create mock rest endpoint
mockServerClient.when(request().withPath("/v1/user/roles/user1").withMethod(HttpMethod.GET))
.withId("MOCK_IAM_KC")
.respond(httpRequest -> response().withStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));

AssignmentUserSearchCriteriaDTO criteriaDTO = new AssignmentUserSearchCriteriaDTO();
criteriaDTO.pageNumber(1).userId("user1").pageSize(1);

var errorResponse = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
.header(APM_HEADER_PARAM, ADMIN)
.contentType(APPLICATION_JSON)
.body(criteriaDTO)
.post("/user/search")
.then()
.statusCode(Response.Status.BAD_REQUEST.getStatusCode())
.extract().as(ProblemDetailResponseDTO.class);
Assertions.assertEquals("USER_NOT_FOUND", errorResponse.getDetail());
mockServerClient.clear("MOCK_IAM_KC");
}

@Test
void searchUsersAssignmentsByCriteria_error_kc_Test() {

Expand Down

0 comments on commit af165dc

Please sign in to comment.