Example #1
0
 def __generate_metadata(self):
     return {
         "request": sanitize_object(
             self.request_config.get("request_data", self.options)
         ),
         "environment": sanitize_object(
             self.request_config.get("environment_data", self.options)
         ),
         "session": sanitize_object(
             self.request_config.get("session_data", self.options)
         ),
         "extraData": sanitize_object(
             self.request_config.get("extra_data", self.options)
         ),
     }
Example #2
0
    def add_tab(self, name, dictionary):
        """
        Add a meta-data tab to the notification

        If the tab already exists, the new content will be merged into the existing content.
        """
        if not isinstance(dictionary, dict):
            self.add_tab("custom", {name:dictionary})
            return

        if name not in self.meta_data:
            self.meta_data[name] = {}

        self.meta_data[name].update(sanitize_object(dictionary, filters=self.config.params_filters))
Example #3
0
    def add_tab(self, name, dictionary):
        """
        Add a meta-data tab to the notification

        If the tab already exists, the new content will be merged into the existing content.
        """
        if not isinstance(dictionary, dict):
            self.add_tab("custom", {name: dictionary})
            return

        if name not in self.meta_data:
            self.meta_data[name] = {}

        self.meta_data[name].update(
            sanitize_object(dictionary, filters=self.config.params_filters))
Example #4
0
def test_sanitize_object():
    filters = ["password", "credit_card"]
    crazy_dict = {
        "password": "******",
        "metadata": {
            "another_password": "******",
            "regular": "text"
        },
        "bad_utf8": "a test of \xe9 char",
        "list": ["list", "of", "things"],
        "unicode": u("string"),
        "obj": Exception(),
        "valid_unicode": u("\u2603"),
    }

    # Sanitize our object
    sane_dict = sanitize_object(crazy_dict, filters=filters)

    # Check the values have been sanitized
    assert(sane_dict["password"] == "[FILTERED]")
    assert(sane_dict["metadata"]["another_password"] == "[FILTERED]")
    assert(sane_dict["metadata"]["regular"] == "text")
    assert("things" in sane_dict["list"])
Example #5
0
def test_sanitize_object():
    filters = ["password", "credit_card"]
    crazy_dict = {
        "password": "******",
        "metadata": {
            "another_password": "******",
            "regular": "text"
        },
        "bad_utf8": "a test of \xe9 char",
        "list": ["list", "of", "things"],
        "unicode": u("string"),
        "obj": Exception(),
        "valid_unicode": u("\u2603"),
    }

    # Sanitize our object
    sane_dict = sanitize_object(crazy_dict, filters=filters)

    # Check the values have been sanitized
    assert (sane_dict["password"] == "[FILTERED]")
    assert (sane_dict["metadata"]["another_password"] == "[FILTERED]")
    assert (sane_dict["metadata"]["regular"] == "text")
    assert ("things" in sane_dict["list"])
 def test_sanitize_filters(self):
     data = {"credit_card": "123213213123", "password": "******", "cake": True}
     sane_data = sanitize_object(data, filters=["credit_card", "password"])
     self.assertEqual(sane_data, {"credit_card": "[FILTERED]",
                                  "password": "******",
                                  "cake": True})
 def test_sanitize_unencoded_object(self):
     data = {"exc": Exception()}
     sane_data = sanitize_object(data, filters=[])
     self.assertEqual(sane_data, {"exc": ""})
 def test_sanitize_bad_utf8_object(self):
     data = {"bad_utf8": u("test \xe9")}
     sane_data = sanitize_object(data, filters=[])
     self.assertEqual(sane_data, data)
 def test_sanitize_nested_object_filters(self):
     data = {"metadata": {"another_password": "******"}}
     sane_data = sanitize_object(data, filters=["password"])
     self.assertEqual(sane_data,
                      {"metadata": {"another_password": "******"}})
 def test_sanitize_valid_unicode_object(self):
     data = {"item": u('\U0001f62c')}
     sane_data = sanitize_object(data, filters=[])
     self.assertEqual(sane_data, data)
 def test_sanitize_list(self):
     data = {"list": ["carrots", "apples", "peas"],
             "passwords": ["abc", "def"]}
     sane_data = sanitize_object(data, filters=["credit_card", "password"])
     self.assertEqual(sane_data, {"list": ["carrots", "apples", "peas"],
                                  "passwords": "[FILTERED]"})
Example #12
0
 def sanitize_object(self, data):
     return sanitize_object(data, filters=self.config.get("params_filters", self.options))