drf-api-tracking icon indicating copy to clipboard operation
drf-api-tracking copied to clipboard

Fix edge cases with unknown IP address

Open yuekui opened this issue 1 year ago • 1 comments
trafficstars

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_FOR header contains 'unknown' by parsing and using the closest valid IP address.
  • Tests:
    • Added test to verify correct IP address is logged when HTTP_X_FORWARDED_FOR contains 'unknown'.

yuekui avatar Jul 25 '24 01:07 yuekui

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.py
tests/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 review on 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.

sourcery-ai[bot] avatar Jul 25 '24 01:07 sourcery-ai[bot]