File: https_upgrade.py

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (49 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from urllib.parse import urlunsplit

import pytest
from tests.support.asserts import assert_error


def navigate_to(session, url):
    return session.transport.send(
        "POST", "session/{session_id}/url".format(**vars(session)), {"url": url}
    )


@pytest.fixture
def http_with_https_port_url(server_config):
    """
    Creates an HTTP URL with a port for HTTPS that would trigger a HTTPS-First
    upgrade when entered in the url bar.
    """

    def _http_with_https_port_url(path, query="", fragment=""):
        domain = server_config["domains"][""][""]
        port = server_config["ports"]["https"][0]
        return urlunsplit(("http", f"{domain}:{port}", path, query, fragment))

    return _http_with_https_port_url


@pytest.mark.capabilities(
    {
        "pageLoadStrategy": "eager",
        "moz:firefoxOptions": {
            "prefs": {
                # Allow HTTPS upgrades for localhost and custom ports
                "dom.security.https_first_for_custom_ports": True,
                "dom.security.https_first_for_local_addresses": True,
                "dom.security.https_first_for_unknown_suffixes": True,
            },
        },
    }
)
def test_no_https_first_upgrade(session, http_with_https_port_url):
    page = http_with_https_port_url("/webdriver/tests/support/html/default.html")

    # A navigation via the WebDriver API should not cause an HTTPS upgrade,
    # so it fails with a neterror page.
    response = navigate_to(session, page)
    assert_error(response, "unknown error")

    assert session.url.startswith("http://")