mirror of
https://github.com/daijro/camoufox.git
synced 2026-10-03 16:00:19 +00:00
The per-context init script passed every webrtc_ip, IPv6 included, to window.setWebRTCIPv4(), and never called setWebRTCIPv6(). An IPv6 address (given directly, or resolved as a proxy's exit IP) was stored as the context's IPv4 value and the IPv6 slot stayed empty. The script now picks the setter by address family, and an address that is neither raises InvalidIP instead of being passed through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
749 B
Python
24 lines
749 B
Python
"""The per-context init script hands a WebRTC IP to the setter for its family."""
|
|
|
|
import pytest
|
|
|
|
from camoufox.exceptions import InvalidIP
|
|
from camoufox.fingerprints import _build_init_script
|
|
|
|
|
|
def test_ipv4_goes_to_the_ipv4_setter():
|
|
script = _build_init_script({"webrtcIP": "203.0.113.7"})
|
|
assert 'w.setWebRTCIPv4("203.0.113.7")' in script
|
|
assert "setWebRTCIPv6(" not in script
|
|
|
|
|
|
def test_ipv6_goes_to_the_ipv6_setter():
|
|
script = _build_init_script({"webrtcIP": "2001:db8::7"})
|
|
assert 'w.setWebRTCIPv6("2001:db8::7")' in script
|
|
assert "2001:db8::7" not in script.split("setWebRTCIPv6")[0]
|
|
|
|
|
|
def test_an_invalid_address_is_refused():
|
|
with pytest.raises(InvalidIP):
|
|
_build_init_script({"webrtcIP": "not-an-ip"})
|