diff ui/tests/binverifytest.cpp @ 1081:edbf5e5e88f4

(issue118) Extend verify_binary to carry an open file * binverify.c: Change result to a structure containing an open fptr Use in Memory data for windows verification. * mainwindow.cpp, selftest.c: Handle the returend structure * binverifytest.cpp: Test for the exclusive read and update signature. * listutil.c: Add optional fptr parameter to read_file
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 11 Sep 2014 12:05:24 +0200
parents 317ee9dc4684
children 948f03bb5254
line wrap: on
line diff
--- a/ui/tests/binverifytest.cpp	Thu Sep 11 12:00:10 2014 +0200
+++ b/ui/tests/binverifytest.cpp	Thu Sep 11 12:05:24 2014 +0200
@@ -30,17 +30,17 @@
 /* Some general robustness checks */
 void BinVerifyTest::testMiscErrors()
 {
-  QVERIFY (verify_binary (NULL, 10) != VerifyValid);
-  QVERIFY (verify_binary ("foo", 10) != VerifyValid);
-  QVERIFY (verify_binary ("bar", -1) != VerifyValid);
+  QVERIFY (verify_binary (NULL, 10).result != VerifyValid);
+  QVERIFY (verify_binary ("foo", 10).result != VerifyValid);
+  QVERIFY (verify_binary ("bar", -1).result!= 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 which we tested above */
 #ifdef Q_OS_WIN
   QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe",
-                          strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyInvalidCertificate);
+                          strlen("c:\\Windows\\System32\\mmc.exe")).result != VerifyInvalidCertificate);
 #endif
-  QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid);
+  QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")).result != VerifyValid);
 }
 
 /* Check that a signature with only a different key (of the same size)
@@ -48,14 +48,16 @@
 void BinVerifyTest::testOtherKey()
 {
     QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst-other-key" EXE_SUFFIX,
-                strlen("fakeinst-other-key" EXE_SUFFIX)));
+                strlen("fakeinst-other-key" EXE_SUFFIX)).result);
 }
 
 /* Check that an invalid signature is not validated */
 void BinVerifyTest::testInvalidSig()
 {
-    QVERIFY(VerifyValid != verify_binary ("fakeinst-invalid" EXE_SUFFIX,
-                strlen("fakeinst-invalid" EXE_SUFFIX)));
+    bin_verify_result res = verify_binary ("fakeinst-invalid" EXE_SUFFIX,
+                strlen("fakeinst-invalid" EXE_SUFFIX));
+    QVERIFY(VerifyValid != res.result);
+    QVERIFY(res.fptr == NULL);
 }
 
 #ifdef Q_OS_WIN
@@ -64,22 +66,34 @@
 void BinVerifyTest::testOtherCert()
 {
     QVERIFY(VerifyInvalidCertificate == verify_binary ("fakeinst-other-cert" EXE_SUFFIX,
-                strlen("fakeinst-other-cert" EXE_SUFFIX)));
+                strlen("fakeinst-other-cert" EXE_SUFFIX)).result);
 }
 #endif
 
 /* Check that no signature is not validated */
 void BinVerifyTest::testNoSignature()
 {
-    QVERIFY(VerifyValid != verify_binary ("fakeinst" EXE_SUFFIX,
-                strlen("fakeinst" EXE_SUFFIX)));
+    bin_verify_result res = verify_binary ("fakeinst" EXE_SUFFIX,
+                strlen("fakeinst" EXE_SUFFIX));
+    QVERIFY(VerifyValid != res.result);
+    QVERIFY(res.fptr == NULL);
 }
 
 /* Check that a valid signed executable is verified */
 void BinVerifyTest::testValidBinary()
 {
-  QVERIFY (VerifyValid == verify_binary ("fakeinst-signed" EXE_SUFFIX,
-                                         strlen("fakeinst-signed" EXE_SUFFIX)));
+    bin_verify_result res = verify_binary ("fakeinst-signed" EXE_SUFFIX,
+                                          strlen("fakeinst-signed" EXE_SUFFIX));
+    QVERIFY (VerifyValid == res.result);
+    QFile thefile ("fakeinst-signed" EXE_SUFFIX);
+#ifdef WIN32
+    /* Verifies the deny write open mode. But on linuy we dont have it. */
+    QVERIFY (!thefile.open(QIODevice::ReadWrite));
+#endif
+    QVERIFY (res.fptr != NULL);
+    fclose(res.fptr);
+    QVERIFY (thefile.open(QIODevice::ReadWrite));
+    thefile.close();
 }
 
 void BinVerifyTest::testSignatureCreation()
@@ -95,8 +109,9 @@
   bool ret = theDialog->appendTextSignatureToFile (garbage, outfile.fileName());
   QVERIFY(QFile::remove(garbage));
   QVERIFY(ret == true);
-  QVERIFY(VerifyValid == verify_binary (outfile.fileName().toUtf8().constData(),
-                                        outfile.fileName().toUtf8().size()));
+  bin_verify_result res = verify_binary (outfile.fileName().toUtf8().constData(),
+                                        outfile.fileName().toUtf8().size());
+  QVERIFY(VerifyValid == res.result);
 }
 bool g_debug = true;
 

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