Improve DB::Crypto negative test ratio 26/238626/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 15 Jul 2020 14:57:51 +0000 (16:57 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 15 Jul 2020 14:57:51 +0000 (16:57 +0200)
Redundant positive tests removed.
Negative constructor tests added.

Change-Id: Ic1c2d30d4121c4e901485cae63cb7a203865af7d

unit-tests/test_db_crypto.cpp

index 1317561..2fb5182 100644 (file)
@@ -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)