Esempio n. 1
0
    def test_urlHasValidScheme_url_scheme_not_in_allowed_schemes(self):
        """
        Tests the following unhappy scenario:
        If the function tries to open a URL with a scheme that is not allowed, the function should generate an error
        message indicating that the url has a disallowed scheme.

        :return:
        """
        invalid_combinations = (("https://www.ultimaker.com", ["http"]),
                                ("http://www.ultimaker.com", ["https"]))
        for url, allowed_schemes in invalid_combinations:
            # Ensure the function fails
            self.assertFalse(
                self.url_util._urlHasValidScheme(url, allowed_schemes))

            # Ensure the correct message is outputted in the console
            expected_output = "The scheme '{scheme}' is not in the allowed schemes".format(
                scheme=urlparse(url).scheme)
            log_lines = [
                message for message_type, message in Logger.getUnloggedLines()
            ]
            console_output = "\n".join(log_lines)
            self.assertIn(expected_output, console_output)
            console_output = re.sub(r'\W+', ' ', console_output)
            for scheme in allowed_schemes:
                self.assertIn(scheme, console_output)
Esempio n. 2
0
    def _sendCrashReport(self):
        if with_sentry_sdk:
            try:
                hub = Hub.current
                if not Logger.getLoggers():
                    # No loggers have been loaded yet, so we don't have any breadcrumbs :(
                    # So add them manually so we at least have some info...
                    add_breadcrumb(
                        level="info",
                        message="SentryLogging was not initialised yet")
                    for log_type, line in Logger.getUnloggedLines():
                        add_breadcrumb(message=line)

                event, hint = event_from_exception(
                    (self.exception_type, self.value, self.traceback))
                hub.capture_event(event, hint=hint)
                hub.flush()
            except Exception as e:  # We don't want any exception to cause problems
                Logger.logException(
                    "e",
                    "An exception occurred while trying to send crash report")
                if not self.has_started:
                    print(
                        "An exception occurred while trying to send crash report: %s"
                        % e)
        else:
            msg = "SentrySDK is not available and the report could not be sent."
            Logger.logException("e", msg)
            if not self.has_started:
                print(msg)
                print("Exception type: {}".format(self.exception_type))
                print("Value: {}".format(self.value))
                print("Traceback: {}".format(self.traceback))

        os._exit(1)
Esempio n. 3
0
    def test_urlHasValidScheme_allowed_invalid_scheme_generates_warning(self):
        """
        Tests the following unhappy scenario:
        If we try to allow an invalid scheme when calling the function (anything other than http or https), then a
        warning message that mentions all the invalid schemes should be generated in the console.
        This warning message lets the developer know that he/she is trying to allow an invalid scheme.

        :return: None
        """
        invalid_schemes = [["mailto"], ["ftp"], ["blue", "potato"]]
        for schemes_list in invalid_schemes:

            allowed_schemes = ["https"]
            allowed_schemes.extend(schemes_list)
            self.url_util._urlHasValidScheme("https://www.ultimaker.com",
                                             allowed_schemes)

            # Ensure the correct message is outputted in the console
            expected_output = re.sub(r'\W+', ' ',
                                     "Attempted to allow invalid schemes"
                                     )  # remove special characters
            log_lines = [
                message for message_type, message in Logger.getUnloggedLines()
            ]
            console_output = "\n".join(log_lines)
            self.assertIn(
                expected_output, console_output
            )  # Assert the correct message is in the console output
            for scheme in schemes_list:
                self.assertIn(
                    scheme, console_output
                )  # Assert each of the schemes that are being tested appears in the console output