drf-api-tracking
drf-api-tracking copied to clipboard
Fix edge cases with unknown IP address
For some reason, HTTP_X_FORWARDED_FOR might be set as "unknown, 128.1.1.9", we should be able to parse and use the closest valid value.
Summary by Sourcery
This pull request addresses an edge case in IP address parsing where the HTTP_X_FORWARDED_FOR header might contain 'unknown'. The code now correctly parses and uses the closest valid IP address. Additionally, a test has been added to ensure this functionality works as expected.
- Bug Fixes:
- Fixed edge case where
HTTP_X_FORWARDED_FORheader contains 'unknown' by parsing and using the closest valid IP address.
- Fixed edge case where
- Tests:
- Added test to verify correct IP address is logged when
HTTP_X_FORWARDED_FORcontains 'unknown'.
- Added test to verify correct IP address is logged when
Reviewer's Guide by Sourcery
This pull request addresses the issue where HTTP_X_FORWARDED_FOR might contain 'unknown' followed by a valid IP address. The _get_ip_address method in rest_framework_tracking/base_mixins.py was updated to parse and use the closest valid IP address. Additionally, a new test case was added to tests/test_mixins.py to ensure the new logic works as expected.
File-Level Changes
| Files | Changes |
|---|---|
rest_framework_tracking/base_mixins.pytests/test_mixins.py |
Enhanced IP address extraction logic to handle edge cases with 'unknown' values and added corresponding test cases. |
Tips
- Trigger a new Sourcery review by commenting
@sourcery-ai reviewon the pull request. - Continue your discussion with Sourcery by replying directly to review comments.
- You can change your review settings at any time by accessing your dashboard:
- Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
- Change the review language;
- You can always contact us if you have any questions or feedback.