Merge ~jslarraz/qa-regression-testing:add_test_iperf3 into qa-regression-testing:master

Proposed by Jorge Sancho Larraz
Status: Merged
Merged at revision: 42d9f05032637862fc4d825fb6c07006665ef9ca
Proposed branch: ~jslarraz/qa-regression-testing:add_test_iperf3
Merge into: qa-regression-testing:master
Diff against target: 133 lines (+111/-0)
2 files modified
.launchpad.yaml (+14/-0)
scripts/test-iperf3.py (+97/-0)
Reviewer Review Type Date Requested Status
Steve Beattie Approve
Alex Murray Approve
Review via email: mp+453895@code.launchpad.net

Commit message

Add test-iperf3.py

Description of the change

Create new tests for iperf3 package

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM but it would be good to add this to .launchpad.yaml so that it gets run by lpci automatically as well against each of the stable releases.

review: Approve
Revision history for this message
Steve Beattie (sbeattie) wrote :

This is great, thanks fo rgetting the infrastrucutre in place to make this test workable and preparing these test. It's fine to merge as is, but a couple of minor comments inline.

And adding it to the .launchpad.yaml would be appreciated, peek at the history for the file for examples, and https://git.launchpad.net/qa-regression-testing/tree/scripts/README.md#n144 also covers a bit of documentation as well as how to handle cases that can't be run in lpci. (That said, please help clarify the documentation.)

THanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.launchpad.yaml b/.launchpad.yaml
2index 7b32321..bd3e3a3 100644
3--- a/.launchpad.yaml
4+++ b/.launchpad.yaml
5@@ -10,6 +10,7 @@ pipeline:
6 - busybox
7 - coreutils
8 - util-linux
9+ - iperf3
10
11 jobs:
12 imagemagick:
13@@ -141,3 +142,16 @@ jobs:
14 - sudo
15 run: |
16 ./lpcraft-runner util-linux
17+
18+ iperf3:
19+ matrix:
20+ - series: jammy
21+ architectures: amd64
22+ - series: focal
23+ architectures: amd64
24+ - series: bionic
25+ architectures: amd64
26+ packages:
27+ - sudo
28+ run: |
29+ ./lpcraft-runner iperf3
30diff --git a/scripts/test-iperf3.py b/scripts/test-iperf3.py
31new file mode 100755
32index 0000000..a70c169
33--- /dev/null
34+++ b/scripts/test-iperf3.py
35@@ -0,0 +1,97 @@
36+#!/usr/bin/python3
37+#
38+# test-iperf3.py quality assurance test script for iperf3
39+# Copyright (C) 2008-2023 Canonical Ltd.
40+# Author: Jorge Sancho <jorge.sancho.larraz@canonical.com>
41+#
42+# This program is free software: you can redistribute it and/or modify
43+# it under the terms of the GNU General Public License version 3,
44+# as published by the Free Software Foundation.
45+#
46+# This program is distributed in the hope that it will be useful,
47+# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+# GNU General Public License for more details.
50+#
51+# You should have received a copy of the GNU General Public License
52+# along with this program. If not, see <http://www.gnu.org/licenses/>.
53+#
54+# QRT-Packages: iperf3
55+# QRT-Privilege: none
56+# QRT-Conflicts: none
57+
58+'''
59+ In general, this test should be run in a virtual machine (VM) or possibly
60+ a chroot and not on a production machine. While efforts are made to make
61+ these tests non-destructive, there is no guarantee this script will not
62+ alter the machine. You have been warned.
63+
64+ How to run in a clean VM:
65+ $ sudo apt-get -y install <QRT-Packages> && sudo ./test-iperf3.py -v'
66+'''
67+
68+import unittest
69+import time
70+import subprocess
71+import socket
72+import testlib
73+
74+class iperfTest(testlib.TestlibCase):
75+ '''Test iperf.'''
76+
77+ def setUp(self):
78+ '''Set up prior to each test_* function'''
79+ self.server = subprocess.Popen(["iperf3", "-s"])
80+ time.sleep(1)
81+
82+ def tearDown(self):
83+ '''Clean up after each test_* function'''
84+ self.server.terminate()
85+ self.server.wait()
86+
87+ def test_client(self):
88+ # Check server can handle several consecutive requests
89+ for i in range(5):
90+ self.assertShellExitSuccess(["iperf3", "-c", "localhost"], timeout=90,
91+ msg="The client process returned something other than 0. It may indicate "
92+ "that something is not working properly..")
93+
94+ def test_CVE_2023_38403(self):
95+ '''Test CVE-2023-38403'''
96+
97+ # Run PoC
98+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
99+ sock.connect(("localhost", 5201))
100+ sock.sendall(bytearray.fromhex('41'*37+'ff'*4+'41'*50))
101+ sock.close()
102+ time.sleep(1)
103+
104+ # Check server is alive
105+ self.assertEqual(self.server.poll(), None, "Server is not running anymore. This behaviour is typically "
106+ " observed after exploting CVE-2023-38403")
107+
108+ # Check client returned sucessfully
109+ self.assertShellExitSuccess(["iperf3", "-c", "localhost"], timeout=90,
110+ msg="The client process returned something other than 0. It may indicate "
111+ "that something is not working properly..")
112+
113+ def test_LP_2038654(self):
114+ '''Test LP-2038654'''
115+
116+ # Run PoC
117+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
118+ sock.connect(("localhost", 5201))
119+ sock.sendall(bytearray.fromhex('41'))
120+ # We need to keep the connection alive, so that we don't want to call sock.close() yet
121+ # sock.close()
122+
123+ # Wait for timeout to happen (timeout included in the patch)
124+ time.sleep(11)
125+
126+ # Check client returned sucessfully
127+ self.assertShellExitSuccess(["iperf3", "-c", "localhost"], timeout=90,
128+ msg="The client process returned something other than 0. It may indicate "
129+ "that something is not working properly..")
130+
131+if __name__ == '__main__':
132+ unittest.main()
133\ No newline at end of file

Subscribers

People subscribed via source and target branches