def main() -> None: logging.config.fileConfig(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'logging.ini')) # Parse required arguments. args = _parse_arguments() raven_client = Client( dsn=args.sentry_dsn, environment=args.sentry_environment, tags={ 'component': 'signing-service', }, ) crash_logger.handlers[0].client = raven_client # type: ignore if hasattr(args, "from_email_address"): notifier = EmailNotifier( args.from_email_address, args.from_email_password, args.to_email_addresses, ) else: notifier = ConsoleNotifier() # type: ignore SigningService( args.concent_cluster_host, args.concent_cluster_port, args.initial_reconnect_delay, args.concent_public_key, args.signing_service_private_key, args.ethereum_private_key, args.max_reconnect_attempts, notifier, ).run()
def _prepare_and_execute_handle_connection( self, raw_message, handle_connection_wrapper=None, expect_response_from_scoket=True): def mocked_generator(): yield raw_message raise SigningServiceValidationError() with mock.patch('signing_service.signing_service.SigningService.run'): with closing(socket.socket( socket.AF_INET, socket.SOCK_STREAM)) as signing_service_socket: signing_service_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) with closing(socket.socket( socket.AF_INET, socket.SOCK_STREAM)) as client_socket: client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) signing_service = SigningService( self.host, self.port, self.initial_reconnect_delay, CONCENT_PUBLIC_KEY, SIGNING_SERVICE_PRIVATE_KEY, TEST_ETHEREUM_PRIVATE_KEY, SIGNING_SERVICE_DEFAULT_RECONNECT_ATTEMPTS, ConsoleNotifier(), ) # For test purposes we reverse roles, so signing service works as server. signing_service_socket.bind( ('127.0.0.1', self.signing_service_port)) signing_service_socket.listen(1) client_socket.connect( ('127.0.0.1', self.signing_service_port)) (connection, _address) = signing_service_socket.accept() client_socket.setblocking(False) with pytest.raises(SigningServiceValidationError): if handle_connection_wrapper is not None: handle_connection_wrapper(signing_service, connection, mocked_generator()) else: signing_service._handle_connection( mocked_generator(), connection) if expect_response_from_scoket: response = next( unescape_stream(connection=client_socket)) else: # We do not expect to get anything from the socket, dummy response is returned. response = mock.sentinel.no_response return response
def setUp(self, unused_tcp_port_factory): self.signing_service = SigningService( '127.0.0.1', unused_tcp_port_factory(), 2, CONCENT_PUBLIC_KEY, SIGNING_SERVICE_PRIVATE_KEY, TEST_ETHEREUM_PRIVATE_KEY, SIGNING_SERVICE_DEFAULT_RECONNECT_ATTEMPTS, ConsoleNotifier(), )
def setUp(self, unused_tcp_port_factory): self.host = '127.0.0.1' self.port = unused_tcp_port_factory() self.initial_reconnect_delay = 2 self.parameters = [ self.host, self.port, self.initial_reconnect_delay, CONCENT_PUBLIC_KEY, SIGNING_SERVICE_PRIVATE_KEY, TEST_ETHEREUM_PRIVATE_KEY, SIGNING_SERVICE_DEFAULT_RECONNECT_ATTEMPTS, ConsoleNotifier(), ]
def setUp(self): self.host = '127.0.0.1' self.port = 8000 self.initial_reconnect_delay = 2 with mock.patch('signing_service.signing_service.SigningService.run'): self.signing_service = SigningService( self.host, self.port, self.initial_reconnect_delay, CONCENT_PUBLIC_KEY, SIGNING_SERVICE_PRIVATE_KEY, TEST_ETHEREUM_PRIVATE_KEY, SIGNING_SERVICE_DEFAULT_RECONNECT_ATTEMPTS, ConsoleNotifier(), )
def _prepare_and_execute_handle_connection(self, raw_message): def mocked_generator(): yield raw_message with mock.patch('signing_service.signing_service.SigningService.run'): with closing(socket.socket( socket.AF_INET, socket.SOCK_STREAM)) as signing_service_socket: signing_service_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) with closing(socket.socket( socket.AF_INET, socket.SOCK_STREAM)) as client_socket: client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) signing_service = SigningService( self.host, self.port, self.initial_reconnect_delay, CONCENT_PUBLIC_KEY, SIGNING_SERVICE_PRIVATE_KEY, TEST_ETHEREUM_PRIVATE_KEY, SIGNING_SERVICE_DEFAULT_RECONNECT_ATTEMPTS, ConsoleNotifier(), ) # For test purposes we reverse roles, so signing service works as server. signing_service_socket.bind( ('127.0.0.1', self.signing_service_port)) signing_service_socket.listen(1) client_socket.connect( ('127.0.0.1', self.signing_service_port)) (connection, _address) = signing_service_socket.accept() signing_service._authenticate(mocked_generator(), connection) raw_message_received = next( unescape_stream(connection=client_socket)) return raw_message_received