Example #1
0
 def testTlsServerProcess(self):
     ''' test that the synchronous TLS server processes requests '''
     with patch('pymodbus.compat.socketserver.ThreadingTCPServer'
                ) as mock_server:
         with patch.object(ssl.SSLContext,
                           'load_cert_chain') as mock_method:
             server = ModbusTlsServer(None)
             server.process_request('request', 'client')
             self.assertTrue(mock_server.process_request.called)
Example #2
0
 def testTlsServerClose(self):
     ''' test that the synchronous TLS server closes correctly '''
     with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
         identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
         server = ModbusTlsServer(context=None,
                                  identity=identity,
                                  bind_and_activate=False)
         server.threads.append(Mock(**{'running': True}))
         server.server_close()
         self.assertEqual(server.control.Identity.VendorName, 'VendorName')
         self.assertFalse(server.threads[0].running)
Example #3
0
 def testTlsServerInit(self):
     ''' test that the synchronous TLS server intial correctly '''
     with patch.object(socket.socket, 'bind') as mock_socket:
         with patch.object(ssl.SSLContext,
                           'load_cert_chain') as mock_method:
             identity = ModbusDeviceIdentification(
                 info={0x00: 'VendorName'})
             server = ModbusTlsServer(context=None, identity=identity)
             self.assertIsNotNone(server.sslctx)
             self.assertEqual(type(server.socket), ssl.SSLSocket)
             server.server_close()
             sslctx = ssl.create_default_context()
             server = ModbusTlsServer(context=None,
                                      identity=identity,
                                      sslctx=sslctx)
             self.assertEqual(server.sslctx, sslctx)
             self.assertEqual(type(server.socket), ssl.SSLSocket)
             server.server_close()