Skip to content

Add comprehensive test coverage and example configuration for X-Forwarded-For#13

Merged
maclarel merged 3 commits intomainfrom
copilot/update-test-code-use-xff
Feb 5, 2026
Merged

Add comprehensive test coverage and example configuration for X-Forwarded-For#13
maclarel merged 3 commits intomainfrom
copilot/update-test-code-use-xff

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 5, 2026

Existing XFF tests covered basic functionality but lacked edge case validation and practical configuration examples.

Test Coverage

Added 10 tests across two new test classes:

TestXFFEdgeCases - Validates handling of:

  • Malformed headers (empty, whitespace-only, invalid IPs)
  • IPv6 addresses in X-Forwarded-For and xff_upstream_ip CIDR
  • Whitespace handling in comma-separated IP lists
  • Integration with other rule conditions (headers, user_agent)
  • Rules without source_ip restrictions

TestXFFDocumentationScenarios - Validates:

  • Load balancer scenario from README Example 7
  • Multi-network access patterns

Example Configuration

Added rules/xff_example.yaml demonstrating:

  • Source IP restrictions behind a proxy/load balancer
  • Multiple CIDR ranges with XFF enabled
  • Configuration comments and security warnings
rule:
  path: files/protected_xff_example.txt
  request_uri: /protected-xff
  source_ip:
    - 203.0.113.0/24   # External client network
    - 198.51.100.0/24
    - 192.0.2.50/32

Total test count: 47 → 57 tests, all passing.

Original prompt

Please update the test code to cover use_xff and xff_upstream_ip functionality, including the addition of a new example rules file to demonstrate how it can be configured.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 5, 2026 20:51
…m_ip

- Add 10 new test cases covering edge cases and documentation scenarios
- Add TestXFFEdgeCases class with tests for:
  * Whitespace and empty X-Forwarded-For headers
  * Invalid IP formats in X-Forwarded-For
  * IPv6 support in X-Forwarded-For
  * Whitespace handling in header values
  * Integration with other rule conditions
  * IPv6 CIDR support for xff_upstream_ip
  * Behavior without source_ip restrictions
- Add TestXFFDocumentationScenarios class with tests validating:
  * Example 7 from README (load balancer scenario)
  * Multi-network access with X-Forwarded-For
- Create xff_example.yaml rules file demonstrating proper xff configuration
- Create protected_xff_example.txt file for the example rule
- All 57 tests pass successfully

Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
Removed duplicate assignment that was flagged in code review for improved code clarity.

Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
Copilot AI changed the title [WIP] Update test coverage for use_xff and xff_upstream_ip Add comprehensive test coverage and example configuration for X-Forwarded-For Feb 5, 2026
Copilot AI requested a review from maclarel February 5, 2026 20:53
@maclarel maclarel marked this pull request as ready for review February 5, 2026 21:00
@maclarel maclarel merged commit 706af48 into main Feb 5, 2026
3 checks passed
@maclarel maclarel deleted the copilot/update-test-code-use-xff branch February 5, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants