chiark / gitweb /
include test cases for python getsig replacement
authorHans-Christoph Steiner <hans@eds.org>
Sat, 30 Aug 2014 15:07:29 +0000 (11:07 -0400)
committerCiaran Gultnieks <ciaran@ciarang.com>
Fri, 7 Nov 2014 09:20:33 +0000 (09:20 +0000)
This includes the old getsig.java since that is the canonical implementation
of that algorithm.

fixes #5 https://gitlab.com/fdroid/fdroidserver/issues/5

MANIFEST.in
tests/getsig/getsig.java [moved from fdroidserver/getsig/getsig.java with 100% similarity]
tests/getsig/make.sh [moved from fdroidserver/getsig/make.sh with 100% similarity]
tests/getsig/run.sh [moved from fdroidserver/getsig/run.sh with 100% similarity]
tests/run-tests
tests/update.TestCase [new file with mode: 0755]
tests/urzip-badcert.apk [new file with mode: 0644]
tests/urzip-badsig.apk [new file with mode: 0644]

index 468d24ee74f0c9325bd9316d6abaab6288af2470..2cf1078c5ab82af0e14b80953d6b71aaeaaa3372 100644 (file)
@@ -24,8 +24,14 @@ include examples/config.py
 include examples/fdroid-icon.png
 include examples/makebs.config.py
 include examples/opensc-fdroid.cfg
+include tests/getsig/run.sh
+include tests/getsig/make.sh
+include tests/getsig/getsig.java
+include tests/getsig/getsig.class
 include tests/run-tests
+include tests/update.TestCase
 include tests/urzip.apk
+include tests/urzip-badsig.apk
 include wp-fdroid/AndroidManifest.xml
 include wp-fdroid/android-permissions.php
 include wp-fdroid/readme.txt
index 1f0e7709e7355f770f496577fb7678403d44e527..c12c78a7b01bb51fbc159d85721080388de6f62d 100755 (executable)
@@ -92,6 +92,15 @@ cd $WORKSPACE
 ./hooks/pre-commit
 
 
+#------------------------------------------------------------------------------#
+echo_header "test python getsig replacement"
+
+cd $WORKSPACE/tests/getsig
+./make.sh
+cd $WORKSPACE/tests
+./update.TestCase
+
+
 #------------------------------------------------------------------------------#
 echo_header "create a source tarball and use that to build a repo"
 
diff --git a/tests/update.TestCase b/tests/update.TestCase
new file mode 100755 (executable)
index 0000000..88b429f
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
+
+import inspect
+import optparse
+import os
+import sys
+import unittest
+
+localmodule = os.path.realpath(os.path.join(
+        os.path.dirname(inspect.getfile(inspect.currentframe())),
+        '..'))
+print('localmodule: ' + localmodule)
+if localmodule not in sys.path:
+    sys.path.insert(0,localmodule)
+
+import fdroidserver.common
+import fdroidserver.update
+from fdroidserver.common import FDroidPopen, SilentPopen
+
+class UpdateTest(unittest.TestCase):
+    '''fdroid update'''
+
+    def javagetsig(self, apkfile):
+        getsig_dir = os.path.join(os.path.dirname(__file__), 'getsig')
+        if not os.path.exists(getsig_dir + "/getsig.class"):
+            logging.critical("getsig.class not found. To fix: cd '%s' && ./make.sh" % getsig_dir)
+            sys.exit(1)
+        p = FDroidPopen(['java', '-cp', os.path.join(os.path.dirname(__file__), 'getsig'),
+                         'getsig', os.path.join(os.getcwd(), apkfile)])
+        sig = None
+        for line in p.output.splitlines():
+            if line.startswith('Result:'):
+                sig = line[7:].strip()
+                break
+        if p.returncode == 0:
+            return sig
+        else:
+            return None
+        
+    def testGoodGetsig(self):
+        apkfile = os.path.join(os.path.dirname(__file__), 'urzip.apk')
+        sig = self.javagetsig(apkfile)
+        self.assertIsNotNone(sig, "sig is None")
+        pysig = fdroidserver.update.getsig(apkfile)
+        self.assertIsNotNone(pysig, "pysig is None")        
+        self.assertEquals(sig, fdroidserver.update.getsig(apkfile),
+                          "python sig not equal to java sig!")
+        self.assertEquals(len(sig), len(pysig),
+                          "the length of the two sigs are different!")
+        try:
+            self.assertEquals(sig.decode('hex'), pysig.decode('hex'),
+                              "the length of the two sigs are different!")
+        except TypeError as e:
+            print e
+            self.assertTrue(False, 'TypeError!')
+
+    def testBadGetsig(self):
+        apkfile = os.path.join(os.path.dirname(__file__), 'urzip-badsig.apk')
+        sig = self.javagetsig(apkfile)
+        self.assertIsNone(sig, "sig should be None: " + str(sig))
+        pysig = fdroidserver.update.getsig(apkfile)
+        self.assertIsNone(pysig, "python sig should be None: " + str(sig))
+
+        apkfile = os.path.join(os.path.dirname(__file__), 'urzip-badcert.apk')
+        sig = self.javagetsig(apkfile)
+        self.assertIsNone(sig, "sig should be None: " + str(sig))
+        pysig = fdroidserver.update.getsig(apkfile)
+        self.assertIsNone(pysig, "python sig should be None: " + str(sig))
+
+
+if __name__ == "__main__":
+    parser = optparse.OptionParser()
+    parser.add_option("-v", "--verbose", action="store_true", default=False,
+                      help="Spew out even more information than normal")
+    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
+
+    newSuite = unittest.TestSuite()
+    newSuite.addTest(unittest.makeSuite(UpdateTest))
+    unittest.main()
diff --git a/tests/urzip-badcert.apk b/tests/urzip-badcert.apk
new file mode 100644 (file)
index 0000000..cd7dd08
Binary files /dev/null and b/tests/urzip-badcert.apk differ
diff --git a/tests/urzip-badsig.apk b/tests/urzip-badsig.apk
new file mode 100644 (file)
index 0000000..89e106b
Binary files /dev/null and b/tests/urzip-badsig.apk differ