tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

allow_origins.py (1864B)


      1 from copy import deepcopy
      2 
      3 import pytest
      4 from support.network import http_request, websocket_request
      5 
      6 pytestmark = pytest.mark.asyncio
      7 
      8 
      9 @pytest.mark.parametrize(
     10    "allow_origins, origin, status",
     11    [
     12        # Valid origins
     13        (["http://web-platform.test"], "http://web-platform.test", 200),
     14        (["http://web-platform.test"], "http://web-platform.test:80", 200),
     15        (["https://web-platform.test"], "https://web-platform.test:443", 200),
     16        # Invalid origins
     17        (["https://web-platform.test"], "http://web-platform.test", 500),
     18        (["http://web-platform.test:8000"], "http://web-platform.test", 500),
     19        (["http://web-platform.test"], "http://www.web-platform.test", 500),
     20    ],
     21 )
     22 def test_allow_hosts(configuration, geckodriver, allow_origins, origin, status):
     23    extra_args = ["--allow-origins"] + allow_origins
     24 
     25    driver = geckodriver(extra_args=extra_args)
     26    response = http_request(driver.hostname, driver.port, origin=origin)
     27 
     28    assert response.status == status
     29 
     30 
     31 @pytest.mark.parametrize(
     32    "allow_origins, origin, status",
     33    [
     34        (
     35            ["https://web-platform.test", "http://web-platform.test"],
     36            "http://web-platform.test",
     37            101,
     38        ),
     39        (["https://web-platform.test"], "http://web-platform.test", 400),
     40    ],
     41    ids=["allowed", "not allowed"],
     42 )
     43 async def test_allow_origins_passed_to_remote_agent(
     44    configuration, geckodriver, allow_origins, origin, status
     45 ):
     46    config = deepcopy(configuration)
     47    config["capabilities"]["webSocketUrl"] = True
     48 
     49    extra_args = ["--allow-origins"] + allow_origins
     50 
     51    driver = geckodriver(config=config, extra_args=extra_args)
     52 
     53    driver.new_session()
     54 
     55    response = websocket_request("127.0.0.1", driver.remote_agent_port, origin=origin)
     56    assert response.status == status
     57 
     58    await driver.delete_session()