-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tcp_malformed_queries.py
101 lines (73 loc) · 3.09 KB
/
test_tcp_malformed_queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
def missing_expression(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE\nBYE\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def missing_solve(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\n(+ 1 2)\nBYE\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def too_short_expression(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE (+ 1)\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def too_short_expression2(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE (+)\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def empty_expression(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE ()\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def empty_expression2(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE ( )\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def missing_left_bracket(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE + 1 2)\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def missing_right_bracket(server_tcp, ipkcpc_tcp):
outs, errors = ipkcpc_tcp.communicate(input=b"HELLO\nSOLVE (+ 1 2\n", timeout=3)
return ipkcpc_tcp.returncode, outs, errors
def test_missing_expression(server_tcp, ipkcpc_tcp):
ret, outs, errors = missing_expression(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""
def test_missing_solve(server_tcp, ipkcpc_tcp):
ret, outs, errors = missing_solve(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""
def test_too_short_expression(server_tcp, ipkcpc_tcp):
ret, outs, errors = too_short_expression(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""
def test_too_short_expression2(server_tcp, ipkcpc_tcp):
ret, outs, errors = too_short_expression2(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""
def test_missing_left_bracket(server_tcp, ipkcpc_tcp):
ret, outs, errors = missing_left_bracket(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""
def test_missing_right_bracket(server_tcp, ipkcpc_tcp):
ret, outs, errors = missing_right_bracket(server_tcp, ipkcpc_tcp)
assert ret == 1
if os.name == "nt":
assert outs == b"HELLO\r\nBYE\r\n"
else:
assert outs == b"HELLO\nBYE\n"
assert errors != b""