diff ui/tests/binverifytest.cpp @ 637:be30d50bc4f0

Add remaining tests to check binverify functionality
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 24 Jun 2014 15:24:09 +0200
parents 2fd4f9980a2a
children 44fa5de02b52
line wrap: on
line diff
--- a/ui/tests/binverifytest.cpp	Mon Jun 23 18:00:45 2014 +0200
+++ b/ui/tests/binverifytest.cpp	Tue Jun 24 15:24:09 2014 +0200
@@ -24,21 +24,41 @@
   QVERIFY (verify_binary ("bar", -1) != VerifyValid);
   /* On windows the next line will check that a valid microsoft
    * signed executable is not valid for us (pinning). On linux
-   * it will just fail with a read error. */
+   * it will just fail with a read error which we tested above */
+#ifdef Q_OS_WIN
   QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe",
-                          strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyValid);
+                          strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyInvalidCertificate);
+#endif
   QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid);
 }
 
+/* Check that a signature with only a different key (of the same size)
+ * is not validated (Invalid signature because key and cert don't match)*/
+void BinVerifyTest::testOtherKey()
+{
+    QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst-other-key" EXE_SUFFIX,
+                strlen("fakeinst-other-key" EXE_SUFFIX)));
+}
+
+/* Check that an invalid signature is not validated */
+void BinVerifyTest::testInvalidSig()
+{
+    QVERIFY(VerifyValid != verify_binary ("fakeinst-invalid" EXE_SUFFIX,
+                strlen("fakeinst-invalid" EXE_SUFFIX)));
+}
+
+/* Check that a signature with a different (valid) certificate is not validated */
+void BinVerifyTest::testOtherCert()
+{
+    QVERIFY(VerifyInvalidCertificate == verify_binary ("fakeinst-other-cert" EXE_SUFFIX,
+                strlen("fakeinst-other-cert" EXE_SUFFIX)));
+}
+
 /* Check that no signature is not validated */
-/* Check that an invalid signature is not validated */
-/* Check that a signature with only a different key (of the same size)
- * is not validated */
-/* Check that a signature with a different certificate is not validated */
 void BinVerifyTest::testNoSignature()
 {
-    QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst" EXE_SUFFIX,
-                                                     strlen("fakeinst" EXE_SUFFIX)));
+    QVERIFY(VerifyValid != verify_binary ("fakeinst" EXE_SUFFIX,
+                strlen("fakeinst" EXE_SUFFIX)));
 }
 
 /* Check that a valid signed executable is verified */

http://wald.intevation.org/projects/trustbridge/