]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: test wireguard peer in drop-in config
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 07:39:58 +0000 (16:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 12:33:36 +0000 (21:33 +0900)
Closes #18241.

test/test-network/conf/25-wireguard.netdev
test/test-network/conf/25-wireguard.netdev.d/peer1.conf [new file with mode: 0644]
test/test-network/conf/25-wireguard.netdev.d/peer2.conf [new file with mode: 0644]
test/test-network/conf/25-wireguard.netdev.d/private-key.conf [new file with mode: 0644]
test/test-network/conf/25-wireguard.network
test/test-network/systemd-networkd-tests.py

index 4866c31ccac68b39837e86561e613631e634d4bd..a95ae205d71a53069f8c4114ecf2b8900970f733 100644 (file)
@@ -3,7 +3,6 @@ Name=wg99
 Kind=wireguard
 
 [WireGuard]
-PrivateKey=EEGlnEPYJV//kbvvIqxKkQwOiS+UENyPncC4bF46ong=
 ListenPort=51820
 FwMark=1234
 
diff --git a/test/test-network/conf/25-wireguard.netdev.d/peer1.conf b/test/test-network/conf/25-wireguard.netdev.d/peer1.conf
new file mode 100644 (file)
index 0000000..47848fc
--- /dev/null
@@ -0,0 +1,5 @@
+[WireGuardPeer]
+PublicKey=TTiCUpCxS7zDn/ax4p5W6Evg41r8hOrnWQw2Sq6Nh10=
+PresharedKey=it7nd33chCT/tKT2ZZWfYyp43Zs+6oif72hexnSNMqA=
+
+AllowedIPs=192.168.124.2
diff --git a/test/test-network/conf/25-wireguard.netdev.d/peer2.conf b/test/test-network/conf/25-wireguard.netdev.d/peer2.conf
new file mode 100644 (file)
index 0000000..bf99a5a
--- /dev/null
@@ -0,0 +1,5 @@
+[WireGuardPeer]
+PublicKey=9uioxkGzjvGjkse3V35I9AhorWfIjBcrf3UPMS0bw2c=
+PresharedKey=6Fsg8XN0DE6aPQgAX4r2oazEYJOGqyHUz3QRH/jCB+I=
+
+AllowedIPs=192.168.124.3
diff --git a/test/test-network/conf/25-wireguard.netdev.d/private-key.conf b/test/test-network/conf/25-wireguard.netdev.d/private-key.conf
new file mode 100644 (file)
index 0000000..9b04cf7
--- /dev/null
@@ -0,0 +1,2 @@
+[WireGuard]
+PrivateKey=EEGlnEPYJV//kbvvIqxKkQwOiS+UENyPncC4bF46ong=
index ab305239151d327503658fb45fb878eef82012b6..163a56ff2944eba998f3cd9a9bbe02fc2b7f232e 100644 (file)
@@ -1,2 +1,5 @@
 [Match]
 Name=wg99
+
+[Network]
+Address=192.168.124.1/24
index 38480e1ce58923727404ca584bccea29dc56513b..2effa42e16dc1744ab789ee3433671ceb2a4306b 100755 (executable)
@@ -1218,7 +1218,11 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt',
                                         '25-wireguard-no-peer.netdev', '25-wireguard-no-peer.network')
         start_networkd()
-        self.wait_online(['wg99:carrier', 'wg98:routable', 'wg97:carrier'])
+        self.wait_online(['wg99:routable', 'wg98:routable', 'wg97:carrier'])
+
+        output = check_output('ip -4 address show dev wg99')
+        print(output)
+        self.assertIn('inet 192.168.124.1/24 scope global wg99', output)
 
         output = check_output('ip -4 address show dev wg98')
         print(output)
@@ -1232,29 +1236,39 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
             call('wg')
 
             output = check_output('wg show wg99 listen-port')
-            self.assertRegex(output, '51820')
+            self.assertEqual(output, '51820')
             output = check_output('wg show wg99 fwmark')
-            self.assertRegex(output, '0x4d2')
+            self.assertEqual(output, '0x4d2')
+            output = check_output('wg show wg99 private-key')
+            self.assertEqual(output, 'EEGlnEPYJV//kbvvIqxKkQwOiS+UENyPncC4bF46ong=')
             output = check_output('wg show wg99 allowed-ips')
-            self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
-            self.assertRegex(output, r'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128')
+            self.assertIn('9uioxkGzjvGjkse3V35I9AhorWfIjBcrf3UPMS0bw2c=\t192.168.124.3/32', output)
+            self.assertIn('TTiCUpCxS7zDn/ax4p5W6Evg41r8hOrnWQw2Sq6Nh10=\t192.168.124.2/32', output)
+            self.assertIn('lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128', output)
+            self.assertIn('RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48', output)
             output = check_output('wg show wg99 persistent-keepalive')
-            self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t20')
+            self.assertIn('9uioxkGzjvGjkse3V35I9AhorWfIjBcrf3UPMS0bw2c=\toff', output)
+            self.assertIn('TTiCUpCxS7zDn/ax4p5W6Evg41r8hOrnWQw2Sq6Nh10=\toff', output)
+            self.assertIn('lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\toff', output)
+            self.assertIn('RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t20', output)
             output = check_output('wg show wg99 endpoints')
-            self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.27.3:51820')
-            output = check_output('wg show wg99 private-key')
-            self.assertRegex(output, r'EEGlnEPYJV//kbvvIqxKkQwOiS\+UENyPncC4bF46ong=')
+            self.assertIn('9uioxkGzjvGjkse3V35I9AhorWfIjBcrf3UPMS0bw2c=\t(none)', output)
+            self.assertIn('TTiCUpCxS7zDn/ax4p5W6Evg41r8hOrnWQw2Sq6Nh10=\t(none)', output)
+            self.assertIn('lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\t(none)', output)
+            self.assertIn('RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.27.3:51820', output)
             output = check_output('wg show wg99 preshared-keys')
-            self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=')
-            self.assertRegex(output, r'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=    cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=')
+            self.assertIn('9uioxkGzjvGjkse3V35I9AhorWfIjBcrf3UPMS0bw2c=\t6Fsg8XN0DE6aPQgAX4r2oazEYJOGqyHUz3QRH/jCB+I=', output)
+            self.assertIn('TTiCUpCxS7zDn/ax4p5W6Evg41r8hOrnWQw2Sq6Nh10=\tit7nd33chCT/tKT2ZZWfYyp43Zs+6oif72hexnSNMqA=', output)
+            self.assertIn('lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tcPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=', output)
+            self.assertIn('RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\tIIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=', output)
 
             output = check_output('wg show wg98 private-key')
-            self.assertRegex(output, r'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr\+WHtZLZ90FU=')
+            self.assertEqual(output, 'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr+WHtZLZ90FU=')
 
             output = check_output('wg show wg97 listen-port')
-            self.assertRegex(output, '51821')
+            self.assertEqual(output, '51821')
             output = check_output('wg show wg97 fwmark')
-            self.assertRegex(output, '0x4d3')
+            self.assertEqual(output, '0x4d3')
 
     def test_geneve(self):
         copy_unit_to_networkd_unit_path('25-geneve.netdev', 'netdev-link-local-addressing-yes.network')