| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 5 |
# You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
import mozunit |
| 8 |
import pytest |
| 9 |
from mozprofile.permissions import Permissions |
| 10 |
|
| 11 |
LOCATIONS = """http://mochi.test:8888 primary,privileged |
| 12 |
http://127.0.0.1:8888 privileged |
| 13 |
""" |
| 14 |
|
| 15 |
|
| 16 |
@pytest.fixture |
| 17 |
def locations_file(tmpdir): |
| 18 |
locations_file = tmpdir.join("locations.txt") |
| 19 |
locations_file.write(LOCATIONS) |
| 20 |
return locations_file.strpath |
| 21 |
|
| 22 |
|
| 23 |
@pytest.fixture |
| 24 |
def perms(tmpdir, locations_file): |
| 25 |
return Permissions(locations_file) |
| 26 |
|
| 27 |
|
| 28 |
def test_nw_prefs(perms): |
| 29 |
prefs, user_prefs = perms.network_prefs(False) |
| 30 |
|
| 31 |
assert len(user_prefs) == 0 |
| 32 |
assert len(prefs) == 0 |
| 33 |
|
| 34 |
prefs, user_prefs = perms.network_prefs({"http": 8888}) |
| 35 |
assert len(user_prefs) == 2 |
| 36 |
assert user_prefs[0] == ("network.proxy.type", 2) |
| 37 |
assert user_prefs[1][0] == "network.proxy.autoconfig_url" |
| 38 |
|
| 39 |
origins_decl = ( |
| 40 |
"var knownOrigins = (function () { return ['http://mochi.test:8888', " |
| 41 |
"'http://127.0.0.1:8888'].reduce" |
| 42 |
) |
| 43 |
assert origins_decl in user_prefs[1][1] |
| 44 |
|
| 45 |
proxy_check = ( |
| 46 |
"'http': 'PROXY mochi.test:8888'", |
| 47 |
"'https': 'PROXY mochi.test:4443'", |
| 48 |
"'ws': 'PROXY mochi.test:9988'", |
| 49 |
"'wss': 'PROXY mochi.test:4443'", |
| 50 |
) |
| 51 |
assert all(c in user_prefs[1][1] for c in proxy_check) |
| 52 |
|
| 53 |
prefs, user_prefs = perms.network_prefs({"dohServerPort": 443}) |
| 54 |
print(user_prefs) |
| 55 |
assert len(user_prefs) == 6 |
| 56 |
assert user_prefs[0] == ("network.proxy.type", 0) |
| 57 |
assert user_prefs[1] == ("network.trr.mode", 3) |
| 58 |
assert user_prefs[2] == ("network.trr.uri", "https://foo.example.com:443/dns-query") |
| 59 |
assert user_prefs[3] == ("network.trr.bootstrapAddr", "127.0.0.1") |
| 60 |
assert user_prefs[4] == ("network.dns.force_use_https_rr", True) |
| 61 |
assert user_prefs[5] == ("network.dns.https_rr.check_record_with_cname", False) |
| 62 |
|
| 63 |
|
| 64 |
if __name__ == "__main__": |
| 65 |
mozunit.main() |