edx_django_utils.ip.internal.tests package#

Submodules#

edx_django_utils.ip.internal.tests.test_ip module#

Tests for IP determination.

Fake data used in these tests, for consistency:

  • 1.2.3.4 – a “real” client IP, e.g. the IP of a laptop or phone.

  • 127.0.0.2 – a local reverse proxy (e.g. nginx or caddy)

  • 10.0.3.0 – our load balancer

  • 5.5.5.5 – our CDN

  • 6.6.6.6 – a malicious CDN configuration

  • 7.8.9.0 – something beyond the real client in the IP chain, probably a spoofed header

…as well as IPv6 versions of these, e.g. 1:2:3:4:: and ::1.

XXXXXXXXX is used as a standin for anything unparseable (some kind of garbage).

class edx_django_utils.ip.internal.tests.test_ip.TestClientIP(methodName='runTest')#

Bases: django.test.testcases.TestCase

Tests for get_client_ip and helpers.

setUp()#

Hook method for setting up the test fixture before exercising it.

test_compute_client_ips_1(cnf_headers, add_meta, expected, expect_warnings)#

Just a few tests to confirm that the correct branch is taken, basically.

test_compute_client_ips_2(cnf_headers, add_meta, expected, expect_warnings)#

Just a few tests to confirm that the correct branch is taken, basically.

test_compute_client_ips_3(cnf_headers, add_meta, expected, expect_warnings)#

Just a few tests to confirm that the correct branch is taken, basically.

test_get_all_client_ips()#

Test getter for all IPs.

test_get_client_ips_via_trusted_header_1(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_2(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_3(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_4(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_5(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_6(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_7(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_8(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_trusted_header_9(cnf_headers, add_meta, expected, warning_count)#
test_get_client_ips_via_xff_01___7_8_9_0____1_2_3_4__10_0_3_0______1_____7_8_9______1_2_3_4___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_02___7_8_9_0____1_2_3_4_____7_8_9_0____1_2_3_4___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_03__None___1_2_3_4_____1_2_3_4___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_04__None___127_0_0_2_____127_0_0_2___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_05___XXXXXXXXX__1_2_3_4______10_0_0_1_____1_2_3_4_____(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_06___7_8_9_0__XXXXXXXXX__10_0_3_0____127_0_0_2_____10_0_3_0___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_07__None_____1_______1___(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_08__None_________(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_09__None___XXXXXXXXX______(xff, remote_addr, expected_strs)#
test_get_client_ips_via_xff_10___1_2_3_4____XXXXXXXXX______(xff, remote_addr, expected_strs)#
test_get_meta_ip_strs_1(add_meta, header_name, expected)#
test_get_meta_ip_strs_2(add_meta, header_name, expected)#
test_get_meta_ip_strs_3(add_meta, header_name, expected)#
test_get_meta_ip_strs_4(add_meta, header_name, expected)#
test_get_safest_client_ip()#

Test convenience wrapper for rightmost IP.

test_get_trusted_header_ip_1(header_name, index, add_meta, expected, warning_substr)#
test_get_trusted_header_ip_2(header_name, index, add_meta, expected, warning_substr)#
test_get_trusted_header_ip_3(header_name, index, add_meta, expected, warning_substr)#
test_get_trusted_header_ip_4(header_name, index, add_meta, expected, warning_substr)#
test_get_trusted_header_ip_5(header_name, index, add_meta, expected, warning_substr)#
test_get_trusted_header_ip_6(header_name, index, add_meta, expected, warning_substr)#
test_get_usable_ip_chain_1(request_meta, expected_strs)#
test_get_usable_ip_chain_2(request_meta, expected_strs)#
test_get_usable_ip_chain_3(request_meta, expected_strs)#
test_init_client_ips()#

Test idempotence of init_client_ips.

test_remove_tail_1(elements, f_discard, expected)#
test_remove_tail_2(elements, f_discard, expected)#
test_remove_tail_3(elements, f_discard, expected)#
test_remove_tail_4(elements, f_discard, expected)#
test_remove_tail_5(elements, f_discard, expected)#
edx_django_utils.ip.internal.tests.test_ip.warning_messages()#

Context manager which produces a list of warning messages as the context value (only populated after block ends).

Module contents#