X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Ftest_db_crypto.cpp;h=a4934484ffc7ddc564d7946d68bcfdb7bab0a47a;hb=ea59c2825e3b8bb2b42ea30f113a96e32dff16bb;hp=4933e6a528b9590e3fc987e19501b9b0e392ec35;hpb=6d6ddcc74076f556a810f4ced007c26d302d9446;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git diff --git a/tests/test_db_crypto.cpp b/tests/test_db_crypto.cpp index 4933e6a..a493448 100644 --- a/tests/test_db_crypto.cpp +++ b/tests/test_db_crypto.cpp @@ -1,145 +1,336 @@ #include -#include #include #include #include +#include #include #include - #include - -BOOST_GLOBAL_FIXTURE(TestConfig) +#include using namespace CKM; -const char* default_alias = "alias"; -const char* default_label = "label"; - -const char* crypto_db = "/tmp/testme.db"; - +namespace +{ const int restricted_local = 1; const int restricted_global = 0; -DBRow createDefaultRow(int restricted = restricted_local, - DBDataType type = DBDataType::BINARY_DATA) { - DBRow row; - row.alias = default_alias; - row.smackLabel = default_label; - row.exportable = 1; - row.restricted = restricted; - row.algorithmType = DBCMAlgType::AES_CBC_256; - row.dataType = type; - row.iv = createDefaultPass(); +const unsigned int c_test_retries = 1000; +const unsigned int c_num_names = 500; +const unsigned int c_num_names_add_test = 5000; +const unsigned int c_names_per_label = 15; - return row; -} - -void compareDBRow(const DBRow &lhs, const DBRow &rhs) { - BOOST_CHECK_MESSAGE(lhs.alias == rhs.alias, - "Aliases didn't match! Got: " << rhs.alias - << " , expected : " << lhs.alias); +} // namespace anonymous - BOOST_CHECK_MESSAGE(lhs.smackLabel == rhs.smackLabel, - "smackLabel didn't match! Got: " << rhs.smackLabel - << " , expected : " << lhs.smackLabel); +BOOST_FIXTURE_TEST_SUITE(DBCRYPTO_TEST, DBFixture) +BOOST_AUTO_TEST_CASE(DBtestSimple) { + DB::Row rowPattern = create_default_row(); + rowPattern.data = RawBuffer(32, 1); + rowPattern.dataSize = rowPattern.data.size(); + rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); - BOOST_CHECK_MESSAGE(lhs.restricted == rhs.restricted, - "restricted didn't match! Got: " << rhs.restricted - << " , expected : " << lhs.restricted); + check_DB_integrity(rowPattern); +} +BOOST_AUTO_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); - BOOST_CHECK_MESSAGE(lhs.exportable == rhs.exportable, - "exportable didn't match! Got: " << rhs.exportable - << " , expected : " << lhs.exportable); + check_DB_integrity(rowPattern); +} +BOOST_AUTO_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_CHECK_MESSAGE(lhs.iv == rhs.iv, - "iv didn't match! Got: " << rhs.iv.size() - << " , expected : " << lhs.iv.size()); + BOOST_REQUIRE_NO_THROW(m_db.saveRow(rowPattern)); - BOOST_CHECK_MESSAGE(lhs.data == rhs.data, - "data didn't match! Got: " << rhs.data.size() - << " , expected : " << lhs.data.size()); + DB::Row name_duplicate = rowPattern; + rowPattern.ownerLabel = rowPattern.ownerLabel + "1"; } +BOOST_AUTO_TEST_CASE(DBtestTransaction) { + DB::Row rowPattern = create_default_row(); + rowPattern.data = RawBuffer(100, 20); + rowPattern.dataSize = rowPattern.data.size(); + rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1); + DB::Crypto::Transaction transaction(&m_db); -void checkDBIntegrity(const DBRow &rowPattern, DBCrypto &db) { + BOOST_REQUIRE_NO_THROW(m_db.saveRow(rowPattern)); + BOOST_REQUIRE_NO_THROW(transaction.rollback()); - BOOST_REQUIRE_NO_THROW(db.saveDBRow(rowPattern)); - DBRow selectRow = rowPattern; + DB::Crypto::RowOptional row_optional; + BOOST_REQUIRE_NO_THROW(row_optional = m_db.getRow(m_default_name, m_default_label, + DataType::BINARY_DATA)); + BOOST_CHECK_MESSAGE(!row_optional, "Row still present after rollback"); +} - DBCrypto::DBRowOptional optional_row; - BOOST_REQUIRE_NO_THROW(optional_row = db.getDBRow("alias", "label", DBDataType::BINARY_DATA)); - BOOST_REQUIRE_MESSAGE(optional_row, "Select didn't return any row"); +BOOST_AUTO_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); - compareDBRow(selectRow, rowPattern); - DBRow alias_duplicate = rowPattern; - alias_duplicate.data = createDefaultPass(); - alias_duplicate.dataSize = alias_duplicate.data.size(); + rowPattern.backendId = CryptoBackend::OpenSSL; + check_DB_integrity(rowPattern); - BOOST_REQUIRE_THROW(db.saveDBRow(alias_duplicate), DBCrypto::Exception::AliasExists); - BOOST_REQUIRE_NO_THROW(db.deleteDBRow("alias", "label")); + rowPattern.backendId = CryptoBackend::TrustZone; + check_DB_integrity(rowPattern); - DBCrypto::DBRowOptional row_optional; - BOOST_REQUIRE_NO_THROW(row_optional = db.getDBRow("alias", "label", DBDataType::BINARY_DATA)); - BOOST_REQUIRE_MESSAGE(!row_optional, "Select should not return row after deletion"); + rowPattern.backendId = CryptoBackend::None; + check_DB_integrity(rowPattern); } -BOOST_AUTO_TEST_SUITE(DBCRYPTO_TEST) -BOOST_AUTO_TEST_CASE(DBtestSimple) { +BOOST_AUTO_TEST_SUITE_END() - BOOST_CHECK(unlink(crypto_db) == 0 || errno == ENOENT); - DBCrypto db; - BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass)); - DBRow rowPattern = createDefaultRow(); - rowPattern.data = RawBuffer(32, 1); - rowPattern.dataSize = rowPattern.data.size(); - checkDBIntegrity(rowPattern, db); +BOOST_FIXTURE_TEST_SUITE(DBCRYPTO_PERF_TEST, DBFixture) + +BOOST_AUTO_TEST_CASE(DBperfAddNames) +{ + // actual test + performance_start("saveRow"); + { + generate_perf_DB(c_num_names_add_test, c_names_per_label); + } + performance_stop(c_num_names_add_test); } -BOOST_AUTO_TEST_CASE(DBtestBIG) { - BOOST_CHECK(unlink(crypto_db) == 0 || errno == ENOENT); - DBCrypto db; - BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass)); - DBRow rowPattern = createDefaultRow(); - rowPattern.data = createBigBlob(4096); - rowPattern.dataSize = rowPattern.data.size(); +BOOST_AUTO_TEST_CASE(DBperfLookupAliasByOwner) +{ + // prepare data + generate_perf_DB(c_num_names, c_names_per_label); + + unsigned int num_labels = c_num_names/c_names_per_label; + Name name; + Label label; + + // actual test - successful lookup + performance_start("getRow"); + for(unsigned int t=0; t + for(unsigned int l=0; l