From: Nick Rosbrook Date: Tue, 22 Oct 2024 14:06:11 +0000 (-0400) Subject: test: add test for resolved SubscribeDNSConfiguration API X-Git-Tag: v258-rc1~1462^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ee20919a2f2b2168d2fcf92021afe92eb6d8d1d;p=thirdparty%2Fsystemd.git test: add test for resolved SubscribeDNSConfiguration API --- diff --git a/test/units/TEST-75-RESOLVED.sh b/test/units/TEST-75-RESOLVED.sh index 25ab02a9383..431b37a5e52 100755 --- a/test/units/TEST-75-RESOLVED.sh +++ b/test/units/TEST-75-RESOLVED.sh @@ -1007,6 +1007,83 @@ testcase_12_resolvectl2() { restart_resolved } +# Test io.systemd.Resolve.Monitor.SubscribeDNSConfiguration +testcase_13_varlink_subscribe_dns_configuration() { + # Cleanup + # shellcheck disable=SC2317 + cleanup() { + echo "===== io.systemd.Resolve.Monitor.SubscribeDNSConfiguration output: =====" + cat "$tmpfile" + echo "==========" + rm -f /run/systemd/resolved.conf.d/global-dns.conf + restart_resolved + } + + trap cleanup RETURN ERR + + local unit + local tmpfile + + unit="subscribe-dns-configuration-$(systemd-id128 new -u).service" + tmpfile=$(mktemp) + + # Clear global and per-interface DNS before monitoring the configuration change. + mkdir -p /run/systemd/resolved.conf.d/ + { + echo "[Resolve]" + echo "DNS=" + } > /run/systemd/resolved.conf.d/global-dns.conf + systemctl reload systemd-resolved.service + resolvectl dns dns0 "" + resolvectl domain dns0 "" + + # Start the call to io.systemd.Resolve.Monitor.SubscribeDNSConfiguration + systemd-run -u "$unit" -p "Type=exec" -p "StandardOutput=truncate:$tmpfile" \ + varlinkctl call --more --timeout=5 --graceful=io.systemd.TimedOut /run/systemd/resolve/io.systemd.Resolve.Monitor io.systemd.Resolve.Monitor.SubscribeDNSConfiguration '{}' + + # Wait until the initial configuration has been received. + timeout 5 bash -c "until [[ -s $tmpfile ]]; do sleep 0.1; done" + + # Update the global configuration. + mkdir -p /run/systemd/resolved.conf.d/ + { + echo "[Resolve]" + echo "DNS=8.8.8.8" + echo "Domains=lan" + } > /run/systemd/resolved.conf.d/global-dns.conf + systemctl reload systemd-resolved.service + + # Update a link configuration. + resolvectl dns dns0 8.8.4.4 1.1.1.1 + resolvectl domain dns0 ~. + + # Wait for the monitor to exit gracefully. + while systemctl --quiet is-active "$unit"; do + sleep 0.5 + done + + # Hack to remove the "Method call returned expected error" line from the output. + sed -i '/^Method call.*returned expected error/d' "$tmpfile" + + # Check that an initial reply was given with the settings applied BEFORE the monitor started. + grep -qF \ + '{"global":{"servers":null,"domains":null}}' \ + <(jq -cr --seq '.configuration[] | select(.ifname == null) | {"global": {servers: .servers, domains: .searchDomains}}' "$tmpfile") + grep -qF \ + '{"dns0":{"servers":null,"domains":null}}' \ + <(jq -cr --seq '.configuration[] | select(.ifname == "dns0") | {"dns0": {servers: .servers, domains: .searchDomains}}' "$tmpfile") + + # Check that the global configuration change was reflected. + grep -qF \ + '{"global":{"servers":[[8,8,8,8]],"domains":["lan"]}}' \ + <(jq -cr --seq '.configuration[] | select(.ifname == null and .servers != null and .searchDomains != null) | {"global":{servers: [.servers[] | .address], domains: [.searchDomains[] | .name]}}' "$tmpfile") + + # Check that the link configuration change was reflected. + grep -qF \ + '{"dns0":{"servers":[[8,8,4,4],[1,1,1,1]],"domains":["."]}}' \ + <(jq -cr --seq '.configuration[] | select(.ifname == "dns0" and .servers != null and .searchDomains != null) | {"dns0":{servers: [.servers[] | .address], domains: [.searchDomains[] | .name]}}' "$tmpfile") +} + # PRE-SETUP systemctl unmask systemd-resolved.service systemctl enable --now systemd-resolved.service