chiark / gitweb /
lint: ban all dangerous HTML tags
[fdroidserver.git] / tests / lint.TestCase
index 158c5cb12a872ebe63a51296a8b625c977b7ffb8..ad9f0514f1791c46b228389200a7cc50c5b2747e 100755 (executable)
@@ -3,6 +3,7 @@
 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
 
 import inspect
+import logging
 import optparse
 import os
 import shutil
@@ -23,6 +24,14 @@ import fdroidserver.lint
 class LintTest(unittest.TestCase):
     '''fdroidserver/lint.py'''
 
+    def setUp(self):
+        logging.basicConfig(level=logging.INFO)
+        self.basedir = os.path.join(localmodule, 'tests')
+        self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
+        if not os.path.exists(self.tmpdir):
+            os.makedirs(self.tmpdir)
+        os.chdir(self.basedir)
+
     def test_check_for_unsupported_metadata_files(self):
         config = dict()
         fdroidserver.common.fill_config_defaults(config)
@@ -31,9 +40,8 @@ class LintTest(unittest.TestCase):
         fdroidserver.lint.config = config
         self.assertTrue(fdroidserver.lint.check_for_unsupported_metadata_files())
 
-        tmpdir = os.path.join(localmodule, '.testfiles')
-        tmptestsdir = tempfile.mkdtemp(prefix='test_check_for_unsupported_metadata_files-',
-                                       dir=tmpdir)
+        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
+                                       dir=self.tmpdir)
         self.assertFalse(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
         shutil.copytree(os.path.join(localmodule, 'tests', 'metadata'),
                         os.path.join(tmptestsdir, 'metadata'),
@@ -43,6 +51,24 @@ class LintTest(unittest.TestCase):
                     os.path.join(tmptestsdir, 'metadata'))
         self.assertTrue(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
 
+    def test_forbidden_html_tags(self):
+        config = dict()
+        fdroidserver.common.fill_config_defaults(config)
+        fdroidserver.common.config = config
+        fdroidserver.lint.config = config
+
+        app = {
+            'Name': 'Bad App',
+            'Summary': 'We pwn you',
+            'Description': 'This way: <style><img src="</style><img src=x onerror=alert(1)//">',
+        }
+
+        anywarns = False
+        for warn in fdroidserver.lint.check_regexes(app):
+            anywarns = True
+            logging.debug(warn)
+        self.assertTrue(anywarns)
+
 
 if __name__ == "__main__":
     parser = optparse.OptionParser()
@@ -53,4 +79,4 @@ if __name__ == "__main__":
 
     newSuite = unittest.TestSuite()
     newSuite.addTest(unittest.makeSuite(LintTest))
-    unittest.main()
+    unittest.main(failfast=False)