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
|
import unittest
import solter
class TestSolter(unittest.TestCase):
def test_get_commands_send_data(self):
expected = ['call (int)send(3, "Hello World", 11, 0x4000)']
self.assertEqual(solter.get_commands_send_data(sockfd=3, data="Hello World"), expected)
with self.assertRaises(ValueError):
solter.get_commands_send_data(sockfd=3, data='Hello"World')
with self.assertRaises(ValueError):
solter.get_commands_send_data(sockfd=3, data='Hello\nWorld')
def test_get_commands_change_tcp_option(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 137",
"call (int)setsockopt(42, 6, 4, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter._get_commands_change_tcp_option(sockfd=42, value=137, param=4), expected)
def test_get_commands_enable_keepalive(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 1",
"call (int)setsockopt(13, 1, 9, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter.get_commands_enable_keepalive(sockfd=13), expected)
def test_get_commands_disable_keepalive(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 0",
"call (int)setsockopt(14, 1, 9, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter.get_commands_disable_keepalive(sockfd=14), expected)
def test_get_commands_change_keepalive_time(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 60",
"call (int)setsockopt(15, 6, 4, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter.get_commands_change_keepalive_time(sockfd=15, value=60), expected)
def test_get_commands_change_keepalive_count(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 10",
"call (int)setsockopt(16, 6, 6, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter.get_commands_change_keepalive_count(sockfd=16, value=10), expected)
def test_get_commands_change_keepalive_interval(self):
expected = (
"set $rsp -= sizeof(int)",
"set {int}$rsp = 40",
"call (int)setsockopt(17, 6, 5, $rsp, sizeof(int))",
"set $rsp += sizeof(int)",
)
self.assertEqual(solter.get_commands_change_keepalive_intvl(sockfd=17, value=40), expected)
|