-
Notifications
You must be signed in to change notification settings - Fork 73
fix: Fix writting all headers in HTTP responses #4522
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
30f4b70
draft of the fix
pavel-jares-bcm 8e54689
test on GW
pavel-jares-bcm c2b53cb
rollout + tests
pavel-jares-bcm 623ac7e
fix checkstyle issues
pavel-jares-bcm 858c0c6
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm 46f6eb3
add @DirtiesContext
pavel-jares-bcm 2904316
add @DirtiesContext to Metrics test
pavel-jares-bcm a103dde
removal of not necessary tests - replaced by acceptance one
pavel-jares-bcm 0283187
fix sonar issue by renaming of copied private methods
pavel-jares-bcm 3539058
sonar issues
pavel-jares-bcm 2c2a9e1
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm a1f3427
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm 941ebff
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm 5fd151d
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm 9ff96a2
code review
pavel-jares-bcm 2f40d54
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm 480a3ee
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm dbb602a
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm ea59113
Merge branch 'v2.x.x' into reboot/cve-2026-22732
pavel-jares-bcm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...og-services/src/test/java/org/zowe/apiml/apicatalog/acceptance/ResponseHeaderFixTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.apicatalog.acceptance; | ||
|
|
||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.web.server.LocalServerPort; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.test.annotation.DirtiesContext; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.zowe.apiml.apicatalog.ApiCatalogApplication; | ||
|
|
||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import static io.restassured.RestAssured.given; | ||
| import static javax.servlet.http.HttpServletResponse.SC_OK; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.notNullValue; | ||
|
|
||
| @SpringBootTest( | ||
| classes = { | ||
| ApiCatalogApplication.class, | ||
| ResponseHeaderFixTest.TestController.class | ||
| }, | ||
| webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT | ||
| ) | ||
| @ActiveProfiles("ResponseHeaderFixTest") | ||
| @DirtiesContext | ||
| class ResponseHeaderFixTest { | ||
|
|
||
| private static final int TEST_CONTENT_LENGTH = 101; | ||
| private static final String CONTENT_LENGTH = "Content-Length"; | ||
|
|
||
| @LocalServerPort | ||
| protected int port; | ||
|
|
||
| @ParameterizedTest(name = "Test handling setting context-type using {1}") | ||
| @CsvSource({ | ||
| "0,addHeader<String String>", | ||
| "1,setHeader<String String>", | ||
| "2,setIntHeader<String int>", | ||
| "3,addIntHeader<String int>" | ||
| }) | ||
| void givenRequest_whenSetContentLength_thenIsPropagated(int method, String description) { | ||
| given() | ||
| .relaxedHTTPSValidation() | ||
| .when() | ||
| .get(String.format("https://localhost:%d/apicatalog/test/%d/%s", port, method, CONTENT_LENGTH)) | ||
| .then() | ||
| .statusCode(SC_OK) | ||
| .header(CONTENT_LENGTH, String.valueOf(TEST_CONTENT_LENGTH)) | ||
| .header("X-XSS-Protection", is(notNullValue())); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "Test handling headers without content-type using {1}") | ||
| @CsvSource({ | ||
| "0,addHeader<String String>", | ||
| "1,setHeader<String String>", | ||
| "2,setIntHeader<String int>", | ||
| "3,addIntHeader<String int>" | ||
| }) | ||
| void givenRequest_whenDontSetContentLength_thenIsMissing(int method, String description) { | ||
| given() | ||
| .relaxedHTTPSValidation() | ||
| .when() | ||
| .get(String.format("https://localhost:%d/apicatalog/test/%d/%s", port, method, "otherHeaderName")) | ||
| .then() | ||
| .statusCode(SC_OK) | ||
| .header(CONTENT_LENGTH,"0") | ||
| .header("X-XSS-Protection", is(notNullValue())); | ||
| } | ||
|
|
||
| @RestController | ||
| @Profile("ResponseHeaderFixTest") | ||
| static class TestController { | ||
|
|
||
| @GetMapping(value = "/test/{method}/{headerName}") | ||
| public void getApiDoc(@PathVariable("method") int method, @PathVariable("headerName") String headerName, HttpServletResponse response) { | ||
| switch (method) { | ||
| case 0: | ||
| response.addHeader(headerName, String.valueOf(TEST_CONTENT_LENGTH)); | ||
| break; | ||
| case 1: | ||
| response.setHeader(headerName, String.valueOf(TEST_CONTENT_LENGTH)); | ||
| break; | ||
| case 2: | ||
| response.setIntHeader(headerName, TEST_CONTENT_LENGTH); | ||
| break; | ||
| case 3: | ||
| response.addIntHeader(headerName, TEST_CONTENT_LENGTH); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("Unknown method: " + method); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
caching-service/src/test/java/org/zowe/apiml/caching/acceptance/ResponseHeaderFixTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.caching.acceptance; | ||
|
|
||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.TestInstance; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.web.server.LocalServerPort; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.test.annotation.DirtiesContext; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.zowe.apiml.caching.CachingService; | ||
| import org.zowe.apiml.util.config.SslContext; | ||
| import org.zowe.apiml.util.config.SslContextConfigurer; | ||
|
|
||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import static io.restassured.RestAssured.given; | ||
| import static javax.servlet.http.HttpServletResponse.SC_OK; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.notNullValue; | ||
|
|
||
| @SpringBootTest( | ||
| classes = { | ||
| CachingService.class, | ||
| ResponseHeaderFixTest.TestController.class | ||
| }, | ||
| webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT | ||
| ) | ||
| @ActiveProfiles("ResponseHeaderFixTest") | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| @DirtiesContext | ||
| class ResponseHeaderFixTest { | ||
|
|
||
| private static final int TEST_CONTENT_LENGTH = 101; | ||
|
pavel-jares-bcm marked this conversation as resolved.
|
||
| private static final String CONTENT_LENGTH = "Content-Length"; | ||
|
|
||
| @LocalServerPort | ||
| protected int port; | ||
|
|
||
| @Value("${server.ssl.keyPassword}") | ||
| private char[] password; | ||
| @Value("${server.ssl.keyStore}") | ||
| private String clientCertKeystore; | ||
| @Value("${server.ssl.keyStore}") | ||
| private String keystore; | ||
|
|
||
| @BeforeAll | ||
|
pavel-jares-bcm marked this conversation as resolved.
|
||
| void setup() throws Exception { | ||
| SslContextConfigurer configurer = new SslContextConfigurer(password, clientCertKeystore, keystore); | ||
| SslContext.prepareSslAuthentication(configurer); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "Test handling setting context-type using {1}") | ||
| @CsvSource({ | ||
|
pavel-jares-bcm marked this conversation as resolved.
|
||
| "0,addHeader<String String>", | ||
| "1,setHeader<String String>", | ||
| "2,setIntHeader<String int>", | ||
| "3,addIntHeader<String int>" | ||
| }) | ||
| void givenRequest_whenSetContentLength_thenIsPropagated(int method, String description) { | ||
| given() | ||
| .config(SslContext.clientCertApiml) | ||
| .when() | ||
| .get(String.format("https://localhost:%d/test/%d/%s", port, method, CONTENT_LENGTH)) | ||
| .then() | ||
| .statusCode(SC_OK) | ||
| .header(CONTENT_LENGTH, String.valueOf(TEST_CONTENT_LENGTH)) | ||
| .header("X-Frame-Options", is(notNullValue())) | ||
| .header("X-XSS-Protection", is(notNullValue())); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "Test handling headers without content-type using {1}") | ||
| @CsvSource({ | ||
|
pavel-jares-bcm marked this conversation as resolved.
|
||
| "0,addHeader<String String>", | ||
| "1,setHeader<String String>", | ||
| "2,setIntHeader<String int>", | ||
| "3,addIntHeader<String int>" | ||
| }) | ||
| void givenRequest_whenDontSetContentLength_thenIsMissing(int method, String description) { | ||
| given() | ||
| .config(SslContext.clientCertApiml) | ||
| .when() | ||
| .get(String.format("https://localhost:%d/test/%d/%s", port, method, "otherHeaderName")) | ||
| .then() | ||
| .statusCode(SC_OK) | ||
| .header(CONTENT_LENGTH,"0") | ||
| .header("X-Frame-Options", is(notNullValue())) | ||
| .header("X-XSS-Protection", is(notNullValue())); | ||
| } | ||
|
|
||
| @RestController | ||
| @Profile("ResponseHeaderFixTest") | ||
| static class TestController { | ||
|
|
||
| @GetMapping(value = "/test/{method}/{headerName}") | ||
| public void getApiDoc(@PathVariable("method") int method, @PathVariable("headerName") String headerName, HttpServletResponse response) { | ||
| switch (method) { | ||
|
pavel-jares-bcm marked this conversation as resolved.
|
||
| case 0: | ||
| response.addHeader(headerName, String.valueOf(TEST_CONTENT_LENGTH)); | ||
| break; | ||
| case 1: | ||
| response.setHeader(headerName, String.valueOf(TEST_CONTENT_LENGTH)); | ||
| break; | ||
| case 2: | ||
| response.setIntHeader(headerName, TEST_CONTENT_LENGTH); | ||
| break; | ||
| case 3: | ||
| response.addIntHeader(headerName, TEST_CONTENT_LENGTH); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("Unknown method: " + method); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.