]> git.ipfire.org Git - pakfire.git/blame - tests/python/jail.py
tests: Re-enable jail tests that pass
[pakfire.git] / tests / python / jail.py
CommitLineData
0b95b06f
MT
1#!/usr/bin/python3
2
d24e232a 3import logging
0b95b06f 4import pakfire
0b95b06f 5
abb05de8
MT
6import tests
7
8class JailTests(tests.TestCase):
0b95b06f
MT
9 """
10 This tests the execute command
11 """
12 def setUp(self):
abb05de8 13 self.pakfire = self.setup_pakfire()
0b95b06f 14
32035a14 15 # XXX Temporarily disabled, because the jail messes up the console
748c5f32
MT
16 def test_execute(self):
17 r = self.pakfire.execute(["/command", "exit-with-code", "0"])
18
19 self.assertIsNone(r)
20
21 def test_return_value(self):
22 with self.assertRaises(pakfire.CommandExecutionError) as e:
23 self.pakfire.execute(["/command", "exit-with-code", "123"])
24
25 # Extract return code
26 code, = e.exception.args
27
28 self.assertTrue(code == 123)
29
30 def test_environ(self):
31 r = self.pakfire.execute(["/command", "echo-environ", "VAR1"],
32 environ={"VAR1" : "VAL1"})
33
34 self.assertIsNone(r)
35
36 def test_invalid_inputs(self):
37 # Arguments
38 with self.assertRaises(TypeError):
39 self.pakfire.execute("/command")
40
41 with self.assertRaises(TypeError):
42 self.pakfire.execute(["/command", 1])
43
44 with self.assertRaises(TypeError):
45 self.pakfire.execute(("/command", "--help"))
46
47 # Environment
48 with self.assertRaises(TypeError):
49 self.pakfire.execute(["/command", "--help"], environ={"VAR1" : 1})
50
51 with self.assertRaises(TypeError):
52 self.pakfire.execute(["/command", "--help"], environ={1 : "VAL1"})
53
54 with self.assertRaises(TypeError):
55 self.pakfire.execute(["/command", "--help"], environ="VAR1=VAL1")
56
57 def test_execute_non_existant_command(self):
58 """
59 Executing non-existant commands should raise an error
60 """
61 with self.assertRaises(pakfire.CommandExecutionError):
62 self.pakfire.execute(["/command-does-not-exist"])
63
64 def test_execute_output(self):
65 self.pakfire.execute(["/command", "echo", "123"])
66
67 # Multiple newlines in one read
68 self.pakfire.execute(["/command", "echo", "1\n2\n3"])
69
70 # Run a command with a lot of output which exceeds the buffer size
71 self.pakfire.execute(["/command", "lines", "1", "65536"])
72
73 # Run a command that generates lots of lines
74 self.pakfire.execute(["/command", "lines", "100", "40"])
75
32035a14
MT
76 #def test_execute_logger(self):
77 # def log(priority, message):
78 # # Priority must be INFO
79 # self.assertEqual(priority, logging.INFO)
80 #
81 # # All lines must be 20 characters long
82 # self.assertEqual(len(message), 20)
83 #
84 # self.pakfire.execute(["/command", "lines", "10", "20"], logging_callback=log)
d5bb2996 85
27f1d9e6
MT
86 # XXX This does not work
87 #def test_execute_logger_exceptions(self):
88 # """
89 # The logger callback will raise an Exception which should be handled
90 # """
91 # def log(priority, message):
92 # raise RuntimeError(message)
93 #
94 # with self.assertRaises(RuntimeError):
95 # self.pakfire.execute(
96 # ["/command", "echo", "Hello World!"],
97 # logging_callback=log,
98 # )
849f2918 99
32035a14
MT
100 #def test_pid(self):
101 # def checkpid(priority, message):
102 # # The PID must be 1
103 # self.assertEqual(message, "1")
104 #
105 # self.pakfire.execute(["/command", "print-pid"], logging_callback=checkpid)
748c5f32
MT
106
107 def test_nice(self):
108 self.pakfire.execute(["/command", "print-nice"], nice=5)
109
110 def test_nice_invalid_input(self):
111 """
112 Tries using an invalid nice value
113 """
114 with self.assertRaises(OSError):
115 self.pakfire.execute(["/command", "print-nice"], nice=100)
116
32035a14
MT
117 #def test_check_open_file_descriptors(self):
118 # """
119 # Since we are spawning child processes, it might happen that we leak file
120 # descriptors to the child process.
121 # """
122 # self.pakfire.execute(["/command", "check-open-file-descriptors"])
748c5f32
MT
123
124 # Signals
125
126 def test_send_signal_DEFAULT(self):
127 """
128 Sends a stupid signal which doesn't do anything
129 """
130 self.pakfire.execute(["/command", "send-signal", "0"])
131
132 def test_send_signal_KILL(self):
133 """
134 Test the process killing itself
135 """
136 self.pakfire.execute(["/command", "send-signal", "9"])
137
138 def test_send_signal_TERM(self):
139 """
140 Test the process terminating itself
141 """
142 self.pakfire.execute(["/command", "send-signal", "15"])
143
0b95b06f
MT
144 # This is an interactive test which cannot be performed automatically
145 #def test_shell(self):
146 # self.pakfire.execute(["/bin/bash", "-i"])
147
148
149if __name__ == "__main__":
abb05de8 150 tests.main()