Exemple #1
0
    def test_tika_bug_unicode_error(self):
        """Test add Tika processing."""

        from src.modules.attachments import tika

        # Complete parameters
        conf = {"enabled": True,
                "path_jar": OPTIONS["TIKA_APP_JAR"],
                "memory_allocation": None,
                "whitelist_content_types": [
                    "application/zip", "application/octet-stream"]}

        p = mailparser.parse_from_file(mail_test_10)
        attachments = MailAttachments.withhashes(p.attachments)
        attachments(intelligence=False)
        tika(conf, attachments)

        self.assertNotIn("tika", attachments[0])
Exemple #2
0
    def test_tika_bug_incorrect_padding(self):
        """Test add Tika processing."""

        from src.modules.attachments import tika

        # Complete parameters
        conf = {"enabled": True,
                "path_jar": OPTIONS["TIKA_APP_JAR"],
                "memory_allocation": None,
                "whitelist_content_types": ["application/zip"]}

        p = mailparser.parse_from_file(mail_test_4)
        attachments = MailAttachments.withhashes(p.attachments)
        attachments(intelligence=False)
        tika(conf, attachments)

        for i in attachments:
            self.assertIn("tika", i)
Exemple #3
0
    def test_tika(self):
        """Test add Tika processing."""

        from src.modules.attachments import tika

        # Complete parameters
        conf = {
            "enabled": True,
            "path_jar": OPTIONS["TIKA_APP_JAR"],
            "memory_allocation": None,
            "whitelist_cont_types": ["application/zip"]
        }
        attachments = MailAttachments.withhashes(self.attachments)
        attachments(intelligence=False, filtercontenttypes=False)
        tika(conf, attachments)

        for i in attachments:
            self.assertIn("tika", i)

        self.assertEqual(len(attachments[0]["tika"]), 2)
        self.assertEqual(int(attachments[0]["tika"][0]["Content-Length"]),
                         attachments[0]["size"])

        # tika disabled
        conf["enabled"] = False
        attachments = MailAttachments.withhashes(self.attachments)
        attachments(intelligence=False, filtercontenttypes=False)
        tika(conf, attachments)

        for i in attachments:
            self.assertNotIn("tika", i)

        conf["enabled"] = True

        # attachments without run()
        with self.assertRaises(KeyError):
            attachments = MailAttachments.withhashes(self.attachments)
            tika(conf, attachments)

        # attachments a key of conf
        with self.assertRaises(KeyError):
            conf_inner = {
                "enabled": True,
                "path_jar": OPTIONS["TIKA_APP_JAR"],
                "memory_allocation": None
            }
            attachments = MailAttachments.withhashes(self.attachments)
            tika(conf_inner, attachments)