# Network pass (S007, WebKit S050): secure DNS through a local stub, the bridge with the VPN off, HTTPS-only (upgrade, the
# certificate warning's "Open anyway", fallback prompt, local addresses stay http), tracking parameter stripping.
# Offline: every name resolves through tests/smoke/net/server.py (*.nacre.test -> 127.0.0.1, the rest NXDOMAIN).
# Never Tor or proxies. Start the server first:
#   python3 tests/smoke/net/server.py &   then   tools/smoke.sh tests/smoke/net-privacy.txt
wait 3
set /vpn/enabled false
set /privacy/doh_custom "http://127.0.0.1:8766/dns-query"
set /privacy/doh "custom"
set /privacy/strip_params true
set /privacy/https_only false
wait 1
status route
expect /vpn "Off"
expect /route "Route { upstream: Direct, doh: \"http://127.0.0.1:8766/dns-query\" }"
# A name only the stub knows: it loads, so the bridge asked secure DNS.
open http://site.nacre.test:8766/
waitfor 20 document.title === "Net test http"
expect /bridge_bytes > 0
# HTTPS-only: the http address is upgraded; the self-signed certificate shows the warning; "Open anyway" opens it.
set /privacy/https_only true
open http://site.nacre.test:8766/
waitfor 20 document.title === "Connection not secure"
shot badcert
locate #allow
wait 0.5
click @
waitfor 20 document.title === "Net test https"
assert location.href === "https://site.nacre.test:8766/"
shot https
# A site with no secure version: the upgrade fails and the tab asks whether to open it over http.
open http://plain.nacre.test:8767/
wait 8
status fallback
shot fallback
expect /active/prompts 1
# "Open anyway" (the prompt bar's main button) opens it over http, and the site stays http this session.
tap 1156 124
waitfor 20 document.title === "Net test http"
assert location.href === "http://plain.nacre.test:8767/"
open http://plain.nacre.test:8767/echo?again
waitfor 20 document.title === "Echo again"
assert location.protocol === "http:"
# Local addresses are never upgraded, and they skip the bridge (S050: through it they ended in "Message was restarted
# too many times" on the bridge's own address).
open http://127.0.0.1:8767/
waitfor 20 document.title === "Net test http"
assert location.protocol === "http:"
open http://localhost:8767/echo?local
waitfor 20 document.title === "Echo local"
assert location.href === "http://localhost:8767/echo?local"
# Tracking parameters: removed, the rest kept, and the page is the clean address.
open http://127.0.0.1:8766/echo?utm_source=news&id=3&fbclid=abc&utm_medium=mail
waitfor 20 document.title === "Echo id=3"
assert location.search === "?id=3"
# The page's own script navigation is stripped too (the browser asks the page whether a frame has that URL first).
js location.href = "http://127.0.0.1:8766/echo?utm_source=a&id=5"
waitfor 20 document.title === "Echo id=5"
# A frame's load stays in its frame (S050: it used to take over the tab with the frame's URL).
open @PAGES@/frames.html
waitfor 20 document.title === "Frames"
wait 3
assert location.href.endsWith("/frames.html")
set /privacy/strip_params false
open http://127.0.0.1:8766/echo?id=4&gclid=x
waitfor 20 document.title === "Echo id=4&gclid=x"
# The stub saw the names, so lookups went through secure DNS.
js fetch("http://127.0.0.1:8766/log").then(r => r.json()).then(l => { window.netlog = l; })
waitfor 5 window.netlog !== undefined
js JSON.stringify(window.netlog.dns)
assert window.netlog.dns.includes("site.nacre.test") && window.netlog.dns.includes("plain.nacre.test")
# The upgraded load reached the server over TLS.
assert window.netlog.tls > 0
# The Images permission (S050: a WebKit content filter): pictures blocked on 127.0.0.1's pages, back once it's reset.
perm 127.0.0.1 images block
wait 3
open http://127.0.0.1:8767/echo?images
waitfor 20 document.title === "Echo images"
js window.pic = new Image(); window.pic.onload = window.pic.onerror = () => { window.picDone = true; }; window.pic.src = "http://img.nacre.test:8766/pixel?images=off"; 1
waitfor 10 window.picDone === true
assert window.pic.naturalWidth === 0
perm 127.0.0.1 images default
wait 3
open http://127.0.0.1:8767/echo?images2
waitfor 20 document.title === "Echo images2"
js window.pic = new Image(); window.pic.onload = window.pic.onerror = () => { window.picDone = true; }; window.pic.src = "http://img.nacre.test:8766/pixel?images=on"; 1
waitfor 10 window.picDone === true
assert window.pic.naturalWidth === 1
status done
quit
