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

Case insensitive lookup for deserialization type for header parameters #123

Merged
merged 3 commits into from
Feb 6, 2020
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 @@ -58,7 +58,11 @@ static void deserialize(HttpServerExchange exchange, OpenApiOperation openApiOpe
}

default boolean isApplicable(HttpServerExchange exchange, Parameter parameter, Set<String> candidateParams) {
return candidateParams.contains(parameter.getName());
// HTTP header names are case insensitive (RFC 7230, https://tools.ietf.org/html/rfc7230#section-3.2)
if(ParameterType.of(parameter.getIn()) == ParameterType.HEADER)
return candidateParams.stream().anyMatch(s->parameter.getName().equalsIgnoreCase(s));
else
return candidateParams.contains(parameter.getName());
}

default void deserialize(HttpServerExchange exchange, Parameter parameter, Set<String> candidateParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class IntegrationTest {
private static final Logger logger = LoggerFactory.getLogger(OpenApiHandlerTest.class);
private static final String EXPECTED_ARRAY_RESULT="3-4-5";
private static final String EXPECTED_MAP_RESULT="id-name-001-Dog";
private static final String EXPECTED_NEGATIVE_RESULT = "failed";

private static Undertow server = null;

Expand Down Expand Up @@ -294,6 +295,12 @@ static RoutingHandler setupRoutings() {
public void test_array_default_query_param_deserialization() throws Exception {
runTest("/pets?limit=3&limit=4&limit=5", EXPECTED_ARRAY_RESULT);
}

@Test
/** negative test: query params are case sensitive */
public void test_mixed_case_array_default_query_param_deserialization() throws Exception {
runTest("/pets?LIMIT=3&LIMIT=4&LIMIT=5", EXPECTED_NEGATIVE_RESULT);
}

@Test
public void test_array_no_explode_query_param_deserialization() throws Exception {
Expand Down Expand Up @@ -392,6 +399,14 @@ public void test_array_header_param_deserialization() throws Exception {

runTest("/pets_header_array", EXPECTED_ARRAY_RESULT, headers, Collections.emptyMap());
}

@Test
public void test_array_mixed_case_header_param_deserialization() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put("PeTiD", "3,4,5");

runTest("/pets_header_array", EXPECTED_ARRAY_RESULT, headers, Collections.emptyMap());
}

@Test
public void test_object_simple_explode_header_param_deserialization() throws Exception {
Expand All @@ -400,27 +415,50 @@ public void test_object_simple_explode_header_param_deserialization() throws Exc

runTest("/pets_header_obj_ep", EXPECTED_MAP_RESULT, headers, Collections.emptyMap());
}

@Test
public void test_object_simple_explode_mixed_case_header_param_deserialization() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put("PeTiD", "id=001,name=Dog");

runTest("/pets_header_obj_ep", EXPECTED_MAP_RESULT, headers, Collections.emptyMap());
}

@Test
public void test_object_simple_no_explode_header_param_deserialization() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put("petId", "id,001,name,Dog");
runTest("/pets_header_obj_no_ep", EXPECTED_MAP_RESULT, headers, Collections.emptyMap());
}

@Test
}

@Test
public void test_object_simple_no_explode_mixed_case_header_param_deserialization() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put("PeTiD", "id,001,name,Dog");
runTest("/pets_header_obj_no_ep", EXPECTED_MAP_RESULT, headers, Collections.emptyMap());
}

@Test
public void test_array_cookie_param_deserialization() throws Exception {
Map<String, String> cookies = new HashMap<>();
cookies.put("petId", "3,4,5");
runTest("/pets_cookie_array", EXPECTED_ARRAY_RESULT, Collections.emptyMap(), cookies);
}

@Test
/*** negative test: cookie params are case sensitive */
public void test_array_mixed_case_cookie_param_deserialization() throws Exception {
Map<String, String> cookies = new HashMap<>();
cookies.put("petid", "3,4,5");
runTest("/pets_cookie_array", EXPECTED_NEGATIVE_RESULT, Collections.emptyMap(), cookies);
}

@Test
public void test_object_simple_no_explode_cookie_param_deserialization() throws Exception {
Map<String, String> cookies = new HashMap<>();
cookies.put("petId", "id,001,name,Dog");
runTest("/pets_cookie_obj_no_ep", EXPECTED_MAP_RESULT, Collections.emptyMap(), cookies);
}
}

public void runTest(String requestPath, String expectedValue, Map<String, String> headers, Map<String, String> cookies) throws Exception {
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
Expand Down