ac3a84
From 0845d4d0f5a37493d3da68624aba1a576382e961 Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Thu, 10 Nov 2022 15:52:57 +0900
ac3a84
Subject: [PATCH] test: add tests for mDNS and LLMNR settings
ac3a84
ac3a84
(cherry picked from commit b77899af0d75ea59c35ba454d869fa759fe7b3a1)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 test/units/testsuite-75.sh | 73 ++++++++++++++++++++++++++++++++++++++
ac3a84
 1 file changed, 73 insertions(+)
ac3a84
ac3a84
diff --git a/test/units/testsuite-75.sh b/test/units/testsuite-75.sh
ac3a84
index 53ceced641..1a656fcdc1 100755
ac3a84
--- a/test/units/testsuite-75.sh
ac3a84
+++ b/test/units/testsuite-75.sh
ac3a84
@@ -55,6 +55,79 @@ echo nameserver 10.0.3.1 10.0.3.2 | "$RESOLVCONF" -a hoge.inet.ipsec.192.168.35
ac3a84
 echo nameserver 10.0.3.3 10.0.3.4 | "$RESOLVCONF" -a hoge.foo.dhcp
ac3a84
 assert_in '10.0.3.1 10.0.3.2' "$(resolvectl dns hoge)"
ac3a84
 assert_in '10.0.3.3 10.0.3.4' "$(resolvectl dns hoge.foo)"
ac3a84
+
ac3a84
+# Tests for mDNS and LLMNR settings
ac3a84
+mkdir -p /run/systemd/resolved.conf.d
ac3a84
+{
ac3a84
+    echo "[Resolve]"
ac3a84
+    echo "MulticastDNS=yes"
ac3a84
+    echo "LLMNR=yes"
ac3a84
+} >/run/systemd/resolved.conf.d/mdns-llmnr.conf
ac3a84
+systemctl restart systemd-resolved.service
ac3a84
+systemctl service-log-level systemd-resolved.service debug
ac3a84
+# make sure networkd is not running.
ac3a84
+systemctl stop systemd-networkd.service
ac3a84
+# defaults to yes (both the global and per-link settings are yes)
ac3a84
+assert_in 'yes' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'yes' "$(resolvectl llmnr hoge)"
ac3a84
+# set per-link setting
ac3a84
+resolvectl mdns hoge yes
ac3a84
+resolvectl llmnr hoge yes
ac3a84
+assert_in 'yes' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'yes' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge resolve
ac3a84
+resolvectl llmnr hoge resolve
ac3a84
+assert_in 'resolve' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'resolve' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge no
ac3a84
+resolvectl llmnr hoge no
ac3a84
+assert_in 'no' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'no' "$(resolvectl llmnr hoge)"
ac3a84
+# downgrade global setting to resolve
ac3a84
+{
ac3a84
+    echo "[Resolve]"
ac3a84
+    echo "MulticastDNS=resolve"
ac3a84
+    echo "LLMNR=resolve"
ac3a84
+} >/run/systemd/resolved.conf.d/mdns-llmnr.conf
ac3a84
+systemctl restart systemd-resolved.service
ac3a84
+systemctl service-log-level systemd-resolved.service debug
ac3a84
+# set per-link setting
ac3a84
+resolvectl mdns hoge yes
ac3a84
+resolvectl llmnr hoge yes
ac3a84
+assert_in 'resolve' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'resolve' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge resolve
ac3a84
+resolvectl llmnr hoge resolve
ac3a84
+assert_in 'resolve' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'resolve' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge no
ac3a84
+resolvectl llmnr hoge no
ac3a84
+assert_in 'no' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'no' "$(resolvectl llmnr hoge)"
ac3a84
+# downgrade global setting to no
ac3a84
+{
ac3a84
+    echo "[Resolve]"
ac3a84
+    echo "MulticastDNS=no"
ac3a84
+    echo "LLMNR=no"
ac3a84
+} >/run/systemd/resolved.conf.d/mdns-llmnr.conf
ac3a84
+systemctl restart systemd-resolved.service
ac3a84
+systemctl service-log-level systemd-resolved.service debug
ac3a84
+# set per-link setting
ac3a84
+resolvectl mdns hoge yes
ac3a84
+resolvectl llmnr hoge yes
ac3a84
+assert_in 'no' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'no' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge resolve
ac3a84
+resolvectl llmnr hoge resolve
ac3a84
+assert_in 'no' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'no' "$(resolvectl llmnr hoge)"
ac3a84
+resolvectl mdns hoge no
ac3a84
+resolvectl llmnr hoge no
ac3a84
+assert_in 'no' "$(resolvectl mdns hoge)"
ac3a84
+assert_in 'no' "$(resolvectl llmnr hoge)"
ac3a84
+
ac3a84
+# Cleanup
ac3a84
+rm -f /run/systemd/resolved.conf.d/mdns-llmnr.conf
ac3a84
 ip link del hoge
ac3a84
 ip link del hoge.foo
ac3a84