Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR-Release #631

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public boolean handle(final RoutingContext ctx) {
}
}

if (requestMethod == GET && !request.params().isEmpty()) {
if (requestMethod == GET && null != request.getParam("q")) {
if (requestUri.contains(normalizedListenerBase) ) {
handleListenerSearch(request);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,35 +912,6 @@ public void testHandleGETRequestWithTrailingSlash(TestContext testContext) {
assertEmptyResult(jsonResponse);
}

@Test
public void testHandleGETRequestWithInvalidParam(TestContext testContext) {
// Define URI with an invalid parameter different from 'q'
GETRequest request = new GETRequest(HOOK_LISTENER_URI, mockResponse);
request.addParameter("invalidParam", "someValue"); // Invalid parameter, not 'q'

// Mock the RoutingContext
when(routingContext.request()).thenReturn(request);

// Capture the response content
ArgumentCaptor<String> responseCaptor = ArgumentCaptor.forClass(String.class);
when(mockResponse.setStatusCode(anyInt())).thenReturn(mockResponse);
when(mockResponse.end(responseCaptor.capture())).thenReturn(Future.succeededFuture());

// Execute the Handler
boolean result = hookHandler.handle(routingContext);

// Verify status 400 due to invalid parameter
verify(mockResponse).setStatusCode(StatusCode.BAD_REQUEST.getStatusCode());
testContext.assertTrue(result);

// Verify captured response content
String jsonResponse = responseCaptor.getValue();
testContext.assertNotNull(jsonResponse);
// Confirm that the response contains "Bad Request"
testContext.assertTrue(jsonResponse.contains("Only the 'q' parameter is allowed and can't be empty or null"));
}


///////////////////////////////////////////////////////////////////////////////
// Helpers
///////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,11 @@ public void testRequestForwardingForTwoListenerAtSameResourceButDifferentHeaders
}

@Test
public void testSearchListenerWithValidAndInvalidSearchParam(TestContext context) {
public void testSearchListenerWithDifferentParams(TestContext context) {
Async async = context.async();
registerDefaultListener();

searchWithQueryParam("wq", defaultListenerName, 400);
searchWithQueryParam("storageExpand", "true", 200);
searchWithQueryParam("expand", "1", 200);
searchWithQueryParam("q", "", 400);

Response response = searchWithQueryParam("q",defaultListenerName,200);
Expand Down Expand Up @@ -940,20 +940,6 @@ public void testHookHandleSearch_NoListenersRegistered(TestContext context) {
async.complete();
}

@Test
public void testHookHandleSearch_ListenerPathInvalidParam(TestContext context) {
Async async = context.async();
delete();
initRoutingRules();

String queryParam = "testQuery";
String requestUrl = searchUrlBase+ "?www=" + queryParam;

// Validate the response
checkGETStatusCodeWithAwait(requestUrl, 400);
async.complete();
}

@Test
public void testHookHandleSearch_ListenerTwoParam(TestContext context) {
Async async = context.async();
Expand Down Expand Up @@ -1042,7 +1028,7 @@ public void testHookHandleSearch_ReturnsTwoOutOfThreeListeners(TestContext conte
// added in searchUrlBase a '/' to validate if also works
Response response = given()
.queryParam("q", "listener")
.when().get(searchUrlBase+"/")
.when().get(searchUrlBase + "/")
.then().assertThat().statusCode(200)
.extract().response();

Expand Down Expand Up @@ -1170,7 +1156,7 @@ private void checkGETBodyWithAwait(final String requestUrl, final String body) {
private Response searchWithQueryParam(String searchParam, String queryParam, int expectedStatusCode ) {
return given()
.queryParam(searchParam, queryParam)
.when().get(searchUrlBase)
.when().get(searchUrlBase + "/")
.then().assertThat().statusCode(expectedStatusCode)
.extract().response();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public void testHookHandleSearch_WithValidAndInvalidSearchParam(TestContext cont
addRoute(queryParam, true, true);

// Verify that the route was correctly registered
searchWithQueryParam("w", queryParam, 400);
searchWithQueryParam("q", "", 400);

// Verify that the route was correctly registered
Expand All @@ -232,7 +231,7 @@ public void testHookHandleSearch_RouteNonMatchingQueryParam(TestContext context)

// Register a route using the addRoute method
addRoute(queryParam, true, true);
assertResponse(get(requestUrlBase), new String[]{queryParam+"/"});
assertResponse(get(requestUrlBase), new String[]{queryParam + "/"});

Response response = searchWithQueryParam("q", queryParam, 200);
Assert.assertTrue("Query param should be found in response",
Expand Down