diff --git a/src/main/java/org/folio/rest/exception/TokenNotFoundException.java b/src/main/java/org/folio/rest/exception/TokenNotFoundException.java index 17cfc472..6fa241da 100644 --- a/src/main/java/org/folio/rest/exception/TokenNotFoundException.java +++ b/src/main/java/org/folio/rest/exception/TokenNotFoundException.java @@ -2,10 +2,6 @@ public class TokenNotFoundException extends RuntimeException { - public TokenNotFoundException() { - super(); - } - public TokenNotFoundException(String message) { super(message); } diff --git a/src/main/java/org/folio/rest/util/ExceptionHelper.java b/src/main/java/org/folio/rest/util/ExceptionHelper.java index 716a8b38..2e13e296 100644 --- a/src/main/java/org/folio/rest/util/ExceptionHelper.java +++ b/src/main/java/org/folio/rest/util/ExceptionHelper.java @@ -45,7 +45,7 @@ public static Response handleException(Throwable throwable) { .type(MediaType.TEXT_PLAIN) .entity(throwable.getMessage()) .build(); - } else if(throwable.getClass() == TokenNotFoundException.class){ + } else if (throwable.getClass() == TokenNotFoundException.class){ return Response.status(HttpStatus.SC_NOT_FOUND) .type(MediaType.TEXT_PLAIN) .entity(throwable.getMessage()) diff --git a/src/test/java/org/folio/rest/GeneratePasswordRestLinkTest.java b/src/test/java/org/folio/rest/GeneratePasswordRestLinkTest.java index 0fb1cb37..4db511d4 100644 --- a/src/test/java/org/folio/rest/GeneratePasswordRestLinkTest.java +++ b/src/test/java/org/folio/rest/GeneratePasswordRestLinkTest.java @@ -391,6 +391,37 @@ public void cannotGeneratePasswordWhenTokenSignLegacyEndPointReturns500( } + public void shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404( + String expirationTime, String expirationTimeOfUnit, String expectedExpirationTime, + String expectedExpirationTimeOfUnit) { + Map configToMock = new HashMap<>(); + configToMock.put(FOLIO_HOST_CONFIG_KEY, MOCK_FOLIO_UI_HOST); + configToMock.put(RESET_PASSWORD_LINK_EXPIRATION_TIME, expirationTime); + configToMock.put(RESET_PASSWORD_LINK_EXPIRATION_UNIT_OF_TIME, expirationTimeOfUnit); + User mockUser = new User() + .withId(UUID.randomUUID().toString()) + .withUsername(MOCK_USERNAME); + boolean passwordExists = true; + + mockUserFound(mockUser.getId(), mockUser); + mockConfigModule(MODULE_NAME, configToMock); + mockSignAuthTokenNotFound(); + mockSignAuthTokenLegacyNotFound(); + mockPostPasswordResetAction(passwordExists); + mockNotificationModule(); + + JsonObject requestBody = new JsonObject() + .put("userId", mockUser.getId()); + RestAssured.given() + .spec(spec) + .header(mockUrlHeader) + .body(requestBody.encode()) + .when() + .post(GENERATE_PASSWORD_RESET_LINK_PATH) + .then() + .statusCode(HttpStatus.SC_NOT_FOUND); + + } @Test public void shouldGenerateAndSendCreatePasswordNotificationWhenPasswordExists() { Map configToMock = new HashMap<>(); @@ -526,6 +557,11 @@ public void cannotGeneratePasswordWhenTokenSignLegacyEndPointReturns500() { EXPIRATION_UNIT_OF_TIME_MINUTES, EXPIRATION_TIME_MINUTES, EXPIRATION_UNIT_OF_TIME_MINUTES); } + @Test + public void shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404() { + shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404(EXPIRATION_TIME_DAYS, + EXPIRATION_UNIT_OF_TIME_DAYS, EXPIRATION_TIME_DAYS, EXPIRATION_UNIT_OF_TIME_DAYS); + } private String toJson(Object object) { return JsonObject.mapFrom(object).toString(); } @@ -583,6 +619,11 @@ private void mockSignAuthTokenLegacyServerError() { .willReturn(WireMock.serverError())); } + private void mockSignAuthTokenLegacyNotFound() { + WireMock.stubFor(WireMock.post("/token") + .willReturn(WireMock.notFound())); + } + private void mockNotificationModule() { WireMock.stubFor(WireMock.post(NOTIFY_PATH) .willReturn(WireMock.created()));