| 1 |
from urllib.parse import urlunsplit |
| 2 |
|
| 3 |
import pytest |
| 4 |
from tests.bidi.browsing_context.navigate import navigate_and_assert |
| 5 |
|
| 6 |
pytestmark = pytest.mark.asyncio |
| 7 |
|
| 8 |
|
| 9 |
@pytest.fixture |
| 10 |
def http_with_https_port_url(server_config): |
| 11 |
""" |
| 12 |
Creates an HTTP URL with a port for HTTPS that would trigger a HTTPS-First |
| 13 |
upgrade when entered in the url bar. |
| 14 |
""" |
| 15 |
|
| 16 |
def _http_with_https_port_url(path, query="", fragment=""): |
| 17 |
domain = server_config["domains"][""][""] |
| 18 |
port = server_config["ports"]["https"][0] |
| 19 |
return urlunsplit(("http", f"{domain}:{port}", path, query, fragment)) |
| 20 |
|
| 21 |
return _http_with_https_port_url |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.capabilities( |
| 25 |
{ |
| 26 |
"moz:firefoxOptions": { |
| 27 |
"prefs": { |
| 28 |
# Allow HTTPS upgrades for localhost and custom ports |
| 29 |
"dom.security.https_first_for_custom_ports": True, |
| 30 |
"dom.security.https_first_for_local_addresses": True, |
| 31 |
"dom.security.https_first_for_unknown_suffixes": True, |
| 32 |
}, |
| 33 |
}, |
| 34 |
} |
| 35 |
) |
| 36 |
async def test_no_https_first_upgrade(bidi_session, new_tab, http_with_https_port_url): |
| 37 |
page = http_with_https_port_url("/webdriver/tests/support/html/default.html") |
| 38 |
|
| 39 |
# A navigation via the WebDriver API should not cause an HTTPS upgrade, |
| 40 |
# so it fails with a neterror page. |
| 41 |
await navigate_and_assert( |
| 42 |
bidi_session, |
| 43 |
new_tab, |
| 44 |
page, |
| 45 |
expected_error=True, |
| 46 |
) |
| 47 |
|
| 48 |
contexts = await bidi_session.browsing_context.get_tree( |
| 49 |
root=new_tab["context"], max_depth=0 |
| 50 |
) |
| 51 |
|
| 52 |
assert contexts[0]["url"].startswith("http://") |