FINERACT-1678: Enable Scheduler API usage for batch manager only

This commit is contained in:
Adam Saghy
2023-03-02 19:26:05 +01:00
parent 8090c614ed
commit f1c89ac914
4 changed files with 49 additions and 3 deletions
@@ -43,6 +43,7 @@ public class FineractInstanceModeApiFilter extends OncePerRequestFilter {
private static final List<ExceptionListItem> EXCEPTION_LIST = List
.of(item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi -> pi.startsWith("/jobs")),
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi -> pi.startsWith("/scheduler")),
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi -> pi.startsWith("/loans/catch-up")),
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled,
pi -> pi.startsWith("/loans/is-catch-up-running")),
@@ -368,4 +368,31 @@ class FineractInstanceModeApiFilterTest {
// then
verify(filterChain).doFilter(request, response);
}
@Test
void testDoFilterInternal_ShouldLetSchedulerApiThrough_WhenFineractIsInBatchManagerMode() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, false, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/scheduler?command=start");
// when
underTest.doFilterInternal(request, response, filterChain);
// then
verify(filterChain).doFilter(request, response);
}
@Test
void testDoFilterInternal_ShouldNotLetSchedulerApiThrough_WhenFineractIsNotInBatchManagerMode() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, true, true, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/scheduler?command=start");
// when
underTest.doFilterInternal(request, response, filterChain);
// then
verifyNoInteractions(filterChain);
verify(response).setStatus(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
}