Fix Wi-Fi QR fallback after failed route lookup

This commit is contained in:
David Heinemeier Hansson committed 2026-09-21 10:54:38 +02:00
1 parent 5b22f50be3
commit 5c2be2e653
2 files changed
+11 -1

No files matched your search

+3 -1
View File
@@ -22,7 +22,9 @@ if [[ -z $interface ]]; then
# menu's visibility gate describe. Fall back to the first connected Wi-Fi
# device. nmcli localizes state names, so pin the locale, and the prefix
# match accepts states like "connected (externally)".
route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }')
if ! route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }'); then
route_device=""
fi
if [[ -n $route_device && -d /sys/class/net/$route_device/wireless ]]; then
interface=$route_device
else
+8
View File
@@ -7,10 +7,12 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/bin"
export QR_ROUTE_EXIT=0
# Loopback is never wireless, so exercise the connected-Wi-Fi fallback.
cat >"$tmp/bin/ip" <<'EOF'
#!/bin/bash
[[ $QR_ROUTE_EXIT == "0" ]] || exit "$QR_ROUTE_EXIT"
printf '1.1.1.1 dev lo\n'
EOF
@@ -93,6 +95,12 @@ run_success_case \
'WIFI:T:WPA;S:Cafe Detected;P:secret;;' \
--meta
QR_ROUTE_EXIT=2 run_success_case \
"network QR helper detects Wi-Fi when route lookup fails" \
$'Cafe No Route\nwpa-psk\nsecret\nno\n' \
'WIFI:T:WPA;S:Cafe No Route;P:secret;;' \
--meta
run_success_case \
"network QR helper supports open networks" \
$'Cafe Open\nnone\n\nno\n' \