Exemplo n.º 1
0
 def test_001_qubesd_call_arg_payload(self, mock_socket):
     mock_config = {
         'return_value.makefile.return_value.read.return_value':
         b'0\x00data'
     }
     mock_socket.configure_mock(**mock_config)
     result = qubespolicy.qubesd_call('test', 'internal.method', 'arg',
                                      b'payload')
     self.assertEqual(result, b'data')
     self.assertEqual(mock_socket.mock_calls, [
         unittest.mock.call(socket.AF_UNIX, socket.SOCK_STREAM),
         unittest.mock.call().connect(qubespolicy.QUBESD_INTERNAL_SOCK),
         unittest.mock.call().sendall(b'dom0'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'internal.method'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'test'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'arg'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'payload'),
         unittest.mock.call().shutdown(socket.SHUT_WR),
         unittest.mock.call().makefile('rb'),
         unittest.mock.call().makefile().read(),
     ])
Exemplo n.º 2
0
 def test_002_qubesd_call_exception(self, mock_socket):
     mock_config = {
         'return_value.makefile.return_value.read.return_value':
         b'2\x00SomeError\x00traceback\x00message\x00'
     }
     mock_socket.configure_mock(**mock_config)
     with self.assertRaises(qubespolicy.QubesMgmtException) as e:
         qubespolicy.qubesd_call('test', 'internal.method')
     self.assertEqual(e.exception.exc_type, 'SomeError')
     self.assertEqual(mock_socket.mock_calls, [
         unittest.mock.call(socket.AF_UNIX, socket.SOCK_STREAM),
         unittest.mock.call().connect(qubespolicy.QUBESD_INTERNAL_SOCK),
         unittest.mock.call().sendall(b'dom0'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'internal.method'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'test'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().shutdown(socket.SHUT_WR),
         unittest.mock.call().makefile('rb'),
         unittest.mock.call().makefile().read(),
     ])
Exemplo n.º 3
0
 def test_002_qubesd_call_exception(self, mock_socket):
     mock_config = {
         'return_value.makefile.return_value.read.return_value':
             b'2\x00SomeError\x00traceback\x00message\x00'
     }
     mock_socket.configure_mock(**mock_config)
     with self.assertRaises(qubespolicy.QubesMgmtException) as e:
         qubespolicy.qubesd_call('test', 'internal.method')
     self.assertEqual(e.exception.exc_type, 'SomeError')
     self.assertEqual(mock_socket.mock_calls, [
         unittest.mock.call(socket.AF_UNIX, socket.SOCK_STREAM),
         unittest.mock.call().connect(qubespolicy.QUBESD_INTERNAL_SOCK),
         unittest.mock.call().sendall(b'dom0'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'internal.method'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'test'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().shutdown(socket.SHUT_WR),
         unittest.mock.call().makefile('rb'),
         unittest.mock.call().makefile().read(),
     ])
Exemplo n.º 4
0
 def test_000_qubesd_call(self, mock_socket):
     mock_config = {
         'return_value.makefile.return_value.read.return_value': b'0\x00data'
     }
     mock_socket.configure_mock(**mock_config)
     result = qubespolicy.qubesd_call('test', 'internal.method')
     self.assertEqual(result, b'data')
     self.assertEqual(mock_socket.mock_calls, [
         unittest.mock.call(socket.AF_UNIX, socket.SOCK_STREAM),
         unittest.mock.call().connect(qubespolicy.QUBESD_INTERNAL_SOCK),
         unittest.mock.call().sendall(b'dom0'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'internal.method'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'test'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().sendall(b'\x00'),
         unittest.mock.call().shutdown(socket.SHUT_WR),
         unittest.mock.call().makefile('rb'),
         unittest.mock.call().makefile().read(),
     ])