Skip to content

Commit 8d113b1

Browse files
committed
WIP: Fix tests
1 parent 4a26993 commit 8d113b1

6 files changed

Lines changed: 50 additions & 53 deletions

File tree

daemon/qrexec-daemon-common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ int handle_daemon_handshake(int fd)
8484
return -1;
8585
}
8686

87-
if (info.version < QREXEC_PROTOCOL_V3) {
87+
if (info.version < QREXEC_CLIENT_PROTOCOL_VERSION) {
8888
LOG(ERROR, "Incompatible daemon protocol version "
8989
"(daemon %d, client %d)",
90-
info.version, QREXEC_PROTOCOL_VERSION);
90+
info.version, QREXEC_CLIENT_PROTOCOL_VERSION);
9191
return -1;
9292
}
9393

9494
hdr.type = MSG_HELLO;
9595
hdr.len = sizeof(info);
96-
info.version = QREXEC_PROTOCOL_VERSION;
96+
info.version = QREXEC_CLIENT_PROTOCOL_VERSION;
9797

9898
if (!write_all(fd, &hdr, sizeof(hdr))) {
9999
LOG(ERROR, "Failed to send MSG_HELLO hdr to daemon");

daemon/qrexec-daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int handle_agent_hello(libvchan_t *ctrl, const char *domain_name)
268268
* readability */
269269
hdr.type = MSG_HELLO;
270270
hdr.len = sizeof(info);
271-
info.version = QREXEC_PROTOCOL_VERSION;
271+
// info.version = QREXEC_PROTOCOL_VERSION;
272272

273273
if (libvchan_send(ctrl, &hdr, sizeof(hdr)) != sizeof(hdr)) {
274274
LOG(ERROR, "Failed to send HELLO hdr to agent");
@@ -463,7 +463,7 @@ static int send_client_hello(int fd)
463463

464464
hdr.type = MSG_HELLO;
465465
hdr.len = sizeof(info);
466-
info.version = QREXEC_PROTOCOL_VERSION;
466+
info.version = QREXEC_CLIENT_PROTOCOL_VERSION;
467467

468468
if (!write_all(fd, &hdr, sizeof(hdr))) {
469469
LOG(ERROR, "Failed to send MSG_HELLO hdr to client %d", fd);

libqrexec/qrexec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdint.h>
3131

3232
#define QREXEC_PROTOCOL_VERSION 4
33+
#define QREXEC_CLIENT_PROTOCOL_VERSION 3
3334
#define MAX_FDS 256
3435
/* protocol version 2 */
3536
#define MAX_DATA_CHUNK_V2 4096

qrexec/tests/socket/agent.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,24 @@
1616
#
1717
# You should have received a copy of the GNU Lesser General Public License along
1818
# with this program; if not, see <http://www.gnu.org/licenses/>.
19-
import sys
20-
import unittest
21-
import subprocess
22-
import os.path
23-
import os
24-
import tempfile
25-
import socket
26-
import shutil
27-
import struct
2819
import getpass
2920
import itertools
30-
import asyncio
21+
import os
22+
import os.path
3123
import shlex
24+
import shutil
25+
import socket
26+
import struct
27+
import subprocess
28+
import sys
29+
import tempfile
30+
import unittest
3231

3332
import psutil
34-
import pytest
3533

3634
from . import qrexec
3735
from . import util
3836

39-
4037
ROOT_PATH = os.path.abspath(
4138
os.path.join(os.path.dirname(__file__), "..", "..", "..")
4239
)
@@ -48,6 +45,7 @@ class TestAgentBase(unittest.TestCase):
4845
domain = 42
4946
target_domain = 43
5047
target_port = 1024
48+
protocol_version = 4
5149

5250
def check_dom0(self, dom0):
5351
self.assertEqual(
@@ -162,7 +160,7 @@ def connect_dom0(self):
162160
self.tempdir, self.domain, 0, 512
163161
)
164162
self.addCleanup(dom0.close)
165-
dom0.handshake()
163+
dom0.handshake(self.protocol_version)
166164
return dom0
167165

168166
def connect_target(self):
@@ -171,6 +169,7 @@ def connect_target(self):
171169
)
172170
self.addCleanup(target.close)
173171
target.accept()
172+
target.handshake(self.protocol_version)
174173
return target
175174

176175
def connect_client(self):
@@ -181,11 +180,10 @@ def connect_client(self):
181180

182181
@unittest.skipIf(os.environ.get("SKIP_SOCKET_TESTS"), "socket tests not set up")
183182
class TestAgent(TestAgentBase):
183+
184184
def test_handshake(self):
185185
self.start_agent()
186186

187-
dom0 = self.connect_dom0()
188-
189187
def _test_just_exec(self, cmd):
190188
self.start_agent()
191189

@@ -203,7 +201,6 @@ def _test_just_exec(self, cmd):
203201
)
204202

205203
target = self.connect_target()
206-
target.handshake()
207204
return target, dom0
208205

209206
def test_001_just_exec_socket(self):
@@ -288,8 +285,6 @@ def test_exec_cmdline(self):
288285
)
289286

290287
target = self.connect_target()
291-
target.handshake()
292-
293288
target.send_message(qrexec.MSG_DATA_STDIN, b"")
294289

295290
self.assertExpectedStdout(target, b"Hello world\n")
@@ -393,7 +388,6 @@ def execute_qubesrpc(self, service: str, src_domain_name: str):
393388
)
394389

395390
target = self.connect_target()
396-
target.handshake()
397391
return target, dom0
398392

399393
def test_exec_symlink(self):
@@ -1190,7 +1184,6 @@ def execute(self, cmd: str):
11901184
)
11911185

11921186
target = self.connect_target()
1193-
target.handshake()
11941187
return target, dom0
11951188

11961189
def test_stdin_stderr(self):
@@ -1375,6 +1368,7 @@ class TestClientVm(unittest.TestCase):
13751368
target_domain_name = "target_domain"
13761369
target_domain = 43
13771370
target_port = 1024
1371+
protocol_version = 4
13781372

13791373
def assertStdoutMessages(
13801374
self, target, expected_stdout: bytes, ty=qrexec.MSG_DATA_STDOUT
@@ -1436,6 +1430,7 @@ def connect_target_client(self):
14361430
self.tempdir, self.domain, self.target_domain, self.target_port
14371431
)
14381432
self.addCleanup(target_client.close)
1433+
target_client.handshake(self.protocol_version)
14391434
return target_client
14401435

14411436
def run_service(
@@ -1475,7 +1470,6 @@ def run_service(
14751470
server.sendall(struct.pack("<LL", self.target_domain, self.target_port))
14761471

14771472
target_client = self.connect_target_client()
1478-
target_client.handshake()
14791473

14801474
return target_client
14811475

qrexec/tests/socket/daemon.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ def connect_client(self):
162162

163163
def test_handshake(self):
164164
agent = self.start_daemon_with_agent()
165-
agent.handshake()
165+
agent.handshake(protocol_version=4)
166166

167167
def test_trigger_service_refused(self):
168168
agent = self.start_daemon_with_agent()
169-
agent.handshake()
169+
agent.handshake(protocol_version=4)
170170

171171
target_domain_name = "target_domain"
172172
ident = "SOCKET42"
@@ -179,7 +179,7 @@ def test_trigger_service_refused(self):
179179

180180
def test_bad_request_id_1(self):
181181
agent = self.start_daemon_with_agent()
182-
agent.handshake()
182+
agent.handshake(protocol_version=4)
183183

184184
target_domain_name = "target_domain"
185185
ident = "\1\2\3"
@@ -193,7 +193,7 @@ def test_bad_request_id_1(self):
193193

194194
def test_bad_request_id_empty(self):
195195
agent = self.start_daemon_with_agent()
196-
agent.handshake()
196+
agent.handshake(protocol_version=4)
197197

198198
target_domain_name = "target_domain"
199199
ident = ""
@@ -207,7 +207,7 @@ def test_bad_request_id_empty(self):
207207

208208
def test_bad_request_id_bad_byte_after_nul_terminator(self):
209209
agent = self.start_daemon_with_agent()
210-
agent.handshake()
210+
agent.handshake(protocol_version=4)
211211

212212
target_domain_name = "target_domain"
213213
ident = "a\0b"
@@ -229,7 +229,7 @@ def test_bad_old_style_request(self):
229229
message_type, data = agent.recv_message()
230230
self.assertEqual(message_type, qrexec.MSG_HELLO)
231231
(ver,) = struct.unpack("<L", data)
232-
self.assertEqual(ver, 4)
232+
self.assertEqual(ver, 2)
233233

234234
target_domain_name = "target_domain"
235235
ident = b"ab"
@@ -262,7 +262,7 @@ def test_bad_new_style_request(self):
262262
Test that qrexec-daemon rejects various invalid requests.
263263
"""
264264
agent = self.start_daemon_with_agent()
265-
agent.handshake()
265+
agent.handshake(protocol_version=4)
266266

267267
target_domain_name = "target_domain"
268268
ident = "ab"
@@ -305,7 +305,7 @@ def test_new_style_request(self):
305305
Test that qrexec-daemon accepts request.
306306
"""
307307
agent = self.start_daemon_with_agent()
308-
agent.handshake()
308+
agent.handshake(protocol_version=4)
309309

310310
ident = "ab"
311311

@@ -374,7 +374,7 @@ def test_qsb_089(self):
374374
Test that qrexec-daemon doesn't corrupt memory on empty request
375375
"""
376376
agent = self.start_daemon_with_agent()
377-
agent.handshake()
377+
agent.handshake(protocol_version=4)
378378

379379
target_domain_name = "target_domain"
380380
ident = "ab"
@@ -432,14 +432,14 @@ def trigger_service(
432432

433433
def test_client_handshake(self):
434434
agent = self.start_daemon_with_agent()
435-
agent.handshake()
435+
agent.handshake(protocol_version=4)
436436

437437
client = self.connect_client()
438438
client.handshake()
439439

440440
def test_restart_agent(self):
441441
agent = self.start_daemon_with_agent()
442-
agent.handshake()
442+
agent.handshake(protocol_version=4)
443443

444444
agent.close()
445445

@@ -452,15 +452,15 @@ def test_restart_agent(self):
452452

453453
agent = self.connect_agent()
454454
agent.accept()
455-
agent.handshake()
455+
agent.handshake(protocol_version=4)
456456

457457
# Now, new client should be able to connect
458458
client = self.connect_client()
459459
client.handshake()
460460

461461
def test_terminate_before_restart(self):
462462
agent = self.start_daemon_with_agent()
463-
agent.handshake()
463+
agent.handshake(protocol_version=4)
464464

465465
agent.close()
466466

@@ -475,7 +475,7 @@ def test_terminate_before_restart(self):
475475

476476
def test_client_exec(self):
477477
agent = self.start_daemon_with_agent()
478-
agent.handshake()
478+
agent.handshake(protocol_version=4)
479479

480480
cmd = "user:echo Hello world"
481481
port = self.client_exec(0, cmd, qrexec.MSG_JUST_EXEC)
@@ -508,7 +508,7 @@ def client_exec(
508508

509509
def test_client_exec_allocates_next_port(self):
510510
agent = self.start_daemon_with_agent()
511-
agent.handshake()
511+
agent.handshake(protocol_version=4)
512512

513513
domain1 = self.domain + 1
514514
domain2 = self.domain + 2
@@ -519,7 +519,7 @@ def test_client_exec_allocates_next_port(self):
519519

520520
def test_client_exec_connection_terminated(self):
521521
agent = self.start_daemon_with_agent()
522-
agent.handshake()
522+
agent.handshake(protocol_version=4)
523523

524524
domain1 = self.domain + 1
525525
domain2 = self.domain + 2
@@ -537,7 +537,7 @@ def test_client_exec_connection_terminated(self):
537537

538538
def test_client_service_connect(self):
539539
agent = self.start_daemon_with_agent()
540-
agent.handshake()
540+
agent.handshake(protocol_version=4)
541541

542542
target_domain = self.domain + 1
543543
target_domain_name = "target_domain"
@@ -571,7 +571,7 @@ def test_client_service_connect(self):
571571

572572
def test_client_service_connect_unexpected(self):
573573
agent = self.start_daemon_with_agent()
574-
agent.handshake()
574+
agent.handshake(protocol_version=4)
575575

576576
client = self.connect_client()
577577
client.handshake()
@@ -595,7 +595,7 @@ def test_client_service_connect_unexpected(self):
595595

596596
def test_client_service_connect_double(self):
597597
agent = self.start_daemon_with_agent()
598-
agent.handshake()
598+
agent.handshake(protocol_version=4)
599599

600600
target_domain = self.domain + 1
601601
target_domain_name = "target_domain"
@@ -750,7 +750,7 @@ def test_run_vm_command_from_dom0(self):
750750
)
751751

752752
target = self.connect_target(target_domain, target_port)
753-
target.handshake()
753+
target.handshake(protocol_version=4)
754754

755755
# select_loop
756756
target.send_message(qrexec.MSG_DATA_STDOUT, b"stdout data\n")
@@ -790,7 +790,7 @@ def test_run_vm_command_from_dom0_reject_stdin(self):
790790
)
791791

792792
target = self.connect_target(target_domain, target_port)
793-
target.handshake()
793+
target.handshake(protocol_version=4)
794794

795795
self.client.send_signal(signal.SIGSTOP)
796796

@@ -850,7 +850,7 @@ def test_run_vm_command_from_dom0_with_local_command(self):
850850
)
851851

852852
target = self.connect_target(target_domain, target_port)
853-
target.handshake()
853+
target.handshake(protocol_version=4)
854854

855855
# select_loop
856856
target.send_message(qrexec.MSG_DATA_STDOUT, b"stdout data\n")
@@ -957,7 +957,7 @@ def connect_service_request(self, cmd, timeout=None):
957957
)
958958

959959
source.accept()
960-
source.handshake()
960+
source.handshake(protocol_version=4)
961961
self.assertEqual(source.recv_message(), (qrexec.MSG_DATA_STDERR, b""))
962962
return source
963963

0 commit comments

Comments
 (0)