[ 
https://issues.apache.org/jira/browse/KNOX-3451?focusedWorklogId=1040788&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1040788
 ]

ASF GitHub Bot logged work on KNOX-3451:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Sep/26 17:55
            Start Date: 10/Sep/26 17:55
    Worklog Time Spent: 10m 
      Work Description: shreyaaryaofficial opened a new pull request, #1390:
URL: https://github.com/apache/knox/pull/1390

   ## What changes were proposed in this pull request?
   
   This pull request adds dedicated unit tests for 
`XForwardedHeaderRequestWrapper` in the `gateway-server-xforwarded-filter` 
module.
   
   The tests provide focused coverage for the request wrapper's 
forwarded-header handling, including:
   
   * `X-Forwarded-For` header generation and handling of existing values.
   * `X-Forwarded-Proto` handling for HTTP and HTTPS requests.
   * Default forwarded ports (`80` for HTTP and `443` for HTTPS).
   * Preservation of existing `X-Forwarded-Port` values.
   * `X-Forwarded-Host` handling.
   * Case-insensitive forwarded-header lookup.
   * `X-Forwarded-Context` generation.
   * Service-context handling.
   * Service-name/context handling.
   * `getHeaders()` behavior for forwarded headers.
   * Forwarded host values containing port information.
   
   The change is limited to unit-test coverage and does not modify the 
production implementation.
   
   ## How was this patch tested?
   
   The new tests are implemented using the existing JUnit and EasyMock testing 
conventions used by the Apache Knox project.
   
   The following Maven command is used to run the new unit test and its 
required modules:
   
   ```bash
   mvn -pl gateway-server-xforwarded-filter -am \
   -Dtest=XForwardedHeaderRequestWrapperTest \
   -Dsurefire.failIfNoSpecifiedTests=false \
   test
   ```
   
   The test verifies the expected forwarded-header values for different request 
configurations, including HTTP/HTTPS requests, existing forwarded headers, 
context paths, service contexts, and case-insensitive header access.
   
   The Maven build also performs the project's existing validation steps, 
including Checkstyle.
   
   ## Integration Tests
   
   No integration tests were added or modified.
   
   This change only adds unit-test coverage for existing 
`XForwardedHeaderRequestWrapper` behavior and does not introduce or modify any 
user-facing functionality or integration behavior. Therefore, changes to 
`.github/workflows/tests` are not required.
   
   ## UI changes
   
   No UI changes are included in this pull request.




Issue Time Tracking
-------------------

            Worklog Id:     (was: 1040788)
    Remaining Estimate: 0h
            Time Spent: 10m

> Add unit tests for XForwardedHeaderRequestWrapper
> -------------------------------------------------
>
>                 Key: KNOX-3451
>                 URL: https://issues.apache.org/jira/browse/KNOX-3451
>             Project: Apache Knox
>          Issue Type: Improvement
>            Reporter: Raghav Maheshwari
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Add dedicated unit tests for `XForwardedHeaderRequestWrapper` to improve 
> unit-test coverage of the forwarded-header handling logic in Apache Knox.
> The `XForwardedHeaderRequestWrapper` class contains logic for generating and 
> handling forwarded request headers such as `X-Forwarded-For`, 
> `X-Forwarded-Proto`, `X-Forwarded-Port`, `X-Forwarded-Host`, 
> `X-Forwarded-Server`, and `X-Forwarded-Context`.
> Currently, the existing test coverage primarily exercises forwarded-header 
> behavior through the filter. Adding a dedicated unit test class for the 
> request wrapper will provide more focused coverage of the wrapper's 
> individual behaviors and edge cases.
> Proposed Change
> Add:
> `gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/XForwardedHeaderRequestWrapperTest.java`
> The test class should cover the following scenarios:
> * Verify default `X-Forwarded-For` behavior when the header is not already 
> present.
> * Verify that an existing `X-Forwarded-For` value is preserved and the remote 
> address is appended appropriately.
> * Verify `X-Forwarded-Proto` generation for HTTP requests.
> * Verify `X-Forwarded-Proto` generation for HTTPS requests.
> * Verify default ports (`80` for HTTP and `443` for HTTPS).
> * Verify that an existing `X-Forwarded-Port` value is preserved.
> * Verify `X-Forwarded-Host` handling.
> * Verify case-insensitive forwarded-header lookup.
> * Verify `X-Forwarded-Context` generation from the request context path.
> * Verify service-context handling.
> * Verify service-name/context handling when enabled.
> * Verify `getHeaders()` returns the expected forwarded-header values.
> * Add regression coverage for host values containing port information.
> * Add edge-case coverage for IPv6-style host values if applicable to the 
> current implementation.
> Testing Approach
> Use the existing JUnit 4 and EasyMock testing conventions used by the 
> `gateway-server-xforwarded-filter` module.
> The tests should mock `HttpServletRequest` and verify the values exposed by 
> `XForwardedHeaderRequestWrapper`.
> No production-code changes are expected as part of this issue.
> Expected Outcome
> The change will provide direct unit-test coverage for 
> `XForwardedHeaderRequestWrapper`, making the forwarded-header behavior easier 
> to validate and reducing the risk of regressions when the request-wrapper 
> implementation is modified in the future.
> Acceptance Criteria
> * A dedicated `XForwardedHeaderRequestWrapperTest` test class is added.
> * Existing forwarded-header behavior is covered by focused unit tests.
> * HTTP and HTTPS scenarios are covered.
> * Existing and generated forwarded-header values are tested.
> * Context/service-name behavior is covered.
> * Header lookup behavior is tested.
> * Relevant edge cases are covered.
> * All existing tests continue to pass.
> * The new tests follow the existing Apache Knox test conventions.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to