def test_server_scan_completed(self): output_file = StringIO() generator = ConsoleOutputGenerator(output_file) server_info = MockServerConnectivityInfo() plugin_result_1 = MockPluginScanResult(server_info, MockPluginScanCommandOne(), u'Plugin ûnicôdé output', None) plugin_result_2 = MockPluginScanResult(server_info, MockPluginScanCommandTwo(), u'other plugin Output', None) server_scan = CompletedServerScan(server_info, [plugin_result_1, plugin_result_2]) generator.server_scan_completed(server_scan) received_output = output_file.getvalue() output_file.close() # Ensure the console output displayed the server's info self.assertIn(server_info.hostname, received_output.lower()) self.assertIn(str(server_info.port), received_output) self.assertIn(server_info.ip_address, received_output.lower()) # Ensure the console output displayed the plugin text outputs self.assertIn(plugin_result_1.text_output, received_output) self.assertIn(plugin_result_2.text_output, received_output)
def test_server_scan_completed(self): # Given a completed scan for a server scan_results = { ScanCommand.TLS_COMPRESSION: CompressionScanResult(supports_compression=True) } scan_result = ServerScanResultFactory.create( scan_commands_results=scan_results) # When generating the console output for this server scan with StringIO() as file_out: console_gen = ConsoleOutputGenerator(file_to=file_out) console_gen.server_scan_completed(scan_result) final_output = file_out.getvalue() # It succeeds assert final_output assert "Compression" in final_output
def test_server_scan_completed_with_error(self): # Given a completed scan for a server that triggered an error error_trace = TracebackExceptionFactory.create() scan_errors = { ScanCommand.TLS_COMPRESSION: ScanCommandError(reason=ScanCommandErrorReasonEnum.BUG_IN_SSLYZE, exception_trace=error_trace) } scan_result = ServerScanResultFactory.create( scan_commands_errors=scan_errors) # When generating the console output for this server scan with StringIO() as file_out: console_gen = ConsoleOutputGenerator(file_to=file_out) console_gen.server_scan_completed(scan_result) final_output = file_out.getvalue() # It succeeds and displays the error assert final_output assert error_trace.stack.format()[0] in final_output
def test_server_scan_completed_with_http_tunneling(self): output_file = StringIO() generator = ConsoleOutputGenerator(output_file) # When scanning through a proxy, we do not know the final server's IP address # This makes sure the console output properly handles that tunneling_settings = HttpConnectTunnelingSettings('ûnicôdé.com', 3128) server_info = MockServerConnectivityInfo(http_tunneling_settings=tunneling_settings) server_scan = CompletedServerScan(server_info, []) generator.server_scan_completed(server_scan) received_output = output_file.getvalue() output_file.close() # Ensure the console output properly listed the online domain and that it was going through a proxy self.assertIn(server_info.hostname, received_output.lower()) self.assertIn(str(server_info.port), received_output.lower()) self.assertIn('proxy', received_output.lower()) self.assertIn(tunneling_settings.hostname, received_output.lower()) self.assertIn(str(tunneling_settings.port), received_output.lower())
def test_server_scan_completed(self): output_file = StringIO() generator = ConsoleOutputGenerator(output_file) server_info = MockServerConnectivityInfo() plugin_result_1 = MockPluginScanResult(server_info, MockPluginScanCommandOne(), 'Plugin ûnicôdé output', None) plugin_result_2 = MockPluginScanResult(server_info, MockPluginScanCommandTwo(), 'other plugin Output', None) server_scan = CompletedServerScan(server_info, [plugin_result_1, plugin_result_2]) generator.server_scan_completed(server_scan) received_output = output_file.getvalue() output_file.close() # Ensure the console output displayed the server's info self.assertIn(server_info.hostname, received_output.lower()) self.assertIn(str(server_info.port), received_output) self.assertIn(server_info.ip_address, received_output.lower()) # Ensure the console output displayed the plugin text outputs self.assertIn(plugin_result_1.text_output, received_output) self.assertIn(plugin_result_2.text_output, received_output)
def test_server_scan_completed_with_http_tunneling(self): output_file = StringIO() generator = ConsoleOutputGenerator(output_file) # When scanning through a proxy, we do not know the final server's IP address # This makes sure the console output properly handles that tunneling_settings = HttpConnectTunnelingSettings('ûnicôdé.com', 3128) server_info = MockServerConnectivityInfo(http_tunneling_settings=tunneling_settings) server_scan = CompletedServerScan(server_info, []) generator.server_scan_completed(server_scan) received_output = output_file.getvalue() output_file.close() # Ensure the console output properly listed the online domain and that it was going through a proxy assert server_info.hostname in received_output.lower() assert str(server_info.port) in received_output.lower() assert 'proxy' in received_output.lower() assert tunneling_settings.hostname in received_output.lower() assert str(tunneling_settings.port) in received_output.lower()
def test_server_scan_completed_with_proxy(self): # Given a completed scan for a server server_info = ServerConnectivityInfoFactory.create( # And sslyze connected to the server via an HTTP proxy server_location=ServerNetworkLocationViaHttpProxyFactory.create()) scan_results = { ScanCommand.TLS_COMPRESSION: CompressionScanResult(supports_compression=True) } scan_result = ServerScanResultFactory.create( server_info=server_info, scan_commands_results=scan_results) # When generating the console output for this server scan with StringIO() as file_out: console_gen = ConsoleOutputGenerator(file_to=file_out) console_gen.server_scan_completed(scan_result) final_output = file_out.getvalue() # It succeeds and mentions the HTTP proxy assert final_output assert "HTTP PROXY" in final_output assert "Compression" in final_output