comparison 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
comparison
equal deleted inserted replaced
636:2fd4f9980a2a 637:be30d50bc4f0
22 QVERIFY (verify_binary (NULL, 10) != VerifyValid); 22 QVERIFY (verify_binary (NULL, 10) != VerifyValid);
23 QVERIFY (verify_binary ("foo", 10) != VerifyValid); 23 QVERIFY (verify_binary ("foo", 10) != VerifyValid);
24 QVERIFY (verify_binary ("bar", -1) != VerifyValid); 24 QVERIFY (verify_binary ("bar", -1) != VerifyValid);
25 /* On windows the next line will check that a valid microsoft 25 /* On windows the next line will check that a valid microsoft
26 * signed executable is not valid for us (pinning). On linux 26 * signed executable is not valid for us (pinning). On linux
27 * it will just fail with a read error. */ 27 * it will just fail with a read error which we tested above */
28 #ifdef Q_OS_WIN
28 QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe", 29 QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe",
29 strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyValid); 30 strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyInvalidCertificate);
31 #endif
30 QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid); 32 QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid);
31 } 33 }
32 34
35 /* Check that a signature with only a different key (of the same size)
36 * is not validated (Invalid signature because key and cert don't match)*/
37 void BinVerifyTest::testOtherKey()
38 {
39 QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst-other-key" EXE_SUFFIX,
40 strlen("fakeinst-other-key" EXE_SUFFIX)));
41 }
42
43 /* Check that an invalid signature is not validated */
44 void BinVerifyTest::testInvalidSig()
45 {
46 QVERIFY(VerifyValid != verify_binary ("fakeinst-invalid" EXE_SUFFIX,
47 strlen("fakeinst-invalid" EXE_SUFFIX)));
48 }
49
50 /* Check that a signature with a different (valid) certificate is not validated */
51 void BinVerifyTest::testOtherCert()
52 {
53 QVERIFY(VerifyInvalidCertificate == verify_binary ("fakeinst-other-cert" EXE_SUFFIX,
54 strlen("fakeinst-other-cert" EXE_SUFFIX)));
55 }
56
33 /* Check that no signature is not validated */ 57 /* Check that no signature is not validated */
34 /* Check that an invalid signature is not validated */
35 /* Check that a signature with only a different key (of the same size)
36 * is not validated */
37 /* Check that a signature with a different certificate is not validated */
38 void BinVerifyTest::testNoSignature() 58 void BinVerifyTest::testNoSignature()
39 { 59 {
40 QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst" EXE_SUFFIX, 60 QVERIFY(VerifyValid != verify_binary ("fakeinst" EXE_SUFFIX,
41 strlen("fakeinst" EXE_SUFFIX))); 61 strlen("fakeinst" EXE_SUFFIX)));
42 } 62 }
43 63
44 /* Check that a valid signed executable is verified */ 64 /* Check that a valid signed executable is verified */
45 void BinVerifyTest::testValidBinary() 65 void BinVerifyTest::testValidBinary()
46 { 66 {

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