tests: every proxy of the tests that could forward outside the lab carries only the lab's destinations
The base Gateway of _socks_servers (CONNECT relay and UDP relay, tcp_from_exit included), Socks5TcpOnly and the SOCKS5 server of test_proxy_socks_auth_e2e refuse and record any destination that is not the lab's (loopback, the documentation ranges, the addresses of this host's interfaces, localhost): a CONNECT is answered with reply 2, a datagram is dropped, and the refusal is written down (time since the gateway started, address type, destination as received, port, protocol) under $RUNNER_TEMP/invpw-evidence/<gateway>/, always, when the gateway is closed. forward_only_to only narrows. The gateway of test_ipv6_literal_connect_e2e reuses the base behaviour and keeps its evidence. New unit test with known-bad inputs; the two unit rows of the registry name it.
This commit is contained in:
1 parent
f5d2ec81f9
commit
ac5a519244
6 files changed
+627
-78
No files matched your search
@@ -14,8 +14,8 @@
|
||||
{"id": "wrapper.e2e.fakeweb", "giro": "G2", "os": ["linux", "windows"], "min_tests": 4, "exact": true, "tests": ["tests/test_fakeweb_p2_e2e.py", "tests/test_fakeweb_p4_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The fake web, offline: our browser on the hard pages (profile P2: a reused routed page reaches networkidle every time, also under a load of three other browsers; the other site is another process) and on the 17-step journey of a person (profile P4), each judged against what stock Firefox does, as tests/fakeweb/pages.json declares it. 4 = 3 + 1. Stock itself is held to that declaration, and compared with ours step by step, by scripts/run_fakeweb.py in .github/workflows/fakeweb.yml. Needs the candidate binary (STEALTHFOX_E2E_BINARY)."},
|
||||
{"id": "wrapper.e2e.fontconfig", "giro": "G2", "os": ["linux"], "min_tests": 2, "exact": true, "tests": ["tests/test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e.py"], "marker": "e2e", "needs_root": false, "linux_only": "Fontconfig exists only on Linux: the parent of the engine shows <GRE>/fonts to it (FcConfigAppFontAddDir) to rebuild a font from a path and a face index. On Windows DirectWrite opens the file from its path, with no folder to scan and no cache to read, so this test has no Windows counterpart.", "note": "2 = (1) the stand-in that runs the engine under strace stays in the engine's place, as the core launches it (the leader of a process group of its own): a fake engine with a child, no browser; the process the launcher holds lives as long as the fake engine, and the group killed holds strace and the child (the stand-in that exec'd setsid forked and exited 0 at once: candidate 44161687675); (2) the warm launch of the parent reads the bundle from fontconfig's cache and does not scan it again (from firefox-66, engine_at_least). Two launches under strace with the same XDG_CACHE_HOME of the test, the first cold and the second warm: the cold parent opens every font file of <GRE>/fonts (the folder as the disk lists it) before any page and fontconfig writes its cache; the warm parent does not open every one of them, and it opens a *.cache-* file of fontconfig (a few files are opened to be used, so the verdict asks about the whole folder, as a scan does). Scan and drawing are told apart by position: only what the parent opens before the first page counts (the opens that draw are written as after_startup). Evidence in RUNNER_TEMP/invpw-evidence/fontconfig-cache: the interval and the number of opens of the bundle, the names of the files of the bundle each launch opened before the first page, the size of the cache file, the VmRSS of the parent after about:blank and after a page with every family, and a third launch with gfx.bundled-fonts.activate=0 (the behaviour before), which is evidence only. Needs strace on the runner: without it both are red, not skipped. No threshold."},
|
||||
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 30, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference, and the box cut out of a screenshot (its pixels, a box outside the picture refused, written as a PNG and read back, two boxes told apart by a pixel that is named, the pixels that are not grey)."},
|
||||
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2203, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.pLine truncated
|
||||
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2204, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_compositioLine truncated
|
||||
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2252, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.pLine truncated
|
||||
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2253, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_compositioLine truncated
|
||||
{"id": "wrapper.e2e.securitystate", "giro": "G2", "os": ["linux", "windows"], "min_tests": 4, "exact": true, "tests": ["tests/test_security_state_engine_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The security state the core declares, against the engine: the engine launched directly in its generate mode makes what it is given (the contract's result, security_state/ with the bytes of the full filter and of the delta, the core's own validation of it); a normal launch declares no pref of the mode and re-imports nothing; a certificate that Mozilla's CRLite test data say is revoked in a delta is refused at the first navigation (SEC_ERROR_REVOKED_CERTIFICATE) while a valid one loads, and the revoked one loads when the ready directory has no data; a ready directory with no or an empty security_state/ starts. Certificates made on the run (a fresh root trusted in cert9.db by the engine's own xpcshell, Mozilla's default test key as the key of CN=int), servers on loopback, no network. Red on firefox-67 (no generate mode)."},
|
||||
{"id": "wrapper.e2e.suite.linux.1", "giro": "G2", "os": ["linux"], "min_tests": 376, "exact": true, "tests": ["tests/test_a_closed_browser_leaves_the_others_alone_e2e.py", "tests/test_a_context_that_ends_leaves_no_process_e2e.py", "tests/test_a_cors_preflight_is_not_a_request_of_the_page_e2e.py", "tests/test_a_declared_webgl_extension_survives_its_use_e2e.py", "tests/test_a_granted_permission_is_the_one_the_page_asks_for_e2e.py", "tests/test_a_launch_without_a_session_gets_one_e2e.py", "tests/test_a_left_documents_body_is_evicted_e2e.py", "tests/test_a_mouse_click_makes_one_mousemove_on_its_point_e2e.py", "tests/test_a_page_over_ipv6_gathers_on_a_machine_declared_without_it_e2e.py", "tests/test_a_popup_is_reported_when_the_engine_says_it_is_ready_as_playwright_does_e2e.py", "tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py", "tests/test_a_served_browser_answers_a_plain_client_e2e.py", "tests/test_a_tiny_download_on_a_served_browser_is_saved_e2e.py", "tests/test_a_turn_name_over_tcp_goes_through_the_proxy_of_the_context_e2e.py", "tests/test_accept_language_on_the_wire_e2e.py", "tests/test_browser_output_is_drained.py", "tests/test_click_rhythm.py", "tests/test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py", "tests/test_control_a_selects_all_in_a_field_e2e.py", "tests/test_cross_origin_iframe.py", "tests/test_declared_host_network_e2e.py", "tests/test_detectors_e2e.py", "tests/test_e2e.py", "tests/test_element_handle_actions.py", "tests/test_element_screenshot_e2e.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_file_chooser.py", "tests/test_fingerprint_surface.py", "tests/test_fission_frames_history_and_processes_e2e.py", "tests/test_fission_frames_workers_storage_and_special_frames_e2e.py", "tests/test_frames_outlive_the_back_forward_cache_e2e.py", "tests/test_goto_networkidle_after_spa_e2e.py", "tests/test_goto_script_redirect_e2e.py", "tests/test_hidden_display_linux.py", "tests/test_ice_names_by_the_context_proxy_e2e.py::test_the_ice_name_of_a_context_goes_by_the_proxy_of_that_context", "tests/test_ignore_https_errors_e2e.py", "tests/test_injected_node_surface.py", "tests/test_juggler_connection.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_navigation_across_processes_e2e.py", "tests/test_navigation_response.py", "tests/test_networkidle_reaches_the_client_e2e.py", "tests/test_oop_frame_element.py", "tests/test_oop_frame_geometry.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pointer_position.py", "tests/test_popups_reach_the_client_e2e.py", "tests/test_preload_newtab_turns_the_privileged_about_process_off_e2e.py", "tests/test_realness_behind_a_declared_exit_e2e.py", "tests/test_resolver_race_e2e.py", "tests/test_route_header_order_e2e.py", "tests/test_same_document_goto_e2e.py", "tests/test_screencast.py", "tests/test_screencast_stop_e2e.py", "tests/test_screenshot_looks_where_you_are.py", "tests/test_security_state_engine_e2e.py", "tests/test_service_worker.py", "tests/test_service_worker_controller_e2e.py", "tests/test_set_offline_e2e.py", "tests/test_shadow_trusted_input.py", "tests/test_strict_and_force.py", "tests/test_the_callers_code_is_not_counted_e2e.py", "tests/test_the_device_enumeration_takes_the_declared_time_e2e.py", "tests/test_the_engine_is_born_in_the_job_e2e.py::test_a_launch_scans_no_process_of_the_machine", "tests/test_the_engine_is_born_in_the_job_e2e.py::test_after_close_no_process_of_the_session_is_left", "tests/test_the_hosts_file_of_the_host_is_never_read_e2e.py", "tests/test_trial_does_not_act.py", "tests/test_turn_over_tcp_is_tried_for_real_e2e.py", "tests/test_ua_widget_not_selectable.py", "tests/test_voices_e2e.py", "tests/test_wait_for_function.py", "tests/test_webgl_draws_on_the_engine_s_own_gl_e2e.py", "tests/test_webgl_noise_active.py", "tests/test_webrtc_realness.py::test_a_gateway_that_is_far_away_still_gives_the_page_a_srflx_born_through_its_relay", "tests/test_webrtc_realness.py::test_a_gather_after_the_page_loaded_through_the_gateway_costs_only_the_road_to_the_server", "tests/test_webrtc_realness.py::test_a_host_with_ipv6_addresses_gathers_through_an_ipv4_relay", "tests/test_webrtc_realness.py::test_a_proxy_that_does_not_relay_udp_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_a_proxy_whose_relay_never_answers_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_a_proxy_whose_udp_leaves_from_another_address_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_not_blocked_behind_tcp_only_socks", "tests/test_webrtc_realness.py::test_the_first_candidate_of_a_gather_does_not_wait_for_a_gateway_that_is_far_away", "tests/test_webrtc_realness.py::test_the_turn_over_tcp_of_a_context_goes_through_the_proxy_of_that_context", "tests/test_webrtc_realness.py::test_two_contexts_with_two_proxies_each_gets_the_srflx_of_its_own"], "marker": "e2e", "needs_root": false, "windows_twin"Line truncated
|
||||
{"id": "wrapper.e2e.suite.linux.2", "giro": "G2", "os": ["linux"], "min_tests": 411, "exact": true, "tests": ["tests/test_a_click_waits_for_the_navigation_it_plans_e2e.py", "tests/test_a_context_init_script_runs_once_e2e.py", "tests/test_a_drag_keeps_its_buttons_pressed_e2e.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_goto_to_a_response_with_no_document_ends_e2e.py", "tests/test_a_keepalive_request_reaches_the_client_e2e.py", "tests/test_a_latin_letter_on_a_cyrillic_persona_e2e.py", "tests/test_a_page_cannot_probe_the_juggler_e2e.py", "tests/test_a_page_that_moves_on_e2e.py", "tests/test_a_pointer_event_is_handled_before_the_call_returns_e2e.py", "tests/test_a_request_says_what_it_is_e2e.py", "tests/test_a_worker_comes_back_with_its_page_from_the_cache_e2e.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_isolated_page_and_the_next_e2e.py", "tests/test_bypass_csp_e2e.py", "tests/test_caller_world_handles_e2e.py", "tests/test_canvas_reads_as_drawn.py", "tests/test_canvas_render_stealth.py", "tests/test_context_locale_e2e.py", "tests/test_context_proxy_only_resolves_by_doh_e2e.py", "tests/test_doh_through_the_proxy_e2e.py", "tests/test_doh_under_stress_e2e.py", "tests/test_download_is_intercepted_e2e.py", "tests/test_drag_motion.py", "tests/test_expose_binding_e2e.py", "tests/test_fakeweb_p4_e2e.py", "tests/test_fingerprint_consistency.py", "tests/test_fission_frames_dialogs_downloads_popups_e2e.py", "tests/test_fission_frames_route_and_bindings_e2e.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fission_iframe_crash_e2e.py", "tests/test_fission_strategy1_bench.py", "tests/test_goto_to_the_same_url_e2e.py", "tests/test_http3_through_the_proxy_e2e.py", "tests/test_input_is_born_before_the_page_sees_it_e2e.py", "tests/test_juggler_actions.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py::test_a_javascript_that_THROWS_arrives_as_an_error_not_as_None", "tests/test_juggler_injected.py::test_actionability_DISTINGUISHES_instead_of_always_saying_yes", "tests/test_juggler_injected.py::test_reads_that_make_no_sense_are_REJECTED", "tests/test_juggler_injected.py::test_states_DISCRIMINATE_instead_of_always_saying_true", "tests/test_juggler_injected.py::test_the_DOM_READING_group", "tests/test_juggler_injected.py::test_the_selector_engines_respond", "tests/test_juggler_injected.py::test_the_text_reads", "tests/test_juggler_lifecycle_e2e.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_long_session_e2e.py", "tests/test_mouse.py", "tests/test_mouse_events_keep_their_values_e2e.py", "tests/test_new_page_defaults.py", "tests/test_popup_destinations_e2e.py", "tests/test_popup_pages.py", "tests/test_proxy_http_auth_e2e.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_proxy_socks_auth_e2e.py", "tests/test_requestless_navigation.py", "tests/test_route_abort_code.py", "tests/test_route_e2e.py", "tests/test_route_post_data_e2e.py", "tests/test_route_sends_a_navigation_elsewhere_e2e.py", "tests/test_route_superseded_e2e.py", "tests/test_same_document_navigation.py", "tests/test_screenshot_of_text_returns_linux_e2e.py", "tests/test_scroll_into_view.py", "tests/test_scroll_only_if_needed_e2e.py", "tests/test_service_workers_blocked.py", "tests/test_set_input_files_payloads.py", "tests/test_software_compositing_is_declared_e2e.py", "tests/test_the_association_is_ready_when_the_peerconnection_is_born_e2e.py", "tests/test_the_callers_code_runs_once_e2e.py", "tests/test_the_close_returns_when_the_browser_has_exited_e2e.py", "tests/test_the_favicon_stays_out_of_sight_e2e.py", "tests/test_the_font_list_is_the_bundle_e2e.py", "tests/test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e.py", "tests/test_the_scheme_is_the_personas_e2e.py", "tests/test_the_whole_udp_chain_by_name_e2e.py::test_a_turn_srflx_by_name_arrives_through_the_relay_when_the_exit_of_the_lab_is_loopback", "tests/test_typing_a_character_without_a_key_e2e.py", "tests/test_wait_for_timeout.py", "tests/test_web_fonts_of_closed_contexts_e2e.py"], "marker": "e2e", "needs_root": false, "windows_twin": "wrapper.e2e.suite.windows.2", "note": "Part 2 of the whole e2e suite of the wrapper (every test that opens the browser: what e2e.yml runs on the published engine), on the engine under test, as two passes through scripts/ci_suite_run.py (4 browsers at once, then the wall_clock tests alone; no rerun). The files of the 2 rows of linux are the files of tests/ that tests/test_the_e2e_suite_is_accounted_for.py holds one by one: a file whole when every test of it is here, else its tests by name. Partition from the junits of runs 44942540063 and 44985244053, test time balanced (about 564 s of estimated wall time, 4 browsers). A new file is added by hand to a row of each system and the minimum of the row goes up by hand. Left out of every row, with the reason in the accounting test: the files and tests of wrapLine truncated
|
||||
|
||||
@@ -602,7 +602,8 @@ class DohGateway(Gateway):
|
||||
* CONNECT to a loopback address is relayed for real (the pages and the echo servers of a test);
|
||||
* the egress endpoints of the base class (``api.ipify.org:80``) keep working;
|
||||
* any other CONNECT is refused (reply 2 "not allowed", for an address; 4 "host unreachable", for a name) and
|
||||
listed in :attr:`refused`: the gateway never resolves a name and never reaches past the loopback.
|
||||
listed in :attr:`refused` (and in ``guard``, the record every gateway of ``_socks_servers`` writes under ``$RUNNER_TEMP/invpw-evidence/``):
|
||||
the gateway never resolves a name and never reaches past the loopback. Its UDP relay is the base one: only the lab's, the rest dropped and recorded.
|
||||
|
||||
:attr:`connects` (inherited) lists EVERY CONNECT target in order, so ``("page-a.test", 80)`` in it means the
|
||||
browser sent a name where it should have sent an address. :attr:`credentials_seen` lists every
|
||||
@@ -696,6 +697,7 @@ class DohGateway(Gateway):
|
||||
if not is_loopback(host):
|
||||
self.connects.append((host, port))
|
||||
self.refused.append((host, port))
|
||||
self.guard.refuse(host, port, getattr(self._local, "atyp", 3), "tcp")
|
||||
self._send(c, self._reply(2 if _is_address(host) else 4))
|
||||
return
|
||||
self.connects.append((host, port))
|
||||
|
||||
+155
-26
@@ -33,11 +33,20 @@ answer as the service; the plain-HTTP endpoint ``api.ipify.org:80`` is still
|
||||
answered here for the tests that ask it), and the UDP exit is what the fake STUN server puts in its XOR-MAPPED-ADDRESS.
|
||||
Both are chosen by the test (``tcp_exit`` and ``udp_exit`` arguments).
|
||||
|
||||
Any other CONNECT is really forwarded, and any other UDP datagram is really
|
||||
forwarded to its destination and the reply wrapped back, so a page, or an echo
|
||||
server on 127.0.0.1, can be reached through the gateway and the test can
|
||||
observe which road its bytes took (:attr:`Gateway.connects`,
|
||||
:attr:`Gateway.datagrams`).
|
||||
HERMETIC: a gateway of this module carries a CONNECT or a datagram only to the LAB (:func:`is_lab_destination`: loopback, the
|
||||
documentation ranges of RFC 5737 and RFC 3849 the tests use as lab exits and servers, the addresses of this host's own interfaces, where a server
|
||||
of a test may stand, and the name ``localhost``). These tests run in the gate of the candidate, where no test may depend on a real service, and the
|
||||
browser behind a gateway makes background requests of its own (a name of the vendor, a captive-portal check, a telemetry endpoint): such a
|
||||
destination is REFUSED, never forwarded (a CONNECT is answered with reply 2, "not allowed"; a datagram is dropped), and RECORDED
|
||||
(:class:`LabGuard`: the time since the gateway started, the SOCKS5 address type, the destination as it was received - the NAME for type 3 -, the
|
||||
port and the protocol, ``tcp`` or ``udp``). The record is always written, when the gateway is closed, under
|
||||
``$RUNNER_TEMP/invpw-evidence/<gateway>/<pid>-<ms>/refused-destinations.json`` (the folder the e2e jobs upload; off a runner nothing is
|
||||
written), so that a reader sees what the browser asked for besides what the test drives. There is no option that reopens it. A subclass can only
|
||||
narrow it (:meth:`Gateway._admits`); the destinations it serves itself (the fake STUN server, the page of ``WEB_NAME``, the exit questions) are
|
||||
answered before it, and a name mapped to a local server by :meth:`Gateway._target` is judged by the server it maps to. What a test sees of the
|
||||
road is :attr:`Gateway.connects`, :attr:`Gateway.datagrams` (every datagram the relay read, carried or dropped) and
|
||||
:attr:`Gateway.guard`. :class:`Socks5TcpOnly` and the SOCKS5 server of ``test_proxy_socks_auth_e2e.py`` are hermetic the same way (same rule,
|
||||
same record).
|
||||
|
||||
This is the ONE SOCKS5 gateway of the test suite. A road that needs more than the three above (a TURN server, a resolver,
|
||||
a page, by NAME: ``tests/_turn_chain.py``) subclasses :class:`Gateway` and overrides the small hooks (:meth:`Gateway._route`,
|
||||
@@ -46,7 +55,10 @@ ASSOCIATE, the relay or the round trip.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import select
|
||||
import socket
|
||||
import struct
|
||||
@@ -55,7 +67,7 @@ import time
|
||||
from typing import Callable, Dict, List, Optional, Set, Tuple
|
||||
|
||||
#: The name the product's STUN probe sends through the relay. The relay maps it
|
||||
#: to the fake STUN server; every other destination is forwarded for real.
|
||||
#: to the fake STUN server; every other destination is the lab's to carry or is refused (``LabGuard``).
|
||||
STUN_NAME = "stun.l.google.com"
|
||||
STUN_PORT = 19302
|
||||
#: The same STUN server by NUMBER. A page cannot resolve a name behind the session (the engine forbids local
|
||||
@@ -79,19 +91,18 @@ _MAGIC = b"\x21\x12\xa4\x42"
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
# The exit of a proxy that forwards for real. The question "where do I leave from" is HTTPS (api.ipify.org:443), and no gateway
|
||||
# of the tests can answer a TLS request as the service: a proxy that FORWARDS (a CONNECT to anything outside loopback goes out for
|
||||
# real) would carry it to the internet, and the answer would be the address of whatever machine runs the test (a GitHub runner
|
||||
# that changes NAT in the middle of a session: ``ProxyEgressDrifted``). So such a proxy DECLARES its exit (``declare_exit``) and
|
||||
# ``tests/_lab_egress.DeclaredExit`` answers the question with it; and as a backstop each of them refuses to forward the question
|
||||
# (``asks_the_world``), which records it and makes the test fail (``nobody_asked_the_world``), so that a proxy that forgot to declare
|
||||
# is a red with its name and not a flaky green.
|
||||
# The exit of a proxy that relays CONNECTs. The question "where do I leave from" is HTTPS (api.ipify.org:443), and no gateway
|
||||
# of the tests can answer a TLS request as the service. A gateway of this module is hermetic (a CONNECT outside the lab is refused, see
|
||||
# ``LabGuard``), so the question could not reach the internet through it anyway; but the product would then be told no exit at all. So such a
|
||||
# proxy DECLARES its exit (``declare_exit``) and ``tests/_lab_egress.DeclaredExit`` answers the question with it; and as a backstop each of
|
||||
# them refuses the question itself (``asks_the_world``), which records it and makes the test fail (``nobody_asked_the_world``), so that a
|
||||
# proxy that forgot to declare is a red with its name and not a flaky green.
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
#: The hosts of the services of the core that tell a caller its address (``invisible_core._geo._IP_ECHO_ENDPOINTS`` and
|
||||
#: ``_IPV6_ECHO_ENDPOINTS``; ``tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py`` checks that this list covers them).
|
||||
EXIT_SERVICES = ("api.ipify.org", "api6.ipify.org", "icanhazip.com", "ipv6.icanhazip.com", "checkip.amazonaws.com", "ifconfig.me")
|
||||
|
||||
#: ``host:port`` of a proxy of the tests that forwards for real -> the exit it declares. Filled by the proxies themselves.
|
||||
#: ``host:port`` of a proxy of the tests that relays CONNECTs -> the exit it declares. Filled by the proxies themselves.
|
||||
_DECLARED_EXITS: Dict[str, str] = {}
|
||||
#: The questions of the exit that reached a forwarding proxy and were refused there: one sentence each, until a test reads them.
|
||||
_WORLD_QUESTIONS: List[str] = []
|
||||
@@ -103,7 +114,7 @@ def _endpoint(server: str) -> str:
|
||||
|
||||
|
||||
def declare_exit(server: str, exit_ip: str) -> None:
|
||||
"""The proxy at ``server`` forwards for real and says its exit is ``exit_ip``."""
|
||||
"""The proxy at ``server`` relays CONNECTs and says its exit is ``exit_ip``."""
|
||||
_DECLARED_EXITS[_endpoint(server)] = exit_ip
|
||||
|
||||
|
||||
@@ -117,10 +128,10 @@ def declared_exit_of(server: Optional[str]) -> Optional[str]:
|
||||
|
||||
|
||||
def asks_the_world(server: str, host: str, port: int) -> bool:
|
||||
"""True, and the question is recorded, when a CONNECT to ``host:port`` is the question of the exit: the proxy must refuse it, not forward it."""
|
||||
"""True, and the question is recorded, when a CONNECT to ``host:port`` is the question of the exit: the proxy must refuse it (the lab answers it with the declared exit)."""
|
||||
if host.lower() not in EXIT_SERVICES:
|
||||
return False
|
||||
_WORLD_QUESTIONS.append("%s was asked %s:%d: the question of the exit reached a proxy that would have forwarded it to the internet" % (
|
||||
_WORLD_QUESTIONS.append("%s was asked %s:%d: the question of the exit reached a proxy of the lab, which refuses it (its exit is declared, not asked of the internet)" % (
|
||||
server, host, port))
|
||||
return True
|
||||
|
||||
@@ -149,6 +160,91 @@ def _recv_exact(s: socket.socket, n: int) -> bytes:
|
||||
return data
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
# The lab. A gateway of the tests forwards nothing that is not the lab's: the destination is refused and recorded.
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
#: The networks that are the lab's whatever the host: loopback, and the documentation ranges (RFC 5737 TEST-NET-1/2/3, RFC 3849) that the tests use
|
||||
#: for their exits and their servers (nothing routes them: a test holds the ones a server stands at on ``lo``).
|
||||
LAB_NETWORKS = tuple(ipaddress.ip_network(net) for net in (
|
||||
"127.0.0.0/8", "::1/128", "192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24", "2001:db8::/32"))
|
||||
#: The folder under ``$RUNNER_TEMP`` the e2e workflows upload (``invpw-evidence-*``).
|
||||
EVIDENCE_FOLDER = "invpw-evidence"
|
||||
|
||||
|
||||
def _own_addresses() -> Set[str]:
|
||||
"""The addresses assigned to an interface of this host (a server of a test stands at one of them), or none when they cannot be listed."""
|
||||
try:
|
||||
from _witness import host_addresses
|
||||
|
||||
return host_addresses()
|
||||
except Exception:
|
||||
return set()
|
||||
|
||||
|
||||
def is_lab_destination(host: str) -> bool:
|
||||
"""Whether ``host`` (an address, or a name as a SOCKS5 client sent it) is the lab's: loopback, a documentation range, an address of one of this host's
|
||||
own interfaces, or ``localhost``. Any other NAME is not: nothing here resolves a name for the internet's sake, and the question would leave the machine."""
|
||||
text = host.strip().strip("[]").split("%", 1)[0].rstrip(".").lower()
|
||||
try:
|
||||
address = ipaddress.ip_address(text)
|
||||
except ValueError:
|
||||
return text == "localhost" or text.endswith(".localhost")
|
||||
mapped = getattr(address, "ipv4_mapped", None)
|
||||
if mapped is not None:
|
||||
address = mapped
|
||||
if any(address in network for network in LAB_NETWORKS):
|
||||
return True
|
||||
return address.compressed in _own_addresses()
|
||||
|
||||
|
||||
class LabGuard:
|
||||
"""What refuses a destination that is not the lab's and writes it down: one per gateway.
|
||||
|
||||
:meth:`admits` is asked with the destination as RECEIVED (``atyp`` is the SOCKS5 address type: 1 IPv4, 3 a name, 4 IPv6; ``protocol`` is ``"tcp"`` or
|
||||
``"udp"``); ``target`` is where it would really go, as (host, port), when that is not the destination itself (a name a gateway maps to a local server): the lab's
|
||||
decision is about the target. A refusal is recorded in :attr:`records` as a dict with ``t`` (seconds since ``t0``, the start of the gateway), ``atyp``,
|
||||
``destination`` (as received), ``port`` and ``protocol``. :meth:`write_evidence` leaves them, always, under ``$RUNNER_TEMP/invpw-evidence/<name>/``."""
|
||||
|
||||
def __init__(self, name: str, t0: Optional[float] = None):
|
||||
self.name = name
|
||||
self.t0 = time.monotonic() if t0 is None else t0
|
||||
#: Every refusal, in order.
|
||||
self.records: List[dict] = []
|
||||
self._lock = threading.Lock()
|
||||
self._written = False
|
||||
|
||||
def admits(self, host: str, port: int, atyp: int, protocol: str, target: Optional[Tuple[str, int]] = None) -> bool:
|
||||
if is_lab_destination(host if target is None else target[0]):
|
||||
return True
|
||||
self.refuse(host, port, atyp, protocol)
|
||||
return False
|
||||
|
||||
def refuse(self, host: str, port: int, atyp: int, protocol: str) -> None:
|
||||
"""Write down a destination that was refused (by this guard's rule, or by the narrower rule of a subclass)."""
|
||||
record = {"t": round(time.monotonic() - self.t0, 3), "atyp": atyp, "destination": host, "port": port, "protocol": protocol}
|
||||
with self._lock:
|
||||
self.records.append(record)
|
||||
|
||||
def refused(self, protocol: Optional[str] = None) -> List[Tuple[str, int]]:
|
||||
"""Every refused destination as (destination as received, port), in order; of one protocol when asked."""
|
||||
with self._lock:
|
||||
return [(r["destination"], r["port"]) for r in self.records if protocol is None or r["protocol"] == protocol]
|
||||
|
||||
def write_evidence(self, extra: Optional[dict] = None) -> Optional[pathlib.Path]:
|
||||
"""Write the record, once (a gateway may be closed twice): the file written, or None off a runner (no ``$RUNNER_TEMP``) or when already written."""
|
||||
runner_temp = os.environ.get("RUNNER_TEMP")
|
||||
with self._lock:
|
||||
if self._written or not runner_temp:
|
||||
return None
|
||||
self._written = True
|
||||
records = list(self.records)
|
||||
folder = pathlib.Path(runner_temp) / EVIDENCE_FOLDER / self.name / ("%d-%d" % (os.getpid(), int(time.time() * 1000)))
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
path = folder / "refused-destinations.json"
|
||||
path.write_text(json.dumps(dict({"gateway": self.name, "refused": records}, **(extra or {})), indent=2), encoding="utf-8")
|
||||
return path
|
||||
|
||||
|
||||
class FakeStun:
|
||||
"""A UDP STUN server that answers every binding request with ``mapped_ip``."""
|
||||
|
||||
@@ -215,10 +311,12 @@ class FakeStun:
|
||||
class Gateway:
|
||||
"""A SOCKS5 server. ``udp`` is ``"relay"`` or ``"refuse"`` (reply code 7)."""
|
||||
|
||||
#: Whether a CONNECT that is not special is forwarded for real, past loopback: such a gateway declares ``tcp_exit`` as its exit
|
||||
#: Whether this gateway relays the CONNECTs that are not special (to the lab: it is hermetic): such a gateway declares ``tcp_exit`` as its exit
|
||||
#: (``declare_exit``). A subclass that refuses everything but loopback (``tests/_doh_servers.DohGateway``) sets False: it cannot carry the
|
||||
#: question of the exit anywhere, and the question is left to what answers it.
|
||||
forwards_for_real = True
|
||||
#: The name of the folder of the record of what this gateway refused under ``$RUNNER_TEMP/invpw-evidence/`` (a subclass may name its own).
|
||||
evidence_name = "socks5-gateway"
|
||||
|
||||
def __init__(self, *, udp: str, tcp_exit: str, udp_exit: str,
|
||||
user: Optional[str] = None, password: Optional[str] = None,
|
||||
@@ -269,6 +367,9 @@ class Gateway:
|
||||
self.associates = 0
|
||||
#: When the gateway started: the origin of the times below.
|
||||
self.t0 = time.monotonic()
|
||||
#: What refuses (and records, and writes under ``$RUNNER_TEMP/invpw-evidence/<evidence_name>/`` when the gateway is closed) every destination that is
|
||||
#: not the lab's, CONNECT or datagram: ``guard.records``, ``guard.refused()``.
|
||||
self.guard = LabGuard(self.evidence_name, self.t0)
|
||||
#: The same instant on the wall clock (seconds since the epoch), to compare with what a page reads from Date.now().
|
||||
self.wall0 = time.time()
|
||||
#: Every TCP connection the gateway accepted (a SOCKS handshake starts with one), as seconds from t0.
|
||||
@@ -287,8 +388,8 @@ class Gateway:
|
||||
self.exit_ports: List[int] = []
|
||||
#: A datagram the relay could not send (a socket that raised): said here and in the report of a test, never mute.
|
||||
self.send_errors: List[str] = []
|
||||
#: The hosts the relay forwards a datagram to (the fake STUN server aside); None: any host. A test that sends from an
|
||||
#: address of this host keeps its lab closed: the browser's own background QUIC does not leave the machine.
|
||||
#: The hosts the relay forwards a datagram to (the fake STUN server aside), among the lab's; None: any host of the lab. It only narrows: a host
|
||||
#: that is not the lab's is never forwarded (``guard``).
|
||||
self.forward_only_to: Optional[Set[str]] = None
|
||||
self._listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self._listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
@@ -330,6 +431,11 @@ class Gateway:
|
||||
except OSError:
|
||||
pass
|
||||
self.stun.close()
|
||||
self.guard.write_evidence(self._evidence())
|
||||
|
||||
def _evidence(self) -> dict:
|
||||
"""What a subclass adds to the record of the refusals written at the close (a dict of JSON values)."""
|
||||
return {}
|
||||
|
||||
def __enter__(self) -> "Gateway":
|
||||
return self
|
||||
@@ -397,9 +503,10 @@ class Gateway:
|
||||
self._send(c, b"\x01\x00")
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _read_address(c: socket.socket) -> Tuple[str, int]:
|
||||
def _read_address(self, c: socket.socket) -> Tuple[str, int]:
|
||||
"""The destination of a request, as received (the NAME for address type 3); its address type is left in ``self._local.atyp``."""
|
||||
atyp = _recv_exact(c, 1)[0]
|
||||
self._local.atyp = atyp
|
||||
if atyp == 1:
|
||||
host = socket.inet_ntoa(_recv_exact(c, 4))
|
||||
elif atyp == 3:
|
||||
@@ -442,6 +549,12 @@ class Gateway:
|
||||
"""Where a CONNECT that is not a special one really goes. A subclass maps a name to a local server."""
|
||||
return host, port
|
||||
|
||||
def _admits(self, host: str, port: int, atyp: int, protocol: str, target: Optional[Tuple[str, int]] = None) -> bool:
|
||||
"""Whether the gateway carries a CONNECT (``protocol`` ``"tcp"``) or a datagram (``"udp"``) to ``host``:``port`` (as received; ``atyp`` is its SOCKS5
|
||||
address type), or to ``target`` (host, port) when it is mapped elsewhere: only the lab's, and the rest is refused and recorded (``guard``). A subclass may narrow
|
||||
it (never widen it: call this one first)."""
|
||||
return self.guard.admits(host, port, atyp, protocol, target)
|
||||
|
||||
def _open_upstream(self, target: Tuple[str, int]) -> socket.socket:
|
||||
"""The TCP connection of a CONNECT: from ``exit_host`` when ``tcp_from_exit``, else from wherever the system chooses."""
|
||||
if not self.tcp_from_exit:
|
||||
@@ -478,8 +591,12 @@ class Gateway:
|
||||
if self.forwards_for_real and asks_the_world(self.server, host, port):
|
||||
self._send(c, self._reply(2)) # not allowed: the exit of this gateway is declared, it is not asked of the internet
|
||||
return
|
||||
target = self._target(host, port)
|
||||
if not self._admits(host, port, getattr(self._local, "atyp", 3), "tcp", target):
|
||||
self._send(c, self._reply(2)) # not allowed: the gateway carries nothing outside the lab
|
||||
return
|
||||
try:
|
||||
up = self._open_upstream(self._target(host, port))
|
||||
up = self._open_upstream(target)
|
||||
except OSError:
|
||||
self._send(c, self._reply(5))
|
||||
return
|
||||
@@ -536,13 +653,15 @@ class Gateway:
|
||||
``target`` is the real address the datagram is sent to from the exit socket (``out_port`` is that socket's port);
|
||||
``reported_as`` is the address the client is told the reply came from (None: the real source). A subclass may also
|
||||
answer by itself with ``answer(host, port, data)``. By default the fake STUN server, by name or by number, is
|
||||
mapped and everything else is forwarded for real."""
|
||||
mapped and everything else is forwarded when it is the lab's (``_admits``); a datagram to any other destination is dropped and recorded."""
|
||||
if (host, dport) in ((STUN_NAME, STUN_PORT), (STUN_NUMBER, STUN_PORT), (MEASURE_NUMBER, STUN_PORT)):
|
||||
if not self.stun_answers:
|
||||
return None
|
||||
# A real server answers from the address it was asked at; the fake STUN server is mapped, so its reply is
|
||||
# reported as from the asked address (only when that was a literal: a name has no address to report).
|
||||
return self.stun.address, ((host, dport) if atyp == 1 else None)
|
||||
if not self._admits(host, dport, atyp, "udp"):
|
||||
return None # not the lab's: dropped, and recorded
|
||||
if self.forward_only_to is not None and host not in self.forward_only_to:
|
||||
return None
|
||||
return (host, dport), None
|
||||
@@ -685,12 +804,15 @@ def silent_udp(*, exit_ip: str = EXIT, user: Optional[str] = None, password: Opt
|
||||
# A tiny TCP-only SOCKS5 server for the e2e tests (the fixture `socks5_tcp_only` of conftest.py makes one).
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
class Socks5TcpOnly:
|
||||
"""Minimal SOCKS5: no-auth, CONNECT (TCP) relayed, UDP ASSOCIATE refused.
|
||||
"""Minimal SOCKS5: no-auth, CONNECT (TCP) relayed to the lab, UDP ASSOCIATE refused.
|
||||
|
||||
Reproduces a residential TCP-only proxy: pages load over TCP, but WebRTC's
|
||||
UDP path is dead - which (for a no-camera page in default_address_only mode)
|
||||
is exactly what made the default-route probe fail and ICE return zero
|
||||
candidates before Fix C.
|
||||
|
||||
Hermetic like :class:`Gateway`: a CONNECT to a destination that is not the lab's (:func:`is_lab_destination`) is refused with reply 2 and
|
||||
recorded in :attr:`guard` (written under ``$RUNNER_TEMP/invpw-evidence/socks5-tcp-only/`` when the server is closed).
|
||||
"""
|
||||
|
||||
def __init__(self, exit_ip: Optional[str] = None):
|
||||
@@ -699,10 +821,12 @@ class Socks5TcpOnly:
|
||||
self._srv.bind(("127.0.0.1", 0))
|
||||
self._srv.listen(16)
|
||||
self.port = self._srv.getsockname()[1]
|
||||
#: It relays a CONNECT for real, so it declares its exit (what a launch behind it is told: the lab's, unless a test gives another).
|
||||
#: It relays a CONNECT (to the lab), so it declares its exit (what a launch behind it is told: the lab's, unless a test gives another).
|
||||
self.exit_ip = exit_ip or _lab_exit()
|
||||
declare_exit(self.server, self.exit_ip)
|
||||
self.udp_associate_attempts = 0
|
||||
#: What refuses (and records) every CONNECT that is not the lab's.
|
||||
self.guard = LabGuard("socks5-tcp-only")
|
||||
self._stop = False
|
||||
self._t = threading.Thread(target=self._serve, daemon=True)
|
||||
self._t.start()
|
||||
@@ -762,6 +886,10 @@ class Socks5TcpOnly:
|
||||
conn.sendall(b"\x05\x02\x00\x01\x00\x00\x00\x00\x00\x00") # not allowed: the exit is declared, not asked of the internet
|
||||
conn.close()
|
||||
return
|
||||
if not self.guard.admits(addr, port, atyp, "tcp"):
|
||||
conn.sendall(b"\x05\x02\x00\x01\x00\x00\x00\x00\x00\x00") # not allowed: nothing outside the lab is carried
|
||||
conn.close()
|
||||
return
|
||||
try:
|
||||
upstream = socket.create_connection((addr, port), timeout=30)
|
||||
except OSError:
|
||||
@@ -801,3 +929,4 @@ class Socks5TcpOnly:
|
||||
self._srv.close()
|
||||
except Exception:
|
||||
pass
|
||||
self.guard.write_evidence()
|
||||
@@ -33,26 +33,22 @@ IPv6 route answers `ENETUNREACH`, the same `NS_ERROR_CONNECTION_REFUSED` as the
|
||||
declared-off launch and behind the proxy. The port is 80: Firefox bans port 9 (discard) before any connect, so a fetch to it never reaches the gate.
|
||||
|
||||
Hermetic: a local listener, a local SOCKS5 gateway of `tests/_socks_servers.py` that maps the documentation address to the listener and forwards
|
||||
NOTHING else: the browser's own background traffic also arrives at the gateway, and every CONNECT to an address that is not the lab's is refused
|
||||
(reply 5) and recorded. Every request, refused or carried, is recorded with its time since the launch, its SOCKS5 address type, its destination as received and
|
||||
its port. The refused list is written, always, under `$RUNNER_TEMP/invpw-evidence/` (the folder the e2e jobs upload), so that a reader sees
|
||||
what the browser asked for besides the literal.
|
||||
NOTHING else: the browser's own background traffic also arrives at the gateway, and every CONNECT that is not the one carried to the listener is refused
|
||||
(reply 2) and recorded. Every gateway of that module is hermetic the same way (it carries only the lab's, see its docstring); this one is narrower still:
|
||||
the lab for it is the listener alone. Every request, refused or carried, is recorded with its time since the launch, its SOCKS5 address type, its destination
|
||||
as received and its port. The refused list is written, always, when the gateway is closed, under `$RUNNER_TEMP/invpw-evidence/` (the folder the e2e jobs
|
||||
upload), so that a reader sees what the browser asked for besides the literal.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import socketserver
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from _servers import LocalServer
|
||||
from _socks_servers import EXIT, Gateway, _recv_exact
|
||||
from _socks_servers import EXIT, Gateway
|
||||
from _udp_line import egress_by_proxy, measure_servers
|
||||
from _waits import wait_until
|
||||
from test_declared_host_network_e2e import DUAL, NETWORK_ENV, V4_ONLY
|
||||
@@ -66,8 +62,6 @@ DOCUMENTATION_HTTP = 80
|
||||
REFUSED = "NS_ERROR_CONNECTION_REFUSED"
|
||||
#: SOCKS5 address type of an IPv6 address (RFC 1928); 1 is IPv4, 3 a domain name.
|
||||
ATYP_IPV6 = 4
|
||||
#: The folder under ``$RUNNER_TEMP`` the e2e workflows upload (``invpw-evidence-*``).
|
||||
EVIDENCE_FOLDER = "invpw-evidence"
|
||||
#: The deadline of a fetch that must END (refused, or carried): far beyond a healthy run; what the page reads on a timeout is a `TimeoutError`, never a verdict.
|
||||
FETCH_SECONDS = 30
|
||||
|
||||
@@ -113,14 +107,15 @@ class _Listener:
|
||||
class _GatewayToALocalListener(Gateway):
|
||||
"""The SOCKS5 gateway of the tests (UDP refused) that carries the documentation address to a local listener and forwards nothing else: the destination
|
||||
it is asked for is what it records in ``connects`` (with its SOCKS5 address type in ``addresses``), what the listener hears is what it carried, and
|
||||
every CONNECT to an address that is not the lab's is refused and recorded in ``refused``."""
|
||||
every CONNECT that is not carried to the listener is refused (the base gateway refuses what is not the lab's; here the lab is the listener alone) and
|
||||
recorded in ``refused``."""
|
||||
|
||||
evidence_name = "ipv6-literal-refused-connects"
|
||||
|
||||
def __init__(self, carried: dict) -> None:
|
||||
self._carried = dict(carried)
|
||||
#: Every address of a request the gateway read, as (host, port, address type), in order.
|
||||
self.addresses: list = []
|
||||
#: Every CONNECT that was not the lab's and was refused (reply 5, connection refused), as (host, port), in order.
|
||||
self.refused: list = []
|
||||
#: Every request, as a dict, for the evidence file: ``t`` (seconds, monotonic, since ``launch_started``), ``atyp`` (SOCKS5 address type: 1 IPv4,
|
||||
#: 3 domain name, 4 IPv6), ``destination`` (as received: the NAME when the type is 3), ``port``, ``outcome``.
|
||||
self.records: list = []
|
||||
@@ -128,23 +123,18 @@ class _GatewayToALocalListener(Gateway):
|
||||
self._current = threading.local()
|
||||
super().__init__(udp="refuse", tcp_exit=EXIT, udp_exit=EXIT)
|
||||
|
||||
@staticmethod
|
||||
def _address_of(c: socket.socket):
|
||||
atyp = _recv_exact(c, 1)[0]
|
||||
if atyp == 1:
|
||||
host = socket.inet_ntoa(_recv_exact(c, 4))
|
||||
elif atyp == 3:
|
||||
host = _recv_exact(c, _recv_exact(c, 1)[0]).decode()
|
||||
else:
|
||||
host = socket.inet_ntop(socket.AF_INET6, _recv_exact(c, 16))
|
||||
return host, struct.unpack("!H", _recv_exact(c, 2))[0], atyp
|
||||
@property
|
||||
def refused(self) -> list:
|
||||
"""Every CONNECT that was refused, as (destination as received, port), in order."""
|
||||
return self.guard.refused("tcp")
|
||||
|
||||
def launch_started(self) -> None:
|
||||
"""Call just before the launch of the browser behind this gateway: the origin of the times of ``records``."""
|
||||
self._launch_t0 = time.monotonic()
|
||||
|
||||
def _read_address(self, c: socket.socket):
|
||||
host, port, atyp = self._address_of(c)
|
||||
def _read_address(self, c):
|
||||
host, port = super()._read_address(c)
|
||||
atyp = self._local.atyp
|
||||
self.addresses.append((host, port, atyp))
|
||||
record = {"t": round(time.monotonic() - self._launch_t0, 3), "atyp": atyp, "destination": host, "port": port,
|
||||
"outcome": "answered by the lab (or not a CONNECT)"}
|
||||
@@ -155,32 +145,23 @@ class _GatewayToALocalListener(Gateway):
|
||||
def _target(self, host: str, port: int):
|
||||
return self._carried.get((host, port), (host, port))
|
||||
|
||||
def _open_upstream(self, target):
|
||||
if target not in self._carried.values():
|
||||
self.refused.append(target)
|
||||
def _admits(self, host, port, atyp, protocol, target=None):
|
||||
if (target or (host, port)) not in self._carried.values():
|
||||
self.guard.refuse(host, port, atyp, protocol)
|
||||
self._current.record["outcome"] = "refused"
|
||||
raise OSError("the lab forwards nothing outside the lab: %s:%d" % target)
|
||||
return False
|
||||
self._current.record["outcome"] = "carried to the listener of the lab"
|
||||
return super()._open_upstream(target)
|
||||
return super()._admits(host, port, atyp, protocol, target)
|
||||
|
||||
def _evidence(self) -> dict:
|
||||
"""The refusals are written by the base gateway at the close, with every request of the launch, so that a reader sees what the browser asked for."""
|
||||
return {"requests": self.records}
|
||||
|
||||
def documentation_connects(self) -> list:
|
||||
"""Every request of the navigation to the documentation destination, in whatever shape it arrived: the host is told by its digits."""
|
||||
return [(host, port, atyp) for host, port, atyp in self.addresses if "2001:db8" in host.lower()]
|
||||
|
||||
|
||||
def _write_refused(gateway: "_GatewayToALocalListener") -> None:
|
||||
"""What the gateway refused, always (a few lines): under ``$RUNNER_TEMP/invpw-evidence/`` the e2e jobs upload. Off a runner nothing is written."""
|
||||
runner_temp = os.environ.get("RUNNER_TEMP")
|
||||
if not runner_temp:
|
||||
return
|
||||
folder = pathlib.Path(runner_temp) / EVIDENCE_FOLDER / "ipv6-literal-refused-connects" / ("%d-%d" % (os.getpid(), int(time.time() * 1000)))
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
(folder / "refused-connects.json").write_text(json.dumps({
|
||||
"refused": ["%s:%d" % target for target in gateway.refused],
|
||||
"requests": gateway.records,
|
||||
}, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def _launch(firefox_binary, gateway=None):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
@@ -243,8 +224,7 @@ def test_a_direct_ipv6_literal_is_refused_and_one_behind_socks_is_left_to_the_pr
|
||||
wait_until(lambda: behind.connections, FETCH_SECONDS, lambda: page.wait_for_timeout(50))
|
||||
documentation = gateway.documentation_connects()
|
||||
finally:
|
||||
gateway.close()
|
||||
_write_refused(gateway)
|
||||
gateway.close() # writes what it refused and every request, under $RUNNER_TEMP/invpw-evidence/
|
||||
|
||||
# The listener is real: its IPv4 literal reaches it, once per launch.
|
||||
for name, seen in (("declared off", off), ("declared on", on)):
|
||||
|
||||
@@ -9,6 +9,10 @@ handshake and relays traffic.
|
||||
Fully hermetic - a local SOCKS5 server + a local HTTP target, with the localhost
|
||||
target forced through the proxy via ``allow_hijacking_localhost`` - so it runs
|
||||
identically on a dev box and on a GitHub runner (no external site, no secrets).
|
||||
The SOCKS5 server carries only the lab's (``_socks_servers.is_lab_destination``: loopback, the documentation ranges, the addresses of this host): the
|
||||
browser behind it also makes background requests of its own, and a CONNECT to any other destination is refused (reply 2) and recorded
|
||||
(``_socks_servers.LabGuard``: time since the server started, address type, destination as received, port, protocol), the record written when the server is
|
||||
closed under ``$RUNNER_TEMP/invpw-evidence/socks5-auth-recorder/`` (the folder the e2e jobs upload; off a runner nothing is written).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -22,7 +26,7 @@ import pytest
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
from _servers import LocalServer
|
||||
from _socks_servers import asks_the_world, declare_exit, forget_exit
|
||||
from _socks_servers import LabGuard, asks_the_world, declare_exit, forget_exit
|
||||
|
||||
_USER = "ferd_socks_user"
|
||||
_PASS = "ferd_socks_pw_42"
|
||||
@@ -30,7 +34,8 @@ _PASS = "ferd_socks_pw_42"
|
||||
|
||||
class _Socks5AuthRecorder:
|
||||
"""SOCKS5 that REQUIRES RFC1929 user/pass auth, records the creds it saw,
|
||||
then relays CONNECT to the requested target."""
|
||||
then relays CONNECT to the requested target when it is the lab's (loopback, the documentation ranges, this host); any other CONNECT is refused and
|
||||
recorded in :attr:`guard`."""
|
||||
|
||||
def __init__(self):
|
||||
self._srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -44,6 +49,8 @@ class _Socks5AuthRecorder:
|
||||
|
||||
declare_exit(self.server, LAB_EGRESS_IP)
|
||||
self.seen_creds: list[tuple[str, str]] = []
|
||||
#: What refuses (and records) every CONNECT that is not the lab's.
|
||||
self.guard = LabGuard("socks5-auth-recorder")
|
||||
self._stop = False
|
||||
threading.Thread(target=self._serve, daemon=True).start()
|
||||
|
||||
@@ -102,6 +109,8 @@ class _Socks5AuthRecorder:
|
||||
conn.sendall(b"\x05\x07\x00\x01\x00\x00\x00\x00\x00\x00"); conn.close(); return
|
||||
if asks_the_world(self.server, addr, port): # the exit is declared above, not asked of the internet
|
||||
conn.sendall(b"\x05\x02\x00\x01\x00\x00\x00\x00\x00\x00"); conn.close(); return
|
||||
if not self.guard.admits(addr, port, atyp, "tcp"): # nothing outside the lab is carried
|
||||
conn.sendall(b"\x05\x02\x00\x01\x00\x00\x00\x00\x00\x00"); conn.close(); return
|
||||
try:
|
||||
up = socket.create_connection((addr, port), timeout=30)
|
||||
except OSError:
|
||||
@@ -140,6 +149,7 @@ class _Socks5AuthRecorder:
|
||||
self._srv.close()
|
||||
except OSError:
|
||||
pass
|
||||
self.guard.write_evidence()
|
||||
|
||||
|
||||
class _LocalHTTP:
|
||||
|
||||
@@ -0,0 +1,428 @@
|
||||
"""The proxies of the tests carry only the lab's destinations: any other is refused and recorded, never forwarded.
|
||||
|
||||
The e2e tests run in the gate of the candidate, where no test may depend on a real service. A proxy of the tests that relayed a CONNECT or a datagram for
|
||||
real would carry the background requests of the browser behind it (a name of the vendor, a captive-portal check, a telemetry endpoint) to the internet, and
|
||||
a verdict would then depend on whether the runner reaches them. What this holds, on the helpers themselves (no browser):
|
||||
|
||||
* :func:`_socks_servers.is_lab_destination`: loopback, the documentation ranges, the addresses of this host's own interfaces and ``localhost`` are the lab's;
|
||||
a public address, a name of the internet and a public IPv6 address are not (an IPv4-mapped one is judged as the IPv4 address it carries);
|
||||
* the base :class:`_socks_servers.Gateway` (and with it ``Gateway(tcp_from_exit=True)``): a CONNECT to a public address or to a name is answered with reply 2
|
||||
and never opened upstream, a CONNECT to a loopback server is carried; a datagram of the UDP relay to a public address or a name is dropped, one to a lab
|
||||
address is sent; each refusal is recorded (time since the gateway started, address type, destination as received, port, protocol ``tcp`` or ``udp``);
|
||||
* ``Socks5TcpOnly`` and the SOCKS5 server of ``test_proxy_socks_auth_e2e.py`` (``_Socks5AuthRecorder``) do the same for CONNECT;
|
||||
* the record is written, always, when the gateway is closed, under ``$RUNNER_TEMP/invpw-evidence/<gateway>/`` (the folder the e2e jobs upload), once even
|
||||
if the gateway is closed twice; off a runner (no ``RUNNER_TEMP``) nothing is written;
|
||||
* the gateway of ``test_ipv6_literal_connect_e2e.py``, which narrows the rule to the listener it carries to, still carries the mapped destination and refuses
|
||||
a loopback server that is not the one mapped.
|
||||
|
||||
Known-bad inputs: a CONNECT to ``8.8.8.8:443`` (a public address), to ``detectportal.firefox.com:80`` (a name) and to a public IPv6 address; a datagram to
|
||||
``8.8.8.8:443`` and to a name; each must be refused and recorded, and nothing must be opened or sent for it.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import socket
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
import _socks_servers as servers
|
||||
from _socks_servers import Socks5TcpOnly, coherent, is_lab_destination
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
PUBLIC_V4 = "8.8.8.8"
|
||||
PUBLIC_V6 = "2606:4700:4700::1111"
|
||||
NAME = "detectportal.firefox.com"
|
||||
|
||||
#: Address types of a SOCKS5 request (RFC 1928).
|
||||
V4, NAMED, V6 = 1, 3, 4
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_own_addresses(monkeypatch):
|
||||
"""The addresses of this machine's interfaces are not a fact of the test (a runner may have a public one): none, unless a test names them."""
|
||||
monkeypatch.setattr(servers, "_own_addresses", lambda: set())
|
||||
|
||||
|
||||
def _address(host: str, atyp: int) -> bytes:
|
||||
if atyp == V4:
|
||||
return b"\x01" + socket.inet_aton(host)
|
||||
if atyp == V6:
|
||||
return b"\x04" + socket.inet_pton(socket.AF_INET6, host)
|
||||
return b"\x03" + bytes([len(host)]) + host.encode()
|
||||
|
||||
|
||||
def _connect(port: int, host: str, dport: int, atyp: int, credentials=None):
|
||||
"""A SOCKS5 CONNECT to ``port`` of 127.0.0.1: the connected socket and the reply code."""
|
||||
s = socket.create_connection(("127.0.0.1", port), timeout=10)
|
||||
if credentials is None:
|
||||
s.sendall(b"\x05\x01\x00")
|
||||
assert s.recv(2) == b"\x05\x00"
|
||||
else:
|
||||
user, password = (c.encode() for c in credentials)
|
||||
s.sendall(b"\x05\x01\x02")
|
||||
assert s.recv(2) == b"\x05\x02"
|
||||
s.sendall(b"\x01" + bytes([len(user)]) + user + bytes([len(password)]) + password)
|
||||
assert s.recv(2) == b"\x01\x00"
|
||||
s.sendall(b"\x05\x01\x00" + _address(host, atyp) + struct.pack("!H", dport))
|
||||
reply = b""
|
||||
while len(reply) < 10:
|
||||
chunk = s.recv(10 - len(reply))
|
||||
if not chunk:
|
||||
break
|
||||
reply += chunk
|
||||
return s, (reply[1] if len(reply) > 1 else None)
|
||||
|
||||
|
||||
class _Echo:
|
||||
"""A TCP echo server on 127.0.0.1: the lab's server."""
|
||||
|
||||
def __init__(self):
|
||||
self._listener = socket.socket()
|
||||
self._listener.bind(("127.0.0.1", 0))
|
||||
self._listener.listen(8)
|
||||
self.port = self._listener.getsockname()[1]
|
||||
threading.Thread(target=self._serve, daemon=True).start()
|
||||
|
||||
def _serve(self):
|
||||
while True:
|
||||
try:
|
||||
conn, _ = self._listener.accept()
|
||||
except OSError:
|
||||
return
|
||||
threading.Thread(target=self._echo, args=(conn,), daemon=True).start()
|
||||
|
||||
@staticmethod
|
||||
def _echo(conn):
|
||||
try:
|
||||
data = conn.recv(4096)
|
||||
conn.sendall(data)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def close(self):
|
||||
self._listener.close()
|
||||
|
||||
|
||||
def _the_echo_is_carried(port: int, echo_port: int, credentials=None) -> None:
|
||||
s, code = _connect(port, "127.0.0.1", echo_port, V4, credentials)
|
||||
try:
|
||||
assert code == 0, "a CONNECT to a loopback server was refused (reply %s)" % code
|
||||
s.sendall(b"ping")
|
||||
assert s.recv(4) == b"ping"
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
def _fields(record: dict) -> tuple:
|
||||
return record["atyp"], record["destination"], record["port"], record["protocol"]
|
||||
|
||||
|
||||
# -- what is the lab's -----------------------------------------------------------------------------------------------------
|
||||
@pytest.mark.parametrize("host", [
|
||||
"127.0.0.1", "127.9.9.9", "::1", "::ffff:127.0.0.1", "[::1]", "198.51.100.9", "198.51.100.5", "203.0.113.80", "203.0.113.7", "192.0.2.1",
|
||||
"2001:db8::1", "[2001:db8::1]", "localhost", "LOCALHOST", "localhost.", "page.localhost",
|
||||
])
|
||||
def test_these_are_the_labs(host):
|
||||
assert is_lab_destination(host), host
|
||||
|
||||
|
||||
@pytest.mark.parametrize("host", [
|
||||
PUBLIC_V4, "1.1.1.1", PUBLIC_V6, "::ffff:8.8.8.8", "10.9.8.7", "192.168.1.20", "fe80::1", NAME, "api.ipify.org", "stun.l.google.com",
|
||||
"example.com", "page.test", "localhost.example.com", "",
|
||||
])
|
||||
def test_these_are_not_the_labs(host):
|
||||
assert not is_lab_destination(host), host
|
||||
|
||||
|
||||
def test_an_address_of_an_interface_of_this_host_is_the_labs_and_no_other_private_one(monkeypatch):
|
||||
monkeypatch.setattr(servers, "_own_addresses", lambda: {"10.9.8.7", "fd00::7"})
|
||||
assert is_lab_destination("10.9.8.7") and is_lab_destination("fd00::7") and is_lab_destination("::ffff:10.9.8.7")
|
||||
assert not is_lab_destination("10.9.8.8") and not is_lab_destination("fd00::8")
|
||||
|
||||
|
||||
# -- the TCP side of the base gateway --------------------------------------------------------------------------------------
|
||||
@pytest.mark.parametrize("host, atyp", [(PUBLIC_V4, V4), (NAME, NAMED), (PUBLIC_V6, V6)], ids=["public_ipv4", "name", "public_ipv6"])
|
||||
def test_a_connect_to_a_public_destination_is_refused_recorded_and_never_opened(host, atyp):
|
||||
with coherent() as gateway:
|
||||
opened = []
|
||||
gateway._open_upstream = lambda target: opened.append(target) or pytest.fail("the gateway opened a connection to %s" % (target,))
|
||||
s, code = _connect(gateway.port, host, 443, atyp)
|
||||
s.close()
|
||||
assert code == 2, "the reply to a CONNECT outside the lab is 2 (not allowed): %s" % code
|
||||
assert opened == []
|
||||
assert len(gateway.guard.records) == 1
|
||||
record = gateway.guard.records[0]
|
||||
assert _fields(record) == (atyp, host, 443, "tcp"), record
|
||||
assert record["t"] >= 0
|
||||
assert gateway.guard.refused("tcp") == [(host, 443)] and gateway.guard.refused("udp") == []
|
||||
assert (host, 443) in gateway.connects, "the CONNECT is still listed: the test sees what the browser asked for"
|
||||
|
||||
|
||||
def test_a_connect_to_a_loopback_server_is_carried_and_leaves_no_refusal():
|
||||
echo = _Echo()
|
||||
try:
|
||||
with coherent() as gateway:
|
||||
_the_echo_is_carried(gateway.port, echo.port)
|
||||
assert gateway.guard.records == []
|
||||
finally:
|
||||
echo.close()
|
||||
|
||||
|
||||
def test_a_gateway_with_credentials_refuses_the_same_way():
|
||||
with coherent(user="alice", password="s3cret") as gateway:
|
||||
s, code = _connect(gateway.port, PUBLIC_V4, 80, V4, ("alice", "s3cret"))
|
||||
s.close()
|
||||
assert code == 2 and gateway.guard.refused("tcp") == [(PUBLIC_V4, 80)]
|
||||
|
||||
|
||||
def test_a_gateway_that_leaves_from_its_exit_refuses_a_public_connect_too():
|
||||
"""``Gateway(tcp_from_exit=True)``: the connection of the gateway would leave from ``exit_host``; to a public address it is never made."""
|
||||
with servers.Gateway(udp="refuse", tcp_exit="203.0.113.7", udp_exit="203.0.113.7", exit_host="127.0.0.2", tcp_from_exit=True) as gateway:
|
||||
opened = []
|
||||
gateway._open_upstream = lambda target: opened.append(target) or pytest.fail("the gateway opened a connection to %s" % (target,))
|
||||
s, code = _connect(gateway.port, PUBLIC_V4, 443, V4)
|
||||
s.close()
|
||||
assert code == 2 and opened == [] and gateway.guard.refused("tcp") == [(PUBLIC_V4, 443)]
|
||||
echo = _Echo()
|
||||
try:
|
||||
with servers.Gateway(udp="refuse", tcp_exit="203.0.113.7", udp_exit="203.0.113.7", exit_host="127.0.0.2", tcp_from_exit=True) as gateway:
|
||||
_the_echo_is_carried(gateway.port, echo.port)
|
||||
assert gateway.guard.records == []
|
||||
finally:
|
||||
echo.close()
|
||||
|
||||
|
||||
def test_the_questions_the_gateway_answers_itself_are_not_refusals():
|
||||
"""The exit question (``api.ipify.org:80``) and the page of ``WEB_NAME`` are the lab's own answers, given before the rule."""
|
||||
with coherent() as gateway:
|
||||
s, code = _connect(gateway.port, "api.ipify.org", 80, NAMED)
|
||||
try:
|
||||
assert code == 0
|
||||
s.sendall(b"GET / HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n")
|
||||
assert gateway.tcp_exit.encode() in s.recv(4096)
|
||||
finally:
|
||||
s.close()
|
||||
s, code = _connect(gateway.port, servers.WEB_NAME, 80, NAMED)
|
||||
s.close()
|
||||
assert code == 0 and gateway.guard.records == []
|
||||
|
||||
|
||||
# -- the UDP side of the base gateway --------------------------------------------------------------------------------------
|
||||
def _associate(gateway):
|
||||
control = socket.create_connection(("127.0.0.1", gateway.port), timeout=5)
|
||||
control.sendall(b"\x05\x01\x00")
|
||||
assert control.recv(2) == b"\x05\x00"
|
||||
control.sendall(b"\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00")
|
||||
reply = b""
|
||||
while len(reply) < 10:
|
||||
reply += control.recv(10 - len(reply))
|
||||
assert reply[1] == 0, "the association was refused: %r" % reply
|
||||
return control, (socket.inet_ntoa(reply[4:8]), int.from_bytes(reply[8:10], "big"))
|
||||
|
||||
|
||||
def _datagram(host: str, port: int, atyp: int, payload: bytes) -> bytes:
|
||||
return b"\x00\x00\x00" + _address(host, atyp) + struct.pack("!H", port) + payload
|
||||
|
||||
|
||||
def test_a_datagram_to_a_public_destination_is_dropped_recorded_and_never_sent_and_one_to_a_lab_address_is_sent():
|
||||
from _waits import wait_until
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
server.bind(("127.0.0.1", 0))
|
||||
server.settimeout(10)
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.bind(("127.0.0.1", 0))
|
||||
with coherent() as gateway:
|
||||
sent = []
|
||||
carry = gateway._later
|
||||
gateway._later = lambda fn, what="a datagram": (sent.append(what), carry(fn, what))
|
||||
control, relay = _associate(gateway)
|
||||
try:
|
||||
client.sendto(_datagram(PUBLIC_V4, 443, V4, b"quic"), relay)
|
||||
client.sendto(_datagram(NAME, 443, NAMED, b"quic"), relay)
|
||||
client.sendto(_datagram(PUBLIC_V6, 443, V6, b"quic"), relay)
|
||||
# the control: the same relay carries a datagram to a lab address (this one is read by the server below)
|
||||
client.sendto(_datagram("127.0.0.1", server.getsockname()[1], V4, b"lab"), relay)
|
||||
data, _peer = server.recvfrom(4096)
|
||||
assert data == b"lab"
|
||||
wait_until(lambda: len(gateway.datagrams) >= 4, 30, lambda: time.sleep(0.01))
|
||||
assert len(sent) == 1 and sent[0].startswith("the datagram to 127.0.0.1:"), "only the lab's datagram was sent: %s" % sent
|
||||
assert [_fields(r) for r in gateway.guard.records] == [
|
||||
(V4, PUBLIC_V4, 443, "udp"), (NAMED, NAME, 443, "udp"), (V6, PUBLIC_V6, 443, "udp")]
|
||||
assert gateway.guard.refused("tcp") == []
|
||||
assert {(h, p) for h, p, _d in gateway.datagrams} >= {(PUBLIC_V4, 443), (NAME, 443)}, "the datagrams read are still listed"
|
||||
assert gateway.send_errors == []
|
||||
finally:
|
||||
control.close()
|
||||
client.close()
|
||||
server.close()
|
||||
|
||||
|
||||
def test_the_documentation_addresses_and_the_fake_stun_are_the_labs_on_the_relay():
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.bind(("127.0.0.1", 0))
|
||||
client.settimeout(10)
|
||||
with coherent() as gateway:
|
||||
control, relay = _associate(gateway)
|
||||
try:
|
||||
request = b"\x00\x01\x00\x00\x21\x12\xa4\x42" + b"txid-of-12by"
|
||||
for number in (servers.STUN_NUMBER, servers.MEASURE_NUMBER):
|
||||
client.sendto(_datagram(number, servers.STUN_PORT, V4, request), relay)
|
||||
answer, _peer = client.recvfrom(4096)
|
||||
assert answer[10:12] == b"\x01\x01"
|
||||
client.sendto(_datagram(servers.STUN_NAME, servers.STUN_PORT, NAMED, request), relay)
|
||||
answer, _peer = client.recvfrom(4096)
|
||||
assert answer[10:12] == b"\x01\x01"
|
||||
assert gateway.guard.records == []
|
||||
finally:
|
||||
control.close()
|
||||
client.close()
|
||||
|
||||
|
||||
def test_forward_only_to_only_narrows():
|
||||
"""A host the test lists that is not the lab's is not forwarded either: the list never reopens the rule."""
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.bind(("127.0.0.1", 0))
|
||||
with coherent() as gateway:
|
||||
gateway.forward_only_to = {PUBLIC_V4}
|
||||
sent = []
|
||||
carry = gateway._later
|
||||
gateway._later = lambda fn, what="a datagram": (sent.append(what), carry(fn, what))
|
||||
control, relay = _associate(gateway)
|
||||
try:
|
||||
from _waits import wait_until
|
||||
|
||||
client.sendto(_datagram(PUBLIC_V4, 443, V4, b"quic"), relay)
|
||||
wait_until(lambda: gateway.guard.records, 30, lambda: time.sleep(0.01))
|
||||
assert sent == [] and gateway.guard.refused("udp") == [(PUBLIC_V4, 443)]
|
||||
finally:
|
||||
control.close()
|
||||
client.close()
|
||||
|
||||
|
||||
# -- the other proxies -----------------------------------------------------------------------------------------------------
|
||||
def test_the_tcp_only_proxy_refuses_a_public_connect_and_carries_a_loopback_one():
|
||||
echo = _Echo()
|
||||
proxy = Socks5TcpOnly()
|
||||
try:
|
||||
for host, atyp in ((PUBLIC_V4, V4), (NAME, NAMED), (PUBLIC_V6, V6)):
|
||||
s, code = _connect(proxy.port, host, 443, atyp)
|
||||
s.close()
|
||||
assert code == 2, (host, code)
|
||||
assert [_fields(r) for r in proxy.guard.records] == [(V4, PUBLIC_V4, 443, "tcp"), (NAMED, NAME, 443, "tcp"), (V6, PUBLIC_V6, 443, "tcp")]
|
||||
_the_echo_is_carried(proxy.port, echo.port)
|
||||
assert len(proxy.guard.records) == 3
|
||||
finally:
|
||||
proxy.close()
|
||||
echo.close()
|
||||
|
||||
|
||||
def test_the_proxy_that_asks_for_the_exit_still_fails_the_test_that_asked_the_world():
|
||||
"""The question of the exit keeps its own backstop (``asks_the_world``) ahead of the rule, so a proxy that forgot to declare its exit is a red with its name."""
|
||||
proxy = Socks5TcpOnly()
|
||||
try:
|
||||
s, code = _connect(proxy.port, "api.ipify.org", 443, NAMED)
|
||||
s.close()
|
||||
assert code == 2 and len(servers.nobody_asked_the_world()) == 1
|
||||
assert proxy.guard.records == [], "the question of the exit is the backstop's, not a destination the rule refused"
|
||||
finally:
|
||||
proxy.close()
|
||||
|
||||
|
||||
def test_the_socks5_server_with_authentication_refuses_a_public_connect_and_carries_a_loopback_one():
|
||||
from test_proxy_socks_auth_e2e import _USER, _PASS, _Socks5AuthRecorder
|
||||
|
||||
echo = _Echo()
|
||||
proxy = _Socks5AuthRecorder()
|
||||
try:
|
||||
s, code = _connect(proxy.port, PUBLIC_V4, 443, V4, (_USER, _PASS))
|
||||
s.close()
|
||||
assert code == 2
|
||||
s, code = _connect(proxy.port, NAME, 80, NAMED, (_USER, _PASS))
|
||||
s.close()
|
||||
assert code == 2
|
||||
assert [_fields(r) for r in proxy.guard.records] == [(V4, PUBLIC_V4, 443, "tcp"), (NAMED, NAME, 80, "tcp")]
|
||||
_the_echo_is_carried(proxy.port, echo.port, (_USER, _PASS))
|
||||
assert len(proxy.guard.records) == 2 and (_USER, _PASS) in proxy.seen_creds
|
||||
finally:
|
||||
proxy.close()
|
||||
echo.close()
|
||||
|
||||
|
||||
def test_the_doh_gateway_records_what_it_refuses_and_its_relay_is_the_labs_only():
|
||||
from _doh_servers import DohGateway, FakeDoh
|
||||
|
||||
with FakeDoh({}) as doh, DohGateway("gw", doh, udp="relay") as gateway:
|
||||
s, code = _connect(gateway.port, PUBLIC_V4, 443, V4)
|
||||
s.close()
|
||||
assert code == 2 and gateway.refused == [(PUBLIC_V4, 443)]
|
||||
assert [_fields(r) for r in gateway.guard.records] == [(V4, PUBLIC_V4, 443, "tcp")]
|
||||
|
||||
|
||||
def test_the_gateway_of_the_ipv6_literal_test_carries_only_what_it_maps():
|
||||
from test_ipv6_literal_connect_e2e import DOCUMENTATION, _GatewayToALocalListener, _Listener
|
||||
|
||||
with _Listener() as listener:
|
||||
gateway = _GatewayToALocalListener({(DOCUMENTATION, 80): ("127.0.0.1", listener.port)})
|
||||
try:
|
||||
s, code = _connect(gateway.port, DOCUMENTATION, 80, V6)
|
||||
try:
|
||||
assert code == 0, "the mapped destination was not carried"
|
||||
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
|
||||
assert s.recv(4096).startswith(b"HTTP/1.1 200")
|
||||
finally:
|
||||
s.close()
|
||||
s, code = _connect(gateway.port, "127.0.0.1", listener.port ^ 1, V4) # loopback, but not the listener it maps to
|
||||
s.close()
|
||||
assert code == 2
|
||||
s, code = _connect(gateway.port, PUBLIC_V4, 443, V4)
|
||||
s.close()
|
||||
assert code == 2
|
||||
assert gateway.refused == [("127.0.0.1", listener.port ^ 1), (PUBLIC_V4, 443)]
|
||||
assert gateway.documentation_connects() == [(DOCUMENTATION, 80, V6)]
|
||||
assert [r["outcome"] for r in gateway.records] == [
|
||||
"carried to the listener of the lab", "refused", "refused"]
|
||||
finally:
|
||||
gateway.close()
|
||||
|
||||
|
||||
# -- the record ------------------------------------------------------------------------------------------------------------
|
||||
def test_the_record_is_written_when_the_gateway_is_closed_under_the_evidence_folder_and_once(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("RUNNER_TEMP", str(tmp_path))
|
||||
gateway = coherent()
|
||||
s, code = _connect(gateway.port, NAME, 80, NAMED)
|
||||
s.close()
|
||||
assert code == 2
|
||||
gateway.close()
|
||||
gateway.close()
|
||||
files = sorted((tmp_path / "invpw-evidence").rglob("*.json"))
|
||||
assert len(files) == 1, files
|
||||
assert files[0].parent.parent.name == "socks5-gateway" and files[0].name == "refused-destinations.json"
|
||||
written = json.loads(files[0].read_text(encoding="utf-8"))
|
||||
assert written["gateway"] == "socks5-gateway"
|
||||
assert [_fields(r) for r in written["refused"]] == [(NAMED, NAME, 80, "tcp")] and written["refused"][0]["t"] >= 0
|
||||
|
||||
|
||||
def test_a_gateway_that_refused_nothing_still_leaves_its_record(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("RUNNER_TEMP", str(tmp_path))
|
||||
proxy = Socks5TcpOnly()
|
||||
proxy.close()
|
||||
files = sorted((tmp_path / "invpw-evidence" / "socks5-tcp-only").rglob("refused-destinations.json"))
|
||||
assert len(files) == 1 and json.loads(files[0].read_text(encoding="utf-8"))["refused"] == []
|
||||
|
||||
|
||||
def test_off_a_runner_nothing_is_written(tmp_path, monkeypatch):
|
||||
monkeypatch.delenv("RUNNER_TEMP", raising=False)
|
||||
monkeypatch.chdir(tmp_path)
|
||||
gateway = coherent()
|
||||
s, _code = _connect(gateway.port, NAME, 80, NAMED)
|
||||
s.close()
|
||||
gateway.close()
|
||||
assert list(tmp_path.rglob("*")) == []
|
||||
assert servers.LabGuard("x").write_evidence() is None
|
||||
Reference in new issue
Block a user