Merge pull request #12748 from omacom/simplify/network-qr-test-environment
Fall back to connected Wi-Fi when QR route lookup fails
This commit is contained in:
2 files changed
+21
-6
No files matched your search
@@ -22,7 +22,9 @@ if [[ -z $interface ]]; then
|
|||||||
# menu's visibility gate describe. Fall back to the first connected Wi-Fi
|
# 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
|
# device. nmcli localizes state names, so pin the locale, and the prefix
|
||||||
# match accepts states like "connected (externally)".
|
# 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
|
if [[ -n $route_device && -d /sys/class/net/$route_device/wireless ]]; then
|
||||||
interface=$route_device
|
interface=$route_device
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -7,6 +7,14 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
|||||||
tmp=$(mktemp -d)
|
tmp=$(mktemp -d)
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
mkdir -p "$tmp/bin"
|
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
|
||||||
|
|
||||||
cat >"$tmp/bin/nmcli" <<'EOF'
|
cat >"$tmp/bin/nmcli" <<'EOF'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@@ -28,13 +36,13 @@ payload=$(</dev/stdin)
|
|||||||
printf '%s' "$payload" >"$QR_PAYLOAD_FILE"
|
printf '%s' "$payload" >"$QR_PAYLOAD_FILE"
|
||||||
printf '## \n ## \n ##\n'
|
printf '## \n ## \n ##\n'
|
||||||
EOF
|
EOF
|
||||||
chmod +x "$tmp/bin/nmcli" "$tmp/bin/qrencode"
|
chmod +x "$tmp/bin/ip" "$tmp/bin/nmcli" "$tmp/bin/qrencode"
|
||||||
|
|
||||||
run_success_case() {
|
run_success_case() {
|
||||||
local description=$1 fields=$2 expected_payload=$3
|
local description=$1 fields=$2 expected_payload=$3
|
||||||
shift 3
|
shift 3
|
||||||
local output meta matrix payload arg with_meta=false
|
local output meta matrix payload arg with_meta=false
|
||||||
local expected_matrix expected_security expected_ssid expected_iface="*"
|
local expected_matrix expected_security expected_ssid expected_iface="wlan0"
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
[[ $arg == "--meta" ]] && with_meta=true || expected_iface=$arg
|
[[ $arg == "--meta" ]] && with_meta=true || expected_iface=$arg
|
||||||
@@ -49,9 +57,8 @@ run_success_case() {
|
|||||||
meta=$(head -n1 <<<"$output")
|
meta=$(head -n1 <<<"$output")
|
||||||
matrix=$(tail -n +2 <<<"$output")
|
matrix=$(tail -n +2 <<<"$output")
|
||||||
|
|
||||||
# The meta line leads with the shared interface, security, and SSID. With
|
# The metadata reports the requested interface, or the connected Wi-Fi
|
||||||
# no interface argument the helper detects one from the live host, so that
|
# interface supplied by the nmcli stub when no interface was requested.
|
||||||
# field is only pinned when the case pinned it.
|
|
||||||
expected_security=${expected_payload#WIFI:T:}
|
expected_security=${expected_payload#WIFI:T:}
|
||||||
expected_security=${expected_security%%;*}
|
expected_security=${expected_security%%;*}
|
||||||
expected_ssid=$(head -n1 <<<"$fields")
|
expected_ssid=$(head -n1 <<<"$fields")
|
||||||
@@ -88,6 +95,12 @@ run_success_case \
|
|||||||
'WIFI:T:WPA;S:Cafe Detected;P:secret;;' \
|
'WIFI:T:WPA;S:Cafe Detected;P:secret;;' \
|
||||||
--meta
|
--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 \
|
run_success_case \
|
||||||
"network QR helper supports open networks" \
|
"network QR helper supports open networks" \
|
||||||
$'Cafe Open\nnone\n\nno\n' \
|
$'Cafe Open\nnone\n\nno\n' \
|
||||||
|
|||||||
Reference in new issue
Block a user