From 641b0b4d0315b3a1fae67e4ad75805741ece4b5d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Wed, 15 Jul 2020 16:57:51 +0200 Subject: [PATCH] Improve DB::Crypto negative test ratio Redundant positive tests removed. Negative constructor tests added. Change-Id: Ic1c2d30d4121c4e901485cae63cb7a203865af7d --- unit-tests/test_db_crypto.cpp | 72 +++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/unit-tests/test_db_crypto.cpp b/unit-tests/test_db_crypto.cpp index 1317561..2fb5182 100644 --- a/unit-tests/test_db_crypto.cpp +++ b/unit-tests/test_db_crypto.cpp @@ -63,28 +63,13 @@ POSITIVE_TEST_CASE(DBtestSimple) rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); check_DB_integrity(rowPattern); -} -POSITIVE_TEST_CASE(DBtestBIG) -{ - DB::Row rowPattern = create_default_row(); + rowPattern.data = createBigBlob(4096); rowPattern.dataSize = rowPattern.data.size(); - rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); check_DB_integrity(rowPattern); } -POSITIVE_TEST_CASE(DBtestGlobal) -{ - DB::Row rowPattern = create_default_row(); - rowPattern.data = RawBuffer(1024, 2); - rowPattern.dataSize = rowPattern.data.size(); - rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); - - BOOST_REQUIRE_NO_THROW(m_db.saveRow(rowPattern)); - DB::Row name_duplicate = rowPattern; - rowPattern.owner = rowPattern.owner + "1"; -} POSITIVE_TEST_CASE(DBtestTransaction) { DB::Row rowPattern = create_default_row(); @@ -103,23 +88,6 @@ POSITIVE_TEST_CASE(DBtestTransaction) BOOST_CHECK_MESSAGE(!row_optional, "Row still present after rollback"); } -POSITIVE_TEST_CASE(DBtestBackend) -{ - DB::Row rowPattern = create_default_row(); - rowPattern.data = RawBuffer(32, 1); - rowPattern.dataSize = rowPattern.data.size(); - rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); - - rowPattern.backendId = CryptoBackend::OpenSSL; - check_DB_integrity(rowPattern); - - rowPattern.backendId = CryptoBackend::TrustZone; - check_DB_integrity(rowPattern); - - rowPattern.backendId = CryptoBackend::None; - check_DB_integrity(rowPattern); -} - POSITIVE_TEST_CASE(DBtestMove) { struct TestCrypto : public DB::Crypto { @@ -383,6 +351,44 @@ NEGATIVE_TEST_CASE(DBtestClientKey) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(DBCRYPTO_CTOR_TEST) + +NEGATIVE_TEST_CASE(DBtestCryptoWrongPasswordLegacy) +{ + BOOST_REQUIRE_THROW(DB::Crypto(DB_TEST_DIR "/testme_ver3.db", "", CKM::RawBuffer(16)), + Exc::DatabaseFailed); +} + +NEGATIVE_TEST_CASE(DBtestCryptoWrongPasswordCurrent) +{ + BOOST_REQUIRE_THROW(DB::Crypto("", DB_TEST_DIR "/testme0_ver4.db", CKM::RawBuffer(16)), + Exc::DatabaseFailed); +} + +NEGATIVE_TEST_CASE(DBtestCryptoNonExistingBoth) +{ + BOOST_REQUIRE_THROW(DB::Crypto("/not/existing.db", "/not/existing.db", defaultPass), + Exc::DatabaseFailed); +} + +NEGATIVE_TEST_CASE(DBtestCryptoNonExistingCurrent) +{ + BOOST_REQUIRE_THROW(DB::Crypto(DB_TEST_DIR "/testme_ver3.db", "/not/existing.db", defaultPass), + Exc::DatabaseFailed); +} + +NEGATIVE_TEST_CASE(DBtestCryptoNotDatabaseLegacy) +{ + BOOST_REQUIRE_THROW(DB::Crypto("/usr/bin/yes", "", defaultPass), Exc::DatabaseFailed); +} + +NEGATIVE_TEST_CASE(DBtestCryptoNotDatabaseCurrent) +{ + BOOST_REQUIRE_THROW(DB::Crypto("", "/usr/bin/yes", defaultPass), Exc::DatabaseFailed); +} + +BOOST_AUTO_TEST_SUITE_END() + BOOST_FIXTURE_TEST_SUITE(DBCRYPTO_PERF_TEST, DBFixture) -- 2.7.4