# Network pass (S007): 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.
open http://127.0.0.1:8767/
waitfor 20 document.title === "Net test http"
assert location.protocol === "http:"
# 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"
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")
status done
quit
