summaryrefslogtreecommitdiff
path: root/tests/DBFixture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/DBFixture.cpp')
-rw-r--r--tests/DBFixture.cpp90
1 files changed, 46 insertions, 44 deletions
diff --git a/tests/DBFixture.cpp b/tests/DBFixture.cpp
index f4636139..9581a534 100644
--- a/tests/DBFixture.cpp
+++ b/tests/DBFixture.cpp
@@ -37,21 +37,21 @@ void DBFixture::performance_stop(long num_operations_performed)
BOOST_TEST_MESSAGE("\t<performance> average time per " << m_operation << ": " << time_elapsed_ms/num_operations_performed << "[ms]");
}
-void DBFixture::generate_alias(unsigned int id, std::string & output)
+void DBFixture::generate_name(unsigned int id, Name & output)
{
std::stringstream ss;
- ss << "alias_no_" << id;
+ ss << "name_no_" << id;
output = ss.str();
}
-void DBFixture::generate_label(unsigned int id, std::string & output)
+void DBFixture::generate_label(unsigned int id, Label & output)
{
std::stringstream ss;
ss << "label_no_" << id;
output = ss.str();
}
-void DBFixture::generate_perf_DB(unsigned int num_alias, unsigned int num_label)
+void DBFixture::generate_perf_DB(unsigned int num_name, unsigned int num_label)
{
// to speed up data creation - cache the row
DBRow rowPattern = create_default_row(DBDataType::BINARY_DATA);
@@ -59,33 +59,34 @@ void DBFixture::generate_perf_DB(unsigned int num_alias, unsigned int num_label)
rowPattern.dataSize = rowPattern.data.size();
rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1);
- for(unsigned int i=0; i<num_alias; i++)
+ for(unsigned int i=0; i<num_name; i++)
{
- generate_alias(i, rowPattern.alias);
+ generate_name(i, rowPattern.name);
generate_label(i/num_label, rowPattern.smackLabel);
BOOST_REQUIRE_NO_THROW(m_db.saveDBRow(rowPattern));
}
}
-long DBFixture::add_full_access_rights(unsigned int num_alias, unsigned int num_alias_per_label)
+long DBFixture::add_full_access_rights(unsigned int num_name, unsigned int num_name_per_label)
{
long iterations = 0;
- unsigned int num_labels = num_alias / num_alias_per_label;
- std::string alias, owner_label, accessor_label;
- for(unsigned int a=0; a<num_alias; a++)
+ unsigned int num_labels = num_name / num_name_per_label;
+ Name name;
+ Label owner_label, accessor_label;
+ for(unsigned int a=0; a<num_name; a++)
{
- generate_alias(a, alias);
- generate_label(a/num_alias_per_label, owner_label);
+ generate_name(a, name);
+ generate_label(a/num_name_per_label, owner_label);
for(unsigned int l=0; l<num_labels; l++)
{
// bypass the owner label
- if(l == (a/num_alias_per_label))
+ if(l == (a/num_name_per_label))
continue;
// add permission
generate_label(l, accessor_label);
- add_permission(alias, owner_label, accessor_label);
+ add_permission(name, owner_label, accessor_label);
iterations ++;
}
}
@@ -95,15 +96,15 @@ long DBFixture::add_full_access_rights(unsigned int num_alias, unsigned int num_
DBRow DBFixture::create_default_row(DBDataType type)
{
- return create_default_row(m_default_alias, m_default_label, type);
+ return create_default_row(m_default_name, m_default_label, type);
}
-DBRow DBFixture::create_default_row(const std::string &alias,
- const std::string &label,
+DBRow DBFixture::create_default_row(const Name &name,
+ const Label &label,
DBDataType type)
{
DBRow row;
- row.alias = alias;
+ row.name = name;
row.smackLabel = label;
row.exportable = 1;
row.algorithmType = DBCMAlgType::AES_GCM_256;
@@ -117,9 +118,9 @@ DBRow DBFixture::create_default_row(const std::string &alias,
void DBFixture::compare_row(const DBRow &lhs, const DBRow &rhs)
{
- BOOST_CHECK_MESSAGE(lhs.alias == rhs.alias,
- "Aliases didn't match! Got: " << rhs.alias
- << " , expected : " << lhs.alias);
+ BOOST_CHECK_MESSAGE(lhs.name == rhs.name,
+ "namees didn't match! Got: " << rhs.name
+ << " , expected : " << lhs.name);
BOOST_CHECK_MESSAGE(lhs.smackLabel == rhs.smackLabel,
"smackLabel didn't match! Got: " << rhs.smackLabel
@@ -144,65 +145,66 @@ void DBFixture::check_DB_integrity(const DBRow &rowPattern)
DBRow selectRow = rowPattern;
DBCrypto::DBRowOptional optional_row;
- BOOST_REQUIRE_NO_THROW(optional_row = m_db.getDBRow("alias", "label", DBDataType::BINARY_DATA));
+ BOOST_REQUIRE_NO_THROW(optional_row = m_db.getDBRow("name", "label", "label", DBDataType::BINARY_DATA));
BOOST_REQUIRE_MESSAGE(optional_row, "Select didn't return any row");
compare_row(selectRow, rowPattern);
- DBRow alias_duplicate = rowPattern;
- alias_duplicate.data = createDefaultPass();
- alias_duplicate.dataSize = alias_duplicate.data.size();
+ DBRow name_duplicate = rowPattern;
+ name_duplicate.data = createDefaultPass();
+ name_duplicate.dataSize = name_duplicate.data.size();
- BOOST_REQUIRE_THROW(m_db.saveDBRow(alias_duplicate), DBCrypto::Exception::AliasExists);
+ BOOST_REQUIRE_THROW(m_db.saveDBRow(name_duplicate), DBCrypto::Exception::NameExists);
unsigned int erased;
- BOOST_REQUIRE_NO_THROW(erased = m_db.deleteDBRow("alias", "label"));
+ BOOST_REQUIRE_NO_THROW(erased = m_db.deleteDBRow("name", "label", "label"));
BOOST_REQUIRE_MESSAGE(erased > 0, "Inserted row didn't exist in db");
DBCrypto::DBRowOptional row_optional;
- BOOST_REQUIRE_NO_THROW(row_optional = m_db.getDBRow("alias", "label", DBDataType::BINARY_DATA));
+ BOOST_REQUIRE_NO_THROW(row_optional = m_db.getDBRow("name", "label", "label", DBDataType::BINARY_DATA));
BOOST_REQUIRE_MESSAGE(!row_optional, "Select should not return row after deletion");
}
void DBFixture::insert_row()
{
- insert_row(m_default_alias, m_default_label);
+ insert_row(m_default_name, m_default_label);
}
-void DBFixture::insert_row(const std::string &alias, const std::string &accessor_label)
+void DBFixture::insert_row(const Name &name, const Label &owner_label)
{
- DBRow rowPattern = create_default_row(alias, accessor_label, DBDataType::BINARY_DATA);
+ DBRow rowPattern = create_default_row(name, owner_label, DBDataType::BINARY_DATA);
rowPattern.data = RawBuffer(100, 20);
rowPattern.dataSize = rowPattern.data.size();
rowPattern.tag = RawBuffer(AES_GCM_TAG_SIZE, 1);
BOOST_REQUIRE_NO_THROW(m_db.saveDBRow(rowPattern));
}
-void DBFixture::delete_row(const std::string &alias, const std::string &accessor_label)
+void DBFixture::delete_row(const Name &name, const Label &owner_label, const Label &accessor_label)
{
bool exit_flag;
- BOOST_REQUIRE_NO_THROW(exit_flag = m_db.deleteDBRow(alias, accessor_label));
- BOOST_REQUIRE_MESSAGE(true == exit_flag, "remove alias failed: no rows removed");
+ BOOST_REQUIRE_NO_THROW(exit_flag = m_db.deleteDBRow(name, owner_label, accessor_label));
+ BOOST_REQUIRE_MESSAGE(true == exit_flag, "remove name failed: no rows removed");
}
-void DBFixture::add_permission(const std::string &alias, const std::string &owner_label, const std::string &accessor_label)
+void DBFixture::add_permission(const Name &name, const Label &owner_label, const Label &accessor_label)
{
int ec;
- BOOST_REQUIRE_NO_THROW(ec = m_db.setAccessRights(owner_label,
- alias,
- accessor_label,
- CKM::AccessRight::AR_READ_REMOVE));
+ BOOST_REQUIRE_NO_THROW(ec = m_db.setAccessRights(name,
+ owner_label,
+ accessor_label,
+ CKM::AccessRight::AR_READ_REMOVE));
BOOST_REQUIRE_MESSAGE(CKM_API_SUCCESS == ec, "add permission failed: " << ec);
}
-void DBFixture::read_row_expect_fail(const std::string &alias, const std::string &accessor_label)
+void DBFixture::read_row_expect_fail(const Name &name, const Label &owner_label, const Label &accessor_label)
{
DBCrypto::DBRowOptional row;
- BOOST_REQUIRE_THROW(row = m_db.getDBRow(alias, accessor_label, DBDataType::BINARY_DATA), DBCrypto::Exception::PermissionDenied);
+ BOOST_REQUIRE_NO_THROW(row = m_db.getDBRow(name, owner_label, accessor_label, DBDataType::BINARY_DATA));
+ BOOST_REQUIRE(!row);
}
-void DBFixture::read_row_expect_success(const std::string &alias, const std::string &accessor_label)
+void DBFixture::read_row_expect_success(const Name &name, const Label &owner_label, const Label &accessor_label)
{
DBCrypto::DBRowOptional row;
- BOOST_REQUIRE_NO_THROW(row = m_db.getDBRow(alias, accessor_label, DBDataType::BINARY_DATA));
+ BOOST_REQUIRE_NO_THROW(row = m_db.getDBRow(name, owner_label, accessor_label, DBDataType::BINARY_DATA));
BOOST_REQUIRE_MESSAGE(row, "row is empty");
- BOOST_REQUIRE_MESSAGE(row->alias == alias, "alias is not valid");
+ BOOST_REQUIRE_MESSAGE(row->name == name, "name is not valid");
}