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)
示例#2
0
    def test_scans_completed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        scan_time = 1.3
        generator.scans_completed(scan_time)
        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output displayed the total scan time
        self.assertIn(str(scan_time), received_output)
示例#3
0
    def test_scans_started(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        generator.scans_started()

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output displayed something
        self.assertTrue(received_output)
    def test_scans_started(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        generator.scans_started()

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output displayed something
        self.assertTrue(received_output)
    def test_scans_completed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        scan_time = 1.3
        generator.scans_completed(scan_time)
        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output displayed the total scan time
        self.assertIn(str(scan_time), received_output)
示例#6
0
    def test_scans_completed(self):
        # Given the time sslyze took to complete all scans
        scan_time = 1.3

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.scans_completed(scan_time)
            final_output = file_out.getvalue()

        # It succeeds and the total scan time is displayed
        assert str(scan_time) in final_output
示例#7
0
    def test_server_connectivity_test_succeeded_with_optional_client_auth(self):
        # Test when client authentication is optional
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo(ClientAuthenticationServerConfigurationEnum.OPTIONAL)
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly warned about client authentication
        self.assertIn('Server requested optional client authentication', received_output)
示例#8
0
    def test_server_connectivity_test_failed(self):
        # Given a server to scan to which sslyze could not connect
        error = ConnectionToServerFailedFactory.create()

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_connectivity_test_failed(error)
            final_output = file_out.getvalue()

        # It succeeds and the connectivity error was displayed
        assert final_output
        assert error.error_message in final_output
示例#9
0
    def test_server_connectivity_test_succeeded(self):
        # Given a server to scan to which sslyze was able to connect
        server_info = ServerConnectivityInfoFactory.create()

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_connectivity_test_succeeded(server_info)
            final_output = file_out.getvalue()

        # It succeeds and the server is displayed
        assert final_output
        assert server_info.server_location.hostname in final_output
示例#10
0
    def test_server_connectivity_test_succeeded_with_optional_client_auth(self):
        # Test when client authentication is optional
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo(ClientAuthenticationServerConfigurationEnum.OPTIONAL)
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly warned about client authentication
        assert 'Server requested optional client authentication' in received_output
    def test_server_connectivity_test_succeeded_with_required_client_auth(self):
        # Test when client authentication is required
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo(ClientAuthenticationServerConfigurationEnum.REQUIRED)
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly warned about client authentication
        assert 'Server REQUIRED client authentication' in received_output
示例#12
0
    def test_server_connectivity_test_failed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        failed_scan = ServerConnectivityError(server_info=MockServerConnectivityTester(), error_message='Some érrôr')
        generator.server_connectivity_test_failed(failed_scan)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the connectivity error with unicode
        self.assertIn('unicödeéè.com', received_output)
        self.assertIn('Some érrôr', received_output)
        self.assertIn('discarding corresponding tasks', received_output)
示例#13
0
    def test_server_connectivity_test_failed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        failed_scan = ServerConnectivityError(server_info=MockServerConnectivityTester(), error_message='Some érrôr')
        generator.server_connectivity_test_failed(failed_scan)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the connectivity error with unicode
        assert 'unicödeéè.com' in received_output
        assert 'Some érrôr' in received_output
        assert 'discarding corresponding tasks' in received_output
示例#14
0
    def test_server_connectivity_test_succeeded(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the online domain
        self.assertIn(server_info.hostname, received_output)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn(server_info.ip_address, received_output)
    def test_server_connectivity_test_succeeded(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the online domain
        self.assertIn(server_info.hostname, received_output)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn(server_info.ip_address, received_output)
示例#16
0
    def test_server_connectivity_test_failed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        failed_scan = FailedServerScan(server_string=u'unicödeéè.com',
                                       connection_exception=ServerConnectivityError(error_msg=u'Some érrôr'))
        generator.server_connectivity_test_failed(failed_scan)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the connectivity error with unicode
        self.assertIn(u'unicödeéè.com', received_output)
        self.assertIn(u'Some érrôr', received_output)
        self.assertIn('discarding corresponding tasks', received_output)
    def test_server_connectivity_test_succeeded_with_required_client_auth(
            self):
        # Test when client authentication is required
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        server_info = MockServerConnectivityInfo(
            ClientAuthenticationServerConfigurationEnum.REQUIRED)
        generator.server_connectivity_test_succeeded(server_info)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly warned about client authentication
        self.assertIn('Server REQUIRED client authentication', received_output)
示例#18
0
    def test_server_connectivity_test_succeeded_with_http_tunneling(self):
        # Given a server to scan to which sslyze was able to connect
        server_info = ServerConnectivityInfoFactory.create(
            # And sslyze connected to it via an HTTP proxy
            server_location=ServerNetworkLocationViaHttpProxyFactory.create())

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_connectivity_test_succeeded(server_info)
            final_output = file_out.getvalue()

        # It succeeds and the fact that an HTTP proxy was used was displayed
        assert final_output
        assert "proxy" in final_output
示例#19
0
    def command_line_parsed(
        self,
        available_plugins: Set[Type[Plugin]],
        args_command_list: Any,
        malformed_servers: List[ServerStringParsingError],
    ) -> None:
        # Configure the console output
        should_print_text_results = (
            not args_command_list.quiet and args_command_list.xml_file != "-" and args_command_list.json_file != "-"
        )
        if should_print_text_results:
            self._output_generator_list.append(ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        if args_command_list.json_file:
            json_file_to = (
                sys.stdout
                if args_command_list.json_file == "-"
                else open(args_command_list.json_file, "wt", encoding="utf-8")
            )
            self._output_generator_list.append(JsonOutputGenerator(json_file_to))  # type: ignore

        # Configure the XML output
        if args_command_list.xml_file:
            xml_file_to = (
                sys.stdout
                if args_command_list.xml_file == "-"
                else open(args_command_list.xml_file, "wt", encoding="utf-8")
            )
            self._output_generator_list.append(XmlOutputGenerator(xml_file_to))  # type: ignore

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins, args_command_list, malformed_servers)
示例#20
0
    def command_line_parsed(self, available_plugins, args_command_list):
        # Configure the console output
        should_print_text_results = not args_command_list.quiet and args_command_list.xml_file != '-' \
                                    and args_command_list.json_file != '-'
        if should_print_text_results:
            self._output_generator_list.append(
                ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        json_file_to = None
        if args_command_list.json_file:
            json_file_to = sys.stdout if args_command_list.json_file == '-' else open(
                args_command_list.json_file, 'w')
        if json_file_to:
            self._output_generator_list.append(
                JsonOutputGenerator(json_file_to))

        # Configure the XML output
        xml_file_to = None
        if args_command_list.xml_file:
            xml_file_to = sys.stdout if args_command_list.xml_file == '-' else open(
                args_command_list.xml_file, 'w')
        if xml_file_to:
            self._output_generator_list.append(XmlOutputGenerator(xml_file_to))

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins,
                                              args_command_list)
示例#21
0
    def command_line_parsed(self, available_plugins, args_command_list,
                            malformed_servers):
        # type: (Set[Type[Plugin]], Any, List[ServerStringParsingError]) -> None
        # Configure the console output
        should_print_text_results = not args_command_list.quiet and args_command_list.xml_file != '-' \
                                    and args_command_list.json_file != '-'
        if should_print_text_results:
            self._output_generator_list.append(
                ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        if args_command_list.json_file:
            json_file_to = sys.stdout if args_command_list.json_file == '-' else open(
                args_command_list.json_file, 'wt')
            self._output_generator_list.append(
                JsonOutputGenerator(json_file_to))  # type: ignore

        # Configure the XML output
        if args_command_list.xml_file:
            xml_file_to = sys.stdout if args_command_list.xml_file == '-' else open(
                args_command_list.xml_file, 'wt')
            self._output_generator_list.append(
                XmlOutputGenerator(xml_file_to))  # type: ignore

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins,
                                              args_command_list,
                                              malformed_servers)
    def test_server_connectivity_test_failed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        failed_scan = FailedServerScan(
            server_string=u'unicödeéè.com',
            connection_exception=ServerConnectivityError(
                error_msg=u'Some érrôr'))
        generator.server_connectivity_test_failed(failed_scan)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the connectivity error with unicode
        self.assertIn(u'unicödeéè.com', received_output)
        self.assertIn(u'Some érrôr', received_output)
        self.assertIn(u'discarding corresponding tasks', received_output)
示例#23
0
    def test_command_line_parsed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        class FakePlugin1:
            pass

        class FakePlugin2:
            pass

        generator.command_line_parsed({FakePlugin1, FakePlugin2}, None, [])

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the available plugins
        assert 'FakePlugin1' in received_output
        assert 'FakePlugin2' in received_output
示例#24
0
    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_command_line_parsed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        class FakePlugin1(object):
            pass

        class FakePlugin2(object):
            pass

        generator.command_line_parsed([FakePlugin1, FakePlugin2], None)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the available plugins
        self.assertIn(u'FakePlugin1', received_output)
        self.assertIn(u'FakePlugin2', received_output)
示例#26
0
    def test_command_line_parsed(self):
        output_file = StringIO()
        generator = ConsoleOutputGenerator(output_file)

        class FakePlugin1:
            pass

        class FakePlugin2:
            pass

        generator.command_line_parsed({FakePlugin1, FakePlugin2}, None, [])

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the console output properly listed the available plugins
        self.assertIn('FakePlugin1', received_output)
        self.assertIn('FakePlugin2', received_output)
示例#27
0
    def command_line_parsed(self, parsed_command_line: ParsedCommandLine) -> None:
        if not parsed_command_line.should_disable_console_output:
            self._output_generator_list.append(ConsoleOutputGenerator(sys.stdout))

        if parsed_command_line.json_file_out:
            self._output_generator_list.append(JsonOutputGenerator(parsed_command_line.json_file_out))

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(parsed_command_line)
示例#28
0
    def test_command_line_parsed(self):
        # Given a command line used to run sslyze
        parsed_cmd_line = ParsedCommandLineFactory.create()

        # Which contained some valid, and some invalid servers
        assert parsed_cmd_line.invalid_servers
        assert parsed_cmd_line.servers_to_scans

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.command_line_parsed(parsed_cmd_line)
            final_output = file_out.getvalue()

        # It succeeds and the invalid servers were displayed
        assert final_output
        for bad_server in parsed_cmd_line.invalid_servers:
            assert bad_server.server_string in final_output
            assert bad_server.error_message in final_output
示例#29
0
    def test_server_connectivity_test_succeeded_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)

        generator.server_connectivity_test_succeeded(server_info)

        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
        assert str(server_info.port) in received_output
        assert 'Proxy' in received_output
        assert tunneling_settings.hostname in received_output
        assert str(tunneling_settings.port) in received_output
示例#30
0
    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
示例#31
0
    def test_server_connectivity_test_succeeded_with_required_client_auth(
            self):
        # Given a server to scan to which sslyze was able to connect
        server_info = ServerConnectivityInfoFactory.create(
            tls_probing_result=ServerTlsProbingResult(
                highest_tls_version_supported=TlsVersionEnum.TLS_1_2,
                cipher_suite_supported="AES",
                # And the server requires client authentication
                client_auth_requirement=ClientAuthRequirementEnum.REQUIRED,
            ))

        # When generating the console output for this
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_connectivity_test_succeeded(server_info)
            final_output = file_out.getvalue()

        # It succeeds and the fact that the server requires client auth was displayed
        assert final_output
        assert "Server REQUIRED client authentication" in final_output
示例#32
0
    def test_server_connectivity_test_succeeded_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)

        generator.server_connectivity_test_succeeded(server_info)

        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)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn('Proxy', received_output)
        self.assertIn(tunneling_settings.hostname, received_output)
        self.assertIn(str(tunneling_settings.port), 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()
示例#34
0
    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)
示例#35
0
    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
    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(u'û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())
示例#37
0
    def command_line_parsed(self, parsed_command_line: ParsedCommandLine) -> None:
        # Setup console output if needed
        if not parsed_command_line.should_disable_console_output:
            self._output_generator_list.append(ConsoleOutputGenerator(sys.stdout))

        # Setup JSON output if needed
        json_file_out = None
        if parsed_command_line.should_print_json_to_console:
            json_file_out = sys.stdout
        elif parsed_command_line.json_path_out:
            json_file_out = parsed_command_line.json_path_out.open("wt", encoding="utf-8")

        if json_file_out:
            self._output_generator_list.append(JsonOutputGenerator(json_file_out))

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(parsed_command_line)
示例#38
0
 def test_scans_started(self):
     with StringIO() as file_out:
         console_gen = ConsoleOutputGenerator(file_to=file_out)
         console_gen.scans_started()
         final_output = file_out.getvalue()
     assert final_output