ExpansionHandler implements RuleChangesObserver { public void handleExpansionRecursion(final HttpServerRequest request) { removeZipParameter(request); handleExpansionRequest(request, RecursiveHandlerFactory.RecursiveHandlerTypes.EXPANSION); } ExpansionHandler(Vertx vertx, final ResourceStorage storage, HttpClient httpClient, final Map<String, Object> properties, String serverRoot, final String rulesPath); @Override void rulesChanged(List<Rule> rules); int getMaxExpansionLevelSoft(); int getMaxExpansionLevelHard(); int getMaxSubRequestCount(); boolean isExpansionRequest(HttpServerRequest request); boolean isZipRequest(HttpServerRequest request); void handleExpansionRecursion(final HttpServerRequest request); void handleZipRecursion(final HttpServerRequest request); boolean isCollection(String target); static final String SERIOUS_EXCEPTION; static final String EXPAND_PARAM; static final String ZIP_PARAM; static final String MAX_EXPANSION_LEVEL_SOFT_PROPERTY; static final String MAX_EXPANSION_LEVEL_HARD_PROPERTY; static final String MAX_SUBREQUEST_PROPERTY; }
@Test public void testBadRequestResponseForInvalidExpandParameterRequests(TestContext context) { expansionHandler = new ExpansionHandler(vertx, storage, httpClient, new HashMap<>(), ROOT, RULES_ROOT); CaseInsensitiveHeaders params = new CaseInsensitiveHeaders(); params.set(EXPAND_PARAM, "foo"); HttpServerResponse response = Mockito.mock(HttpServerResponse.class); Request request = new Request(HttpMethod.GET, "/some/expandRequest/uri", params, response); expansionHandler.handleExpansionRecursion(request); verify(response, times(1)).setStatusCode(StatusCode.BAD_REQUEST.getStatusCode()); verify(response, times(1)).setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage()); verify(response, times(1)).end("Expand parameter is not valid. Must be a positive number"); verifyZeroInteractions(httpClient); }
@Test public void testBadRequestResponseForExceedingMaxExpansionLevelHard(TestContext context) { Map<String, Object> properties = new HashMap<>(); properties.put("max.expansion.level.hard", "10"); expansionHandler = new ExpansionHandler(vertx, storage, httpClient, properties, ROOT, RULES_ROOT); CaseInsensitiveHeaders params = new CaseInsensitiveHeaders(); params.set(EXPAND_PARAM, "15"); HttpServerResponse response = Mockito.mock(HttpServerResponse.class); Request request = new Request(HttpMethod.GET, "/some/expandRequest/uri", params, response); expansionHandler.handleExpansionRecursion(request); verify(response, times(1)).setStatusCode(StatusCode.BAD_REQUEST.getStatusCode()); verify(response, times(1)).setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage()); verify(response, times(1)).end("Expand level '15' is greater than the maximum expand level '10'"); verifyZeroInteractions(httpClient); }