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
50
51
52
53
54
55
56
|
from copy import deepcopy
import pytest
from support.network import http_request, websocket_request
@pytest.mark.parametrize(
"allow_origins, origin, status",
[
# Valid origins
(["http://web-platform.test"], "http://web-platform.test", 200),
(["http://web-platform.test"], "http://web-platform.test:80", 200),
(["https://web-platform.test"], "https://web-platform.test:443", 200),
# Invalid origins
(["https://web-platform.test"], "http://web-platform.test", 500),
(["http://web-platform.test:8000"], "http://web-platform.test", 500),
(["http://web-platform.test"], "http://www.web-platform.test", 500),
],
)
def test_allow_hosts(configuration, geckodriver, allow_origins, origin, status):
extra_args = ["--allow-origins"] + allow_origins
driver = geckodriver(extra_args=extra_args)
response = http_request(driver.hostname, driver.port, origin=origin)
assert response.status == status
@pytest.mark.parametrize(
"allow_origins, origin, status",
[
(
["https://web-platform.test", "http://web-platform.test"],
"http://web-platform.test",
101,
),
(["https://web-platform.test"], "http://web-platform.test", 400),
],
ids=["allowed", "not allowed"],
)
def test_allow_origins_passed_to_remote_agent(
configuration, geckodriver, allow_origins, origin, status
):
config = deepcopy(configuration)
config["capabilities"]["webSocketUrl"] = True
extra_args = ["--allow-origins"] + allow_origins
driver = geckodriver(config=config, extra_args=extra_args)
driver.new_session()
response = websocket_request("127.0.0.1", driver.remote_agent_port, origin=origin)
assert response.status == status
driver.delete_session()
|