Skip to content

feat: Add IPv4 and IPv6 address validation utilities with comprehensive test coverage - #7066

Closed
tboy1337 wants to merge 3 commits into
psf:mainfrom
tboy1337:edit-15
Closed

feat: Add IPv4 and IPv6 address validation utilities with comprehensive test coverage#7066
tboy1337 wants to merge 3 commits into
psf:mainfrom
tboy1337:edit-15

Conversation

@tboy1337

@tboy1337 tboy1337 commented Oct 24, 2025

Copy link
Copy Markdown

Summary

This PR possibly solves #5953 by introducing robust IPv4 and IPv6 address validation utilities to the requests library, enhancing the existing address_in_network function to support both IPv4 and IPv6 CIDR notation checks.

Changes

New Functionality

  • IPv4 & IPv6 Validation: Added new utility functions for validating and comparing IPv4 and IPv6 addresses
  • Enhanced Network Checks: Updated address_in_network function to support both IPv4 and IPv6 addresses with CIDR notation
  • Type Safety: Implemented proper type checking and validation for address formats

Testing

  • Comprehensive Test Suite: Added 191 new lines of test coverage for the new functionalities
  • Edge Case Coverage: Includes tests for:
    • Valid and invalid IPv4/IPv6 addresses
    • CIDR notation parsing and validation
    • Network range boundary conditions
    • Malformed input handling

Files Changed

  • src/requests/utils.py: +113 insertions
  • tests/test_utils.py: +191 insertions

Total: 2 files changed, 263 insertions(+), 41 deletions(-)

Testing

All new functionality has been thoroughly tested with comprehensive unit tests covering both happy paths and edge cases. The test suite ensures robust handling of various IP address formats and network configurations.

Motivation

This enhancement improves the library's ability to handle modern networking scenarios where both IPv4 and IPv6 addresses are commonly used, providing developers with reliable tools for address validation and network comparisons.

- Introduced new functions for validating and comparing IPv4 and IPv6 addresses.
- Enhanced `address_in_network` to support both IPv4 and IPv6 checks.
- Added tests for new functionalities, including edge cases for CIDR notation and invalid inputs.
- Updated `requirements-dev.txt` to include additional testing dependencies: pytest-mock, pytest-timeout, and pytest-xdist.
@nateprewitt

Copy link
Copy Markdown
Member

There is already an open PR for this in #5953.

@nateprewitt nateprewitt closed this Nov 3, 2025
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