Adding/removing those macro calls will add/remove test cases they provide. To
change tests, change body of those macro calls. Registered tests are run within
group alphabetically.
+Those macros allow additional arguments which are classes with mandatory
+methods:
+* (constructor) ()
+ Called while registering test.
+ Should not throw any exceptions
+* init(const std::string &testName)
+ Called before test case function in order of classes passed to macro.
+ Should not be forked.
+ testName argument is name of the test (first macro argument).
+* finish(void)
+ called after test case function in reversed order of classes passed to
+ macro.
+ Should not be forked.
+Created instances of those classes may be accessed from within test case body
+as argument of test case funtion is
+ std::tuple<ClassesPassed> &optionalArgsTuple
dpl-test-framework
test_runner.h
"Wrong errno on opening " << " file");
}
+class Env
+{
+public:
+ Env() { ... }
+ void init(const std::string &testName) { ... }
+ void finish() { ... }
+ void doEnv() { ... }
+};
+
+class Restore
+{
+public:
+ Restore() { ... }
+ void init(const std::string &testName) { ... }
+ void finish() { ... }
+ void doRestore() { ... }
+};
+
+RUNNER_TEST(bar_optional_args, Env, Restore)
+{
+ std::get<0>(optionalArgsTuple).doEnv();
+ std::get<1>(optionalArgsTuple).doRestore();
+}
+
int main(int argc, char *argv[])
{
SummaryCollector::Register();
<filesystem path="/usr/bin/cynara-tests" exec_label="_" />
<filesystem path="/usr/bin/ckm-tests" exec_label="_" />
+ <filesystem path="/usr/bin/test-app-wgt" exec_label="User" />
<filesystem path="/usr/bin/test-app-efl" exec_label="User" />
<filesystem path="/usr/bin/test-app-osp" exec_label="User" />
</assign>
const AliasVector&,
const AliasVector&,
bool);
-} // namespace anonymous
+class CKMAsyncAPIEnv
+{
+public:
+ void init(const std::string &) {
+ reset_user_data(0, TEST_PASS);
+ reset_user_data(APP_UID, TEST_PASS);
+ }
+ void finish() {
+ remove_user_data(APP_UID);
+ remove_user_data(0);
+ }
+};
-RUNNER_TEST_GROUP_INIT(CKM_ASYNC_API);
+CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export";
+CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export";
-RUNNER_TEST(TA0000_init)
+CKM::PKCS12ShPtr loadPkcs()
{
- int temp;
- ControlShPtr control = Control::create();
+ std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+ std::istreambuf_iterator<char> begin(is), end;
+ std::vector<char> buff(begin, end);
+
+ CKM::RawBuffer buffer(buff.size());
+ memcpy(buffer.data(), buff.data(), buff.size());
+
+ auto pkcs = CKM::PKCS12::create(buffer, CKM::Password());
+ RUNNER_ASSERT_MSG(
+ NULL != pkcs.get(),
+ "Error in PKCS12::create()");
+
+ auto cert = pkcs->getCertificate();
+ RUNNER_ASSERT_MSG(
+ NULL != cert.get(),
+ "Error in PKCS12::getCertificate()");
+
+ auto key = pkcs->getKey();
+ RUNNER_ASSERT_MSG(
+ NULL != key.get(),
+ "Error in PKCS12::getKey()");
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->removeUserData(0)),
- "Error=" << CKM::ErrorToString(temp));
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->unlockUserKey(0, TEST_PASS)),
- "Error=" << CKM::ErrorToString(temp));
+ auto caVector = pkcs->getCaCertificateShPtrVector();
+ RUNNER_ASSERT_MSG(
+ 2 == caVector.size(),
+ "Wrong size of vector");
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->removeUserData(APP_UID)),
- "Error=" << ErrorToString(temp));
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->unlockUserKey(APP_UID, TEST_PASS)),
- "Error=" << ErrorToString(temp));
+ return pkcs;
}
+} // namespace anonymous
+
+
+RUNNER_TEST_GROUP_INIT(CKM_ASYNC_API);
+
// saveKey
-RUNNER_CHILD_TEST(TA0010_save_key_invalid_param)
+RUNNER_CHILD_TEST(TA0010_save_key_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::saveKey, "alias", KeyShPtr(), Policy());
}
-RUNNER_CHILD_TEST(TA0020_save_key_already_exists)
+RUNNER_CHILD_TEST(TA0020_save_key_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA0050_save_key_positive)
+RUNNER_CHILD_TEST(TA0050_save_key_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// saveCertificate
-RUNNER_CHILD_TEST(TA0110_save_cert_invalid_param)
+RUNNER_CHILD_TEST(TA0110_save_cert_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::saveCertificate, "alias", CertificateShPtr(), Policy());
}
-RUNNER_CHILD_TEST(TA0120_save_cert_already_exists)
+RUNNER_CHILD_TEST(TA0120_save_cert_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA0150_save_cert_positive)
+RUNNER_CHILD_TEST(TA0150_save_cert_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// saveData
-RUNNER_CHILD_TEST(TA0210_save_data_invalid_param)
+RUNNER_CHILD_TEST(TA0210_save_data_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::saveData, "alias", RawBuffer(), Policy());
}
-RUNNER_CHILD_TEST(TA0220_save_data_already_exists)
+RUNNER_CHILD_TEST(TA0220_save_data_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA0250_save_data_positive)
+RUNNER_CHILD_TEST(TA0250_save_data_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// removeKey
-RUNNER_CHILD_TEST(TA0310_remove_alias_invalid_param)
+RUNNER_CHILD_TEST(TA0310_remove_alias_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::removeAlias, "");
}
-RUNNER_CHILD_TEST(TA0330_remove_alias_unknown_alias)
+RUNNER_CHILD_TEST(TA0330_remove_alias_unknown_alias, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias");
}
-RUNNER_CHILD_TEST(TA0350_remove_key_positive)
+RUNNER_CHILD_TEST(TA0350_remove_key_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
}
-RUNNER_CHILD_TEST(TA0450_remove_cert_positive)
+RUNNER_CHILD_TEST(TA0450_remove_cert_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
}
-RUNNER_CHILD_TEST(TA0550_remove_data_positive)
+RUNNER_CHILD_TEST(TA0550_remove_data_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getKey
-RUNNER_CHILD_TEST(TA0610_get_key_invalid_param)
+RUNNER_CHILD_TEST(TA0610_get_key_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::getKey, "", "");
}
-RUNNER_CHILD_TEST(TA0630_get_key_unknown_alias)
+RUNNER_CHILD_TEST(TA0630_get_key_unknown_alias, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_negative(&ManagerAsync::getKey, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias", "");
}
-RUNNER_CHILD_TEST(TA0640_get_key_wrong_password)
+RUNNER_CHILD_TEST(TA0640_get_key_wrong_password, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
"wrong-password");
}
-RUNNER_CHILD_TEST(TA0650_get_key_positive)
+RUNNER_CHILD_TEST(TA0650_get_key_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getCertificate
-RUNNER_CHILD_TEST(TA0710_get_cert_invalid_param)
+RUNNER_CHILD_TEST(TA0710_get_cert_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::getCertificate, "", "");
}
-RUNNER_CHILD_TEST(TA0730_get_cert_unknown_alias)
+RUNNER_CHILD_TEST(TA0730_get_cert_unknown_alias, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
"");
}
-RUNNER_CHILD_TEST(TA0740_get_cert_wrong_password)
+RUNNER_CHILD_TEST(TA0740_get_cert_wrong_password, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
"wrong-password");
}
-RUNNER_CHILD_TEST(TA0750_get_cert_positive)
+RUNNER_CHILD_TEST(TA0750_get_cert_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getData
-RUNNER_CHILD_TEST(TA0810_get_data_invalid_param)
+RUNNER_CHILD_TEST(TA0810_get_data_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::getData, "", "");
}
-RUNNER_CHILD_TEST(TA0830_get_data_unknown_alias)
+RUNNER_CHILD_TEST(TA0830_get_data_unknown_alias, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias", "");
}
-RUNNER_CHILD_TEST(TA0840_get_data_wrong_password)
+RUNNER_CHILD_TEST(TA0840_get_data_wrong_password, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
"wrong-password");
}
-RUNNER_CHILD_TEST(TA0850_get_data_positive)
+RUNNER_CHILD_TEST(TA0850_get_data_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getKeyAliasVector
-RUNNER_CHILD_TEST(TA0910_get_key_alias_vector_invalid_param)
+RUNNER_CHILD_TEST(TA0910_get_key_alias_vector_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_no_observer(&ManagerAsync::getKeyAliasVector);
}
-RUNNER_CHILD_TEST(TA0950_get_key_alias_vector_positive)
+RUNNER_CHILD_TEST(TA0950_get_key_alias_vector_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getCertificateAliasVector
-RUNNER_CHILD_TEST(TA1010_get_cert_alias_vector_invalid_param)
+RUNNER_CHILD_TEST(TA1010_get_cert_alias_vector_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_no_observer(&ManagerAsync::getCertificateAliasVector);
}
-RUNNER_CHILD_TEST(TA1050_get_cert_alias_vector_positive)
+RUNNER_CHILD_TEST(TA1050_get_cert_alias_vector_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getDataAliasVector
-RUNNER_CHILD_TEST(TA1110_get_data_alias_vector_invalid_param)
+RUNNER_CHILD_TEST(TA1110_get_data_alias_vector_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_no_observer(&ManagerAsync::getDataAliasVector);
}
-RUNNER_CHILD_TEST(TA1150_get_data_alias_vector_positive)
+RUNNER_CHILD_TEST(TA1150_get_data_alias_vector_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// createKeyPairRSA
-RUNNER_CHILD_TEST(TA1210_create_key_pair_rsa_invalid_param)
+RUNNER_CHILD_TEST(TA1210_create_key_pair_rsa_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1220_create_key_pair_rsa_already_exists)
+RUNNER_CHILD_TEST(TA1220_create_key_pair_rsa_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1250_create_key_pair_rsa_positive)
+RUNNER_CHILD_TEST(TA1250_create_key_pair_rsa_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
}
// createKeyPairDSA
-RUNNER_CHILD_TEST(TA1270_create_key_pair_dsa_invalid_param)
+RUNNER_CHILD_TEST(TA1270_create_key_pair_dsa_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1280_create_key_pair_dsa_already_exists)
+RUNNER_CHILD_TEST(TA1280_create_key_pair_dsa_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1290_create_key_pair_dsa_positive)
+RUNNER_CHILD_TEST(TA1290_create_key_pair_dsa_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
}
// createKeyPairECDSA
-RUNNER_CHILD_TEST(TA1310_create_key_pair_ecdsa_invalid_param)
+RUNNER_CHILD_TEST(TA1310_create_key_pair_ecdsa_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1320_create_key_pair_ecdsa_already_exists)
+RUNNER_CHILD_TEST(TA1320_create_key_pair_ecdsa_already_exists, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
Policy());
}
-RUNNER_CHILD_TEST(TA1350_create_key_pair_ecdsa_positive)
+RUNNER_CHILD_TEST(TA1350_create_key_pair_ecdsa_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// getCertificateChain
-RUNNER_CHILD_TEST(TA1410_get_certificate_chain_invalid_param)
+RUNNER_CHILD_TEST(TA1410_get_certificate_chain_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
true);
}
-RUNNER_CHILD_TEST(TA1420_get_certificate_chain_negative)
+RUNNER_CHILD_TEST(TA1420_get_certificate_chain_negative, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
true);
}
-RUNNER_CHILD_TEST(TA1450_get_certificate_chain_positive)
+RUNNER_CHILD_TEST(TA1450_get_certificate_chain_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// createSignature
-RUNNER_CHILD_TEST(TA1510_create_signature_invalid_param)
+RUNNER_CHILD_TEST(TA1510_create_signature_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1520_create_signature_invalid_password)
+RUNNER_CHILD_TEST(TA1520_create_signature_invalid_password, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1550_create_signature_positive)
+RUNNER_CHILD_TEST(TA1550_create_signature_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// verifySignature
-RUNNER_CHILD_TEST(TA1610_verify_signature_invalid_param)
+RUNNER_CHILD_TEST(TA1610_verify_signature_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1620_verify_signature_invalid_password)
+RUNNER_CHILD_TEST(TA1620_verify_signature_invalid_password, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1630_verify_signature_invalid_message)
+RUNNER_CHILD_TEST(TA1630_verify_signature_invalid_message, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1640_verify_signature_invalid_signature)
+RUNNER_CHILD_TEST(TA1640_verify_signature_invalid_signature, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1650_verify_signature_wrong_key)
+RUNNER_CHILD_TEST(TA1650_verify_signature_wrong_key, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
RSAPaddingAlgorithm::PKCS1);
}
-RUNNER_CHILD_TEST(TA1660_verify_signature_positive)
+RUNNER_CHILD_TEST(TA1660_verify_signature_positive, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
// ocspCheck
-RUNNER_CHILD_TEST(TA1710_ocsp_check_invalid_param)
+RUNNER_CHILD_TEST(TA1710_ocsp_check_invalid_param, CKMAsyncAPIEnv)
{
test_no_observer(&ManagerAsync::ocspCheck, EMPTY_CERT_VECTOR);
test_invalid_param(&ManagerAsync::ocspCheck, EMPTY_CERT_VECTOR);
}
-RUNNER_CHILD_TEST(TA1720_ocsp_check_negative)
+RUNNER_CHILD_TEST(TA1720_ocsp_check_negative, CKMAsyncAPIEnv)
{
switch_to_storage_ocsp_user(TEST_LABEL);
"Verification should fail. Got: " << obs->m_ocspStatus);
}
-RUNNER_CHILD_TEST(TA1750_ocsp_check_positive)
+RUNNER_CHILD_TEST(TA1750_ocsp_check_positive, CKMAsyncAPIEnv)
{
switch_to_storage_ocsp_user(TEST_LABEL);
}
// setPermission
-RUNNER_CHILD_TEST(TA1810_allow_access_invalid_param)
+RUNNER_CHILD_TEST(TA1810_allow_access_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::setPermission, "alias", "", CKM::Permission::READ | CKM::Permission::REMOVE);
}
-RUNNER_TEST(TA1820_allow_access)
+RUNNER_TEST(TA1820_allow_access, CKMAsyncAPIEnv)
{
DBCleanup dbc;
CharPtr top_label = get_label();
}
// denyAccess
-RUNNER_CHILD_TEST(TA1910_deny_access_invalid_param)
+RUNNER_CHILD_TEST(TA1910_deny_access_invalid_param, CKMAsyncAPIEnv)
{
switch_to_storage_user(TEST_LABEL);
test_invalid_param(&ManagerAsync::setPermission, "alias", "", CKM::Permission::NONE);
}
-RUNNER_TEST(TA1920_deny_access)
+RUNNER_TEST(TA1920_deny_access, CKMAsyncAPIEnv)
{
DBCleanup dbc;
CharPtr top_label = get_label();
}
}
-namespace
-{
-CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export";
-CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export";
-}
-
-RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs)
+RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs, CKMAsyncAPIEnv)
{
DBCleanup dbc;
- auto manager = CKM::Manager::create();
- std::ifstream is("/usr/share/ckm-test/pkcs.p12");
- std::istreambuf_iterator<char> begin(is), end;
- std::vector<char> buff(begin, end);
-
- CKM::RawBuffer buffer(buff.size());
- memcpy(buffer.data(), buff.data(), buff.size());
-
- auto pkcs = CKM::PKCS12::create(buffer, CKM::Password());
- RUNNER_ASSERT_MSG(
- NULL != pkcs.get(),
- "Error in PKCS12::create()");
-
- auto cert = pkcs->getCertificate();
- RUNNER_ASSERT_MSG(
- NULL != cert.get(),
- "Error in PKCS12::getCertificate()");
-
- auto key = pkcs->getKey();
- RUNNER_ASSERT_MSG(
- NULL != key.get(),
- "Error in PKCS12::getKey()");
-
- auto caVector = pkcs->getCaCertificateShPtrVector();
- RUNNER_ASSERT_MSG(
- 2 == caVector.size(),
- "Wrong size of vector");
+ auto pkcs = loadPkcs();
// save to the CKM
CKM::Policy exportable;
CKM::Policy notExportable(CKM::Password(), false);
test_positive(&ManagerAsync::savePKCS12,
- alias_PKCS_exportable,
+ dbc.alias(alias_PKCS_exportable.c_str()),
pkcs,
exportable,
exportable);
test_negative(&ManagerAsync::savePKCS12,
CKM_API_ERROR_DB_ALIAS_EXISTS,
- alias_PKCS_exportable,
+ dbc.alias(alias_PKCS_exportable.c_str()),
pkcs,
exportable,
exportable);
test_positive(&ManagerAsync::savePKCS12,
- alias_PKCS_not_exportable,
+ dbc.alias(alias_PKCS_not_exportable.c_str()),
pkcs,
notExportable,
notExportable);
test_negative(&ManagerAsync::savePKCS12,
CKM_API_ERROR_DB_ALIAS_EXISTS,
- alias_PKCS_not_exportable,
+ dbc.alias(alias_PKCS_not_exportable.c_str()),
pkcs,
notExportable,
notExportable);
}
-RUNNER_TEST(TA2010_PKCS_get)
+RUNNER_TEST(TA2010_PKCS_get, CKMAsyncAPIEnv)
{
DBCleanup dbc;
- auto manager = CKM::Manager::create();
+
+ auto pkcs = loadPkcs();
+
+ // save to the CKM
+ CKM::Policy exportable;
+ CKM::Policy notExportable(CKM::Password(), false);
+
+ test_positive(&ManagerAsync::savePKCS12,
+ dbc.alias(alias_PKCS_exportable.c_str()),
+ pkcs,
+ exportable,
+ exportable);
+ test_positive(&ManagerAsync::savePKCS12,
+ dbc.alias(alias_PKCS_not_exportable.c_str()),
+ pkcs,
+ notExportable,
+ notExportable);
// fail - no entry
test_negative(&ManagerAsync::getPKCS12,
2 == caVector.size(),
"Wrong size of vector");
}
-
-RUNNER_TEST(TA9999_deinit)
-{
- int temp;
- ControlShPtr control = Control::create();
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->lockUserKey(APP_UID)),
- "Error=" << ErrorToString(temp));
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->removeUserData(APP_UID)),
- "Error=" << ErrorToString(temp));
-
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->lockUserKey(0)),
- "Error=" << ErrorToString(temp));
- RUNNER_ASSERT_MSG(CKM_API_SUCCESS == (temp = control->removeUserData(0)),
- "Error=" << ErrorToString(temp));
-}
// tries to use admin API as a user
RUNNER_CHILD_TEST(T3110_control_allow_access_as_user)
{
+ RUNNER_IGNORED_MSG("Disabled until labeled sockets not available");
+
switch_to_storage_user(TEST_LABEL);
int ret = ckmc_set_permission_by_adm(USER_ROOT, aliasWithLabel("owner", "alias").c_str(), "accessor", CKMC_PERMISSION_READ);
RUNNER_ASSERT_MSG(CKMC_ERROR_PERMISSION_DENIED == ret,
// tries to use admin API as a user
RUNNER_CHILD_TEST(T3111_control_allow_access_as_user)
{
+ RUNNER_IGNORED_MSG("Disabled until labeled sockets not available");
+
switch_to_storage_user(TEST_LABEL);
int ret = ckmc_set_permission_by_adm(USER_ROOT, aliasWithLabel("owner", "alias").c_str(), "accessor", CKMC_PERMISSION_NONE);
RUNNER_ASSERT_MSG(CKMC_ERROR_PERMISSION_DENIED == ret,
RUNNER_ASSERT_MSG(time(0) > 1405343457,
"Time error. Device date is before 14th of July 2014. You must set proper time on device before run this tests!");
+ ScopedLabel sl("System");
struct hostent* he = gethostbyname("google.com");
RUNNER_ASSERT_MSG(he != NULL, "There is problem with translate domain google.com into ip address. Probably network "
RUNNER_TEST_GROUP_INIT(T151_CKM_STORAGE_PERNAMENT_TESTS);
+namespace {
+CKM::Alias certeeAlias("CertEE");
+CKM::Alias certimAlias("CertIM");
+}
RUNNER_CHILD_TEST(T1510_init_unlock_key)
{
- int tmp;
+ reset_user_data(USER_TEST, "strong-password");
+
+ // initial DB feed
AccessProvider ap("my-label");
- ap.allowAPI("key-manager::api-control", "rw");
+ ap.allowAPI("key-manager::api-storage", "rw");
ap.applyAndSwithToUser(USER_TEST, GROUP_APP);
- auto control = CKM::Control::create();
- RUNNER_ASSERT_MSG(
- CKM_API_SUCCESS == (tmp = control->unlockUserKey(USER_TEST, "strong-password")),
- "Error=" << CKM::ErrorToString(tmp));
+ auto manager = CKM::Manager::create();
+ auto certee = TestData::getTestCertificate(TestData::MBANK);
+ auto certim = TestData::getTestCertificate(TestData::SYMANTEC);
+ RUNNER_ASSERT(CKM_API_SUCCESS == manager->saveCertificate(certeeAlias, certee, CKM::Policy()));
+ RUNNER_ASSERT(CKM_API_SUCCESS == manager->saveCertificate(certimAlias, certim, CKM::Policy()));
+}
+
+RUNNER_TEST(T1511_restart_CKM)
+{
+ // restart CKM
+ stop_service(MANAGER);
+ start_service(MANAGER);
+ unlock_user_data(USER_TEST, "strong-password");
}
-RUNNER_CHILD_TEST(T1511_insert_data)
+RUNNER_CHILD_TEST(T1512_check_data_exists)
{
+ // actual test
AccessProvider ap("my-label");
ap.allowAPI("key-manager::api-storage", "rw");
ap.applyAndSwithToUser(USER_TEST, GROUP_APP);
+ auto manager = CKM::Manager::create();
auto certee = TestData::getTestCertificate(TestData::MBANK);
auto certim = TestData::getTestCertificate(TestData::SYMANTEC);
-
- auto manager = CKM::Manager::create();
- int status1 = manager->saveCertificate(CKM::Alias("CertEE"), certee, CKM::Policy());
- int status2 = manager->saveCertificate(CKM::Alias("CertIM"), certim, CKM::Policy());
-
+ int status1 = manager->saveCertificate(certeeAlias, certee, CKM::Policy());
+ int status2 = manager->saveCertificate(certimAlias, certim, CKM::Policy());
RUNNER_ASSERT_MSG(
CKM_API_ERROR_DB_ALIAS_EXISTS == status1,
"Certificate should be in database already. Error=" << CKM::ErrorToString(status1));
-
RUNNER_ASSERT_MSG(
CKM_API_ERROR_DB_ALIAS_EXISTS == status2,
"Certificate should be in database already. Error=" << CKM::ErrorToString(status2));
}
-RUNNER_CHILD_TEST(T1519_deinit)
+RUNNER_TEST(T1519_deinit)
{
- int tmp;
- AccessProvider ap("my-label");
- ap.allowAPI("key-manager::api-control", "rw");
- ap.applyAndSwithToUser(USER_APP, GROUP_APP);
-
- auto control = CKM::Control::create();
- RUNNER_ASSERT_MSG(
- CKM_API_SUCCESS == (tmp = control->lockUserKey(USER_TEST)),
- "Error=" << CKM::ErrorToString(tmp));
+ remove_user_data(USER_TEST);
}
cm[TestData::EQUIFAX] = std::make_pair(raw_base64, createCert(raw_base64));
}
- // GOOGLE_COM, *.google.com - signed by GIAG2, expires 12 May 2015
+ // GOOGLE_COM, *.google.com - signed by GIAG2, expires 21 Jul 2015
{
std::string raw_base64 = std::string(
"-----BEGIN CERTIFICATE-----\n"
- "MIIGxTCCBa2gAwIBAgIIBIsVw6gw3hgwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE\n"
+ "MIIGxTCCBa2gAwIBAgIIF4oWRtoEsZgwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE\n"
"BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl\n"
- "cm5ldCBBdXRob3JpdHkgRzIwHhcNMTUwMjExMTI0NzAyWhcNMTUwNTEyMDAwMDAw\n"
+ "cm5ldCBBdXRob3JpdHkgRzIwHhcNMTUwNDIyMTM0NzM5WhcNMTUwNzIxMDAwMDAw\n"
"WjBmMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN\n"
"TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEVMBMGA1UEAwwMKi5n\n"
- "b29nbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEmokK6sw/osw7yrkc\n"
- "rSJZk5FAod6yrCptxyq7AssrJbcTCpuxGbG9Ip6/jR8QP4109kZxadoaZ/0ICOh5\n"
- "bHx44qOCBF0wggRZMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjCCAyYG\n"
+ "b29nbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeI/HfDmnVdpQ4JNA\n"
+ "9z7aYLzV30SZp0EFfrC5iV4l4AVNRfnCjOdYrdx387n9mhVPghWVWDkb05JtRZqr\n"
+ "9vgwMqOCBF0wggRZMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjCCAyYG\n"
"A1UdEQSCAx0wggMZggwqLmdvb2dsZS5jb22CDSouYW5kcm9pZC5jb22CFiouYXBw\n"
"ZW5naW5lLmdvb2dsZS5jb22CEiouY2xvdWQuZ29vZ2xlLmNvbYIWKi5nb29nbGUt\n"
"YW5hbHl0aWNzLmNvbYILKi5nb29nbGUuY2GCCyouZ29vZ2xlLmNsgg4qLmdvb2ds\n"
"YmWCC3lvdXR1YmUuY29tghR5b3V0dWJlZWR1Y2F0aW9uLmNvbTALBgNVHQ8EBAMC\n"
"B4AwaAYIKwYBBQUHAQEEXDBaMCsGCCsGAQUFBzAChh9odHRwOi8vcGtpLmdvb2ds\n"
"ZS5jb20vR0lBRzIuY3J0MCsGCCsGAQUFBzABhh9odHRwOi8vY2xpZW50czEuZ29v\n"
- "Z2xlLmNvbS9vY3NwMB0GA1UdDgQWBBShZRhQFOqlCCt51oEJBD94sL7K4zAMBgNV\n"
+ "Z2xlLmNvbS9vY3NwMB0GA1UdDgQWBBTgUFAZJ8fMjqEj8KpwMspvje7cSzAMBgNV\n"
"HRMBAf8EAjAAMB8GA1UdIwQYMBaAFErdBhYbvPZotXb1gba7Yhq6WoEvMBcGA1Ud\n"
"IAQQMA4wDAYKKwYBBAHWeQIFATAwBgNVHR8EKTAnMCWgI6Ahhh9odHRwOi8vcGtp\n"
- "Lmdvb2dsZS5jb20vR0lBRzIuY3JsMA0GCSqGSIb3DQEBBQUAA4IBAQBOQBrolcUp\n"
- "UFh/5O369pXbuxDZajpSKAjX4Zu6L5LxS9NQRuWqheWNsNcZMRzZ6dP6xpeqf522\n"
- "zUjzUEzDCOaxCbccakucnXUvg3/m5qgYhxUmLdZjXZ53mTCy4tHbswQrwnxZH+t+\n"
- "Y4rlJFr4bzPNPx7ucB7wRvxFGCjWXflK1JpgXmUcjFFu8/xrlqJdCwmrjEOJaVRq\n"
- "urh11t2o4N/DjdboKWBdv+reuijPjzJTKmTbjuZU/bty6COIqtu8vWD39xRCK2y+\n"
- "W6und7oGKIEvisrLIoHRRgBPfiFBxuzLbvOg/mGbz34pSuBJEzMxrAbkOnGWEQOm\n"
- "B3KPgoV0lPFo\n"
+ "Lmdvb2dsZS5jb20vR0lBRzIuY3JsMA0GCSqGSIb3DQEBBQUAA4IBAQA2YKaE9hJu\n"
+ "96a81VC53Qrk1JbhMeVRL+uLsidRNK2uBCzJs4zkKT8QTp2m0w792djprAMDuzKx\n"
+ "GUaVj9TyAX5b1ObcRh2cvom1bzakjWpr1sLW+71vPIeRK8XZvbkVpvgbUF5pQFda\n"
+ "xZmS49iTG4+8yH6jSnlC/GLSFBihIYmKhU4HSOvzhRBbMNc6ldfvyomE0DtGJXDs\n"
+ "qOQqfwpyUopGZIIiETLw3PQrdrXSxhoTaVdvL0V9+SGS4Dp7D+WsNl23a7nhxUv3\n"
+ "PSl6FTRcANKzXflSpdbu9BsuD78KQNnK2cl0mlcE8PETflMFjogi7OhEEQitwp3S\n"
+ "043LZ7LBy0m5\n"
"-----END CERTIFICATE-----\n");
cm[TestData::GOOGLE_COM] = std::make_pair(raw_base64, createCert(raw_base64));
}
SYMANTEC, // SYMANTEC, signed by VERISIGN, expires 30 Oct 2023
GEOTRUST, // GEOTRUST, GeoTrust Global CA - signed by EQUIFAX, expires 21 Aug 2018
EQUIFAX, // EQUIFAX (root CA), expires 22 Aug 2018
- GOOGLE_COM, // GOOGLE_COM, *.google.com - signed by GIAG2, expires 12 May 2015
+ GOOGLE_COM, // GOOGLE_COM, *.google.com - signed by GIAG2, expires 21 Jul 2015
// footer - last element in the set
NO_CERT
#define _TESTS_COMMON_H_
#include <sys/smack.h>
+#include <dpl/test/test_case_extended.h>
#include <dpl/test/test_runner.h>
#include <dpl/test/test_runner_child.h>
#include <dpl/test/test_runner_multiprocess.h>
#include <privilege-control.h>
#include <sys/smack.h>
#include <string>
+#include <tuple>
#include <errno.h>
#include <string.h>
void symlinkSafe(const std::string &targetPath, const std::string &linkPath);
void removeDir(const std::string &path);
-#define RUNNER_TEST_SMACK(Proc) \
- void Proc(); \
- static int Static##Proc##Init() \
- { \
- if(smack_check()) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc()
-
-#define RUNNER_TEST_NOSMACK(Proc) \
- void Proc(); \
- static int Static##Proc##Init() \
- { \
- if(!(smack_check())) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc()
-
-#define RUNNER_CHILD_TEST_SMACK(Proc) \
- void Proc(); \
- void Proc##Child(); \
- static int Static##Proc##Init() \
- { \
- if(smack_check()) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunChildProc(&Proc##Child); \
- } \
- void Proc##Child()
-
-#define RUNNER_CHILD_TEST_NOSMACK(Proc) \
- void Proc(); \
- void Proc##Child(); \
- static int Static##Proc##Init() \
- { \
- if(!(smack_check())) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunChildProc(&Proc##Child); \
- } \
- void Proc##Child()
-
-#define RUNNER_MULTIPROCESS_TEST_SMACK(Proc) \
- void Proc(); \
- void Proc##Multi(); \
- static int Static##Proc##Init() \
- { \
- if(smack_check()) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunMultiProc(&Proc##Multi); \
- } \
- void Proc##Multi()
-
-#define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc) \
- void Proc(); \
- void Proc##Multi(); \
- static int Static##Proc##Init() \
- { \
- if(!(smack_check())) \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunMultiProc(&Proc##Multi); \
- } \
- void Proc##Multi()
+
+#define RUNNER_TEST_SMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
+
+#define RUNNER_TEST_NOSMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (!smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
+
+#define RUNNER_CHILD_TEST_SMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunChildProc(std::bind(Proc##Child, optionalArgsTuple)); \
+ } \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
+
+#define RUNNER_CHILD_TEST_NOSMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (!smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunChildProc(std::bind(Proc##Child, optionalArgsTuple)); \
+ } \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
+
+#define RUNNER_MULTIPROCESS_TEST_SMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunMultiProc(std::bind(Proc##Multi, optionalArgsTuple)); \
+ } \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
+
+#define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ if (!smack_check()) \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunMultiProc(std::bind(Proc##Multi, optionalArgsTuple)); \
+ } \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
namespace DB {
*/
#include <cynara_test_commons.h>
-#include <cynara_test_env.h>
#include <cynara_test_file_operations.h>
#include <cynara_test_cynara_mask.h>
}
-void environmentWrap(const char *testName, const std::function<void(void)> &func)
-{
- CynaraTestEnv env(testName);
- env.save();
- env.loadDefaultDatabase();
-
- try {
- func();
- } catch (const DPL::Test::TestException &e) {
- env.restore();
- throw;
- } catch (const DPL::Exception &e) {
- env.restore();
- throw;
- } catch (const std::exception &e) {
- env.restore();
- throw;
- } catch (...) {
- env.restore();
- throw std::runtime_error("Unknown exception");
- }
- env.restore();
-}
-
void loadServicePlugins(const DirectoryPaths &pluginDirectories)
{
CynaraMask mask;
#ifndef CYNARA_TEST_COMMONS_H_
#define CYNARA_TEST_COMMONS_H_
-#include <functional>
#include <string>
#include <vector>
+#include <cynara_test_env.h>
+
+#include <dpl/test/test_runner.h>
+
namespace CynaraTestConsts
{
const char *m_privilege;
};
-void environmentWrap(const char *testName, const std::function<void(void)> &func);
-
#define RUN_CYNARA_TEST(Proc) \
- RUNNER_TEST(Proc) \
- { \
- environmentWrap(#Proc, Proc##_func); \
- }
+ RUNNER_TEST(Proc, CynaraTestEnv) \
typedef std::vector<std::string> DirectoryPaths;
void loadServicePlugins(const DirectoryPaths &pluginDirectories);
using namespace FileOperations;
-CynaraTestEnv::CynaraTestEnv(const char *dirName)
+CynaraTestEnv::CynaraTestEnv()
: m_dbPresent(false)
{
- m_saveDir = TMP_DIR + "/" + dirName;
- m_dbSaveDir = m_saveDir + "/db";
- m_pluginsSaveDir = m_saveDir + "/plugins";
- m_defaultDir = "/etc/security-tests/db_patterns/default";
}
CynaraTestEnv::~CynaraTestEnv()
{
}
-void CynaraTestEnv::save()
+void CynaraTestEnv::init(const std::string &testName)
{
+ m_saveDir = TMP_DIR + "/" + testName;
+ m_dbSaveDir = m_saveDir + "/db";
+ m_pluginsSaveDir = m_saveDir + "/plugins";
+ m_defaultDir = "/etc/security-tests/db_patterns/default";
+
CynaraMask mask;
removeDirFiles(m_dbSaveDir);
}
makeDir(m_pluginsSaveDir);
copyCynaraFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR, m_pluginsSaveDir);
+ unmaskedLoadDefaultDatabase();
}
-void CynaraTestEnv::restore()
+void CynaraTestEnv::finish()
{
CynaraMask mask;
removeDirIfExists(m_saveDir);
}
-void CynaraTestEnv::loadDefaultDatabase()
+void CynaraTestEnv::unmaskedLoadDefaultDatabase()
{
- CynaraMask mask;
-
if (m_dbPresent) {
removeDirFiles(CynaraTestConsts::DB_DIR);
copyCynaraFiles(m_defaultDir, CynaraTestConsts::DB_DIR);
}
}
+
+void CynaraTestEnv::loadDefaultDatabase()
+{
+ CynaraMask mask;
+ unmaskedLoadDefaultDatabase();
+}
class CynaraTestEnv
{
public:
- explicit CynaraTestEnv(const char *dirName);
- virtual ~CynaraTestEnv();
-
- void save();
- void restore();
+ explicit CynaraTestEnv();
+ ~CynaraTestEnv();
+ void init(const std::string &testName);
+ void finish();
void loadDefaultDatabase();
private:
+ void unmaskedLoadDefaultDatabase();
std::string m_saveDir;
std::string m_dbSaveDir;
std::string m_pluginsSaveDir;
using namespace CynaraTestAdmin;
using namespace CynaraTestClient;
-void tc01_cynara_initialize_func()
+RUNNER_TEST_GROUP_INIT(cynara_tests)
+
+RUN_CYNARA_TEST(tc01_cynara_initialize)
{
Client();
}
-void tc02_admin_initialize_func()
+RUN_CYNARA_TEST(tc02_admin_initialize)
{
Admin admin;
}
-void tc03_cynara_check_invalid_params_func()
+RUN_CYNARA_TEST(tc03_cynara_check_invalid_params)
{
Client cynara;
admin.setPolicies(cp, CYNARA_API_INVALID_PARAM);
}
-void tc04_admin_set_policies_invalid_params_func()
+RUN_CYNARA_TEST(tc04_admin_set_policies_invalid_params)
{
Admin admin;
checkInvalidPolicy(admin, bucket, client, user, privilege, resultNone, resultExtra);
}
-void tc05_admin_set_bucket_invalid_params_func()
+RUN_CYNARA_TEST(tc05_admin_set_bucket_invalid_params)
{
Admin admin;
admin.setBucket(bucket, operationNone, extra, CYNARA_API_OPERATION_NOT_ALLOWED);
}
-void tc06_cynara_check_empty_admin1_func()
+RUN_CYNARA_TEST(tc06_cynara_check_empty_admin1)
{
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc06_cynara_check_empty_admin2_func()
+RUN_CYNARA_TEST(tc06_cynara_check_empty_admin2)
{
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc07_admin_set_bucket_admin_allow_deny_func()
+RUN_CYNARA_TEST(tc07_admin_set_bucket_admin_allow_deny)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc08_admin_set_policies_allow_remove1_func()
+RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove1)
{
Admin admin;
Client cynara;
cynara.check(data[1][0], session, data[1][1], data[1][2], CYNARA_API_ACCESS_DENIED);
}
-void tc08_admin_set_policies_allow_remove2_func()
+RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove2)
{
Admin admin;
Client cynara;
cynara.check(data[1][0], session, data[1][1], data[1][2], CYNARA_API_ACCESS_DENIED);
}
-void tc08_admin_set_policies_allow_remove3_func()
+RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove3)
{
Admin admin;
Client cynara;
admin.setPolicies(cp);
}
-void tc09_admin_set_policies_wildcard_accesses_func()
+RUN_CYNARA_TEST(tc09_admin_set_policies_wildcard_accesses)
{
const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *session = "session09";
checkAllDeny(data, session);
}
-void tc10_admin_change_extra_bucket_func()
+RUN_CYNARA_TEST(tc10_admin_change_extra_bucket)
{
Admin admin;
Client cynara;
admin.setBucket(bucket, CYNARA_ADMIN_DELETE, extra);
}
-void tc11_admin_bucket_not_found_func()
+RUN_CYNARA_TEST(tc11_admin_bucket_not_found)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc12_admin_delete_bucket_with_policies_pointing_to_it_func()
+RUN_CYNARA_TEST(tc12_admin_delete_bucket_with_policies_pointing_to_it)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc13_admin_set_policies_to_extra_bucket_func()
+RUN_CYNARA_TEST(tc13_admin_set_policies_to_extra_bucket)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc14_admin_set_policies_integrity_func()
+RUN_CYNARA_TEST(tc14_admin_set_policies_integrity)
{
const char *bucketDefault = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *bucket = "bucket14";
}
}
-void tc15_admin_set_bucket_admin_none1_func()
+RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none1)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_ALLOWED);
}
-void tc15_admin_set_bucket_admin_none2_func()
+RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none2)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_DENIED);
}
-void tc15_admin_set_bucket_admin_none3_func()
+RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none3)
{
Admin admin;
Client cynara;
cynara.check(client, session, user, privilege, CYNARA_API_ACCESS_ALLOWED);
}
-void tc16_admin_check_single_bucket_func()
+RUN_CYNARA_TEST(tc16_admin_check_single_bucket)
{
const char *bucketDefault = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *client = "client16";
CYNARA_ADMIN_ALLOW, nullptr, CYNARA_API_SUCCESS);
}
-void tc17_admin_check_nested_bucket_func()
+RUN_CYNARA_TEST(tc17_admin_check_nested_bucket)
{
const char *bucketDefault = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *bucket = "bucket17";
CYNARA_ADMIN_ALLOW, nullptr, CYNARA_API_SUCCESS);
}
-void tc18_admin_check_multiple_matches_func()
+RUN_CYNARA_TEST(tc18_admin_check_multiple_matches)
{
const char *bucketDefault = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *client = "client18";
check(CYNARA_ADMIN_ALLOW);
}
-void tc19_admin_check_none_bucket_func()
+RUN_CYNARA_TEST(tc19_admin_check_none_bucket)
{
const char *bucketDefault = CYNARA_ADMIN_DEFAULT_BUCKET;
const char *bucket1 = "bucket19_a";
CYNARA_ADMIN_ALLOW, nullptr, CYNARA_API_SUCCESS);
}
-void tc20_admin_list_empty_bucket_func()
+RUN_CYNARA_TEST(tc20_admin_list_empty_bucket)
{
const char *emptyBucket = "empty_bucket20";
const char *client = "client20";
admin.listPolicies(emptyBucket, client, user, privilege, emptyPolicies);
}
-void tc21_admin_list_no_bucket_func()
+RUN_CYNARA_TEST(tc21_admin_list_no_bucket)
{
const char *emptyBucket = "empty_bucket21";
const char *notExistingBucket = "not_existing_bucket21";
CYNARA_API_BUCKET_NOT_FOUND);
}
-void tc22_admin_list_bucket_func()
+RUN_CYNARA_TEST(tc22_admin_list_bucket)
{
const char *bucket = "bucket22";
const char *emptyBucket = "empty_bucket22";
admin.listPolicies(bucket, client, wildcard, any, expectedPolicies);
}
-void tc23_admin_erase_empty_bucket_func()
+RUN_CYNARA_TEST(tc23_admin_erase_empty_bucket)
{
const char *emptyBucket = "empty_bucket23";
const char *client = "client23";
admin.erasePolicies(emptyBucket, recursive, client, user, privilege);
}
-void tc24_admin_erase_no_bucket_func()
+RUN_CYNARA_TEST(tc24_admin_erase_no_bucket)
{
const char *emptyBucket = "empty_bucket24";
const char *notExistingBucket = "not_existing_bucket24";
CYNARA_API_BUCKET_NOT_FOUND);
}
-void tc25_admin_erase_single_bucket_func()
+RUN_CYNARA_TEST(tc25_admin_erase_single_bucket)
{
const char *bucket = "bucket25";
const char *emptyBucket = "empty_bucket25";
}
}
-void tc26_admin_erase_recursive_not_linked_buckets_func()
+RUN_CYNARA_TEST(tc26_admin_erase_recursive_not_linked_buckets)
{
const char *bucket = "bucket26";
const char *subBucket = "sub_bucket26";
}
}
-void tc27_admin_erase_recursive_linked_buckets_func()
+RUN_CYNARA_TEST(tc27_admin_erase_recursive_linked_buckets)
{
const char *bucket = "bucket27";
const char *subBucket = "sub_bucket27";
}
}
-void tc28_admin_erase_non_recursive_linked_buckets_func()
+RUN_CYNARA_TEST(tc28_admin_erase_non_recursive_linked_buckets)
{
const char *bucket = "bucket28";
const char *subBucket = "sub_bucket28";
}
}
-void tc29_admin_erase_recursive_from_sub_bucket_func()
+RUN_CYNARA_TEST(tc29_admin_erase_recursive_from_sub_bucket)
{
const char *bucket = "bucket29";
const char *subBucket = "sub_bucket29";
admin.listPoliciesDescriptions(expectedDescriptions);
}
-void tc30_admin_list_descriptions_no_plugins_func()
+RUN_CYNARA_TEST(tc30_admin_list_descriptions_no_plugins)
{
testPlugins({});
}
-void tc31_admin_list_descriptions_1_plugin_single_policy_func()
+RUN_CYNARA_TEST(tc31_admin_list_descriptions_1_plugin_single_policy)
{
testPlugins({CynaraTestPlugins::SINGLE_POLICY});
}
-void tc32_admin_list_descriptions_1_plugin_multiple_policy_func()
+RUN_CYNARA_TEST(tc32_admin_list_descriptions_1_plugin_multiple_policy)
{
testPlugins({CynaraTestPlugins::MULTIPLE_POLICY});
}
-void tc33_admin_list_descriptions_multiple_plugins_func()
+RUN_CYNARA_TEST(tc33_admin_list_descriptions_multiple_plugins)
{
testPlugins({CynaraTestPlugins::SINGLE_POLICY,
CynaraTestPlugins::MULTIPLE_POLICY});
}
-
-RUNNER_TEST_GROUP_INIT(cynara_tests)
-
-RUN_CYNARA_TEST(tc01_cynara_initialize)
-RUN_CYNARA_TEST(tc02_admin_initialize)
-RUN_CYNARA_TEST(tc03_cynara_check_invalid_params)
-RUN_CYNARA_TEST(tc04_admin_set_policies_invalid_params)
-RUN_CYNARA_TEST(tc05_admin_set_bucket_invalid_params)
-RUN_CYNARA_TEST(tc06_cynara_check_empty_admin1)
-RUN_CYNARA_TEST(tc06_cynara_check_empty_admin2)
-RUN_CYNARA_TEST(tc07_admin_set_bucket_admin_allow_deny)
-RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove1)
-RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove2)
-RUN_CYNARA_TEST(tc08_admin_set_policies_allow_remove3)
-RUN_CYNARA_TEST(tc09_admin_set_policies_wildcard_accesses)
-RUN_CYNARA_TEST(tc10_admin_change_extra_bucket)
-RUN_CYNARA_TEST(tc11_admin_bucket_not_found)
-RUN_CYNARA_TEST(tc12_admin_delete_bucket_with_policies_pointing_to_it)
-RUN_CYNARA_TEST(tc13_admin_set_policies_to_extra_bucket)
-RUN_CYNARA_TEST(tc14_admin_set_policies_integrity)
-RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none1)
-RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none2)
-RUN_CYNARA_TEST(tc15_admin_set_bucket_admin_none3)
-RUN_CYNARA_TEST(tc16_admin_check_single_bucket)
-RUN_CYNARA_TEST(tc17_admin_check_nested_bucket)
-RUN_CYNARA_TEST(tc18_admin_check_multiple_matches)
-RUN_CYNARA_TEST(tc19_admin_check_none_bucket)
-RUN_CYNARA_TEST(tc20_admin_list_empty_bucket)
-RUN_CYNARA_TEST(tc21_admin_list_no_bucket)
-RUN_CYNARA_TEST(tc22_admin_list_bucket)
-RUN_CYNARA_TEST(tc23_admin_erase_empty_bucket)
-RUN_CYNARA_TEST(tc24_admin_erase_no_bucket)
-RUN_CYNARA_TEST(tc25_admin_erase_single_bucket)
-RUN_CYNARA_TEST(tc26_admin_erase_recursive_not_linked_buckets)
-RUN_CYNARA_TEST(tc27_admin_erase_recursive_linked_buckets)
-RUN_CYNARA_TEST(tc28_admin_erase_non_recursive_linked_buckets)
-RUN_CYNARA_TEST(tc29_admin_erase_recursive_from_sub_bucket)
-RUN_CYNARA_TEST(tc30_admin_list_descriptions_no_plugins)
-RUN_CYNARA_TEST(tc31_admin_list_descriptions_1_plugin_single_policy)
-RUN_CYNARA_TEST(tc32_admin_list_descriptions_1_plugin_multiple_policy)
-RUN_CYNARA_TEST(tc33_admin_list_descriptions_multiple_plugins)
sendClientRequest, hangOnGetRequest);
}
-void tcag01_set_agent_type_policy_without_plugin_func()
+RUNNER_TEST_GROUP_INIT(cynara_agent_tests)
+
+RUN_CYNARA_TEST(tcag01_set_agent_type_policy_without_plugin_func)
{
loadServicePlugins(DirectoryPaths());
setAgentPolicy(CYNARA_API_INVALID_PARAM);
}
-void tcag02_set_agent_type_policy_with_plugin_loaded_func()
+RUN_CYNARA_TEST(tcag02_set_agent_type_policy_with_plugin_loaded_func)
{
loadAgentPlugin();
setAgentPolicy();
}
-void tcag03_check_with_no_agent_func()
+RUN_CYNARA_TEST(tcag03_check_with_no_agent_func)
{
std::string testNo("03");
cynara_check_id id;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tcag04_agent_initialize_func()
+RUN_CYNARA_TEST(tcag04_agent_initialize_func)
{
Agent();
}
-void tcag05_agent_request_timeout_func()
+RUN_CYNARA_TEST(tcag05_agent_request_timeout_func)
{
Agent agent;
AgentRequest request;
restartCynaraServiceAndSockets, hangOnGetRequest);
}
-void tcag06_check_with_unregistered_agent_func()
+RUN_CYNARA_TEST(tcag06_check_with_unregistered_agent_func)
{
std::string testNo("06");
cynara_check_id id;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tcag07_get_request_func()
+RUN_CYNARA_TEST(tcag07_get_request_func)
{
std::string testNo("07");
CheckData data(testNo);
client.process();
}
-void tcag08_get_request_and_respond_with_wrong_id_func()
+RUN_CYNARA_TEST(tcag08_get_request_and_respond_with_wrong_id_func)
{
std::string testNo("08");
CheckData data(testNo);
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_TIMEOUT, 2);
}
-void tcag09_get_request_and_correct_responded_id_func()
+RUN_CYNARA_TEST(tcag09_get_request_and_correct_responded_id_func)
{
std::string testNo("09");
CheckData data(testNo);
client.process();
}
-void tcag10_cancel_request_func()
+RUN_CYNARA_TEST(tcag10_cancel_request_func)
{
std::string testNo("10");
CheckData data(testNo);
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
}
-void tcag11_cancel_processed_request_func()
+RUN_CYNARA_TEST(tcag11_cancel_processed_request_func)
{
std::string testNo("11");
CheckData data(testNo);
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
}
-void tcag12_create_two_requests_func()
+RUN_CYNARA_TEST(tcag12_create_two_requests_func)
{
std::string testNo("12");
CheckData data1(testNo, 1), data2(testNo, 2);
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::IGNORE_TIMEOUT, 1);
}
-void tcag13_create_many_requests_func()
+RUN_CYNARA_TEST(tcag13_create_many_requests_func)
{
const int numberOfRequests = 4;
std::string testNo("13");
}
}
-void tcag14_client_disconnects_func()
+RUN_CYNARA_TEST(tcag14_client_disconnects_func)
{
std::string testNo("14");
CheckData data(testNo);
agentRequest.assertCancel();
}
-void tcag15_agent_disconnects_func()
+RUN_CYNARA_TEST(tcag15_agent_disconnects_func)
{
std::string testNo("15");
CheckData data(testNo);
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
}
-RUNNER_TEST_GROUP_INIT(cynara_agent_tests)
-
-RUN_CYNARA_TEST(tcag01_set_agent_type_policy_without_plugin)
-RUN_CYNARA_TEST(tcag02_set_agent_type_policy_with_plugin_loaded)
-RUN_CYNARA_TEST(tcag03_check_with_no_agent)
-RUN_CYNARA_TEST(tcag04_agent_initialize)
-RUN_CYNARA_TEST(tcag05_agent_request_timeout)
-RUN_CYNARA_TEST(tcag06_check_with_unregistered_agent)
-RUN_CYNARA_TEST(tcag07_get_request)
-RUN_CYNARA_TEST(tcag08_get_request_and_respond_with_wrong_id)
-RUN_CYNARA_TEST(tcag09_get_request_and_correct_responded_id)
-RUN_CYNARA_TEST(tcag10_cancel_request)
-RUN_CYNARA_TEST(tcag11_cancel_processed_request)
-RUN_CYNARA_TEST(tcag12_create_two_requests)
-RUN_CYNARA_TEST(tcag13_create_many_requests)
-RUN_CYNARA_TEST(tcag14_client_disconnects)
-RUN_CYNARA_TEST(tcag15_agent_disconnects)
using namespace CynaraTestClientAsync;
using namespace CynaraTestAdmin;
-void tca01_initialize_func()
+RUNNER_TEST_GROUP_INIT(cynara_async_tests)
+
+RUN_CYNARA_TEST(tca01_initialize)
{
Client client;
}
-void tca02_empty_cache_miss_func()
+RUN_CYNARA_TEST(tca02_empty_cache_miss)
{
std::string testNo("02");
Client client;
client.checkCache({testNo}, CYNARA_API_CACHE_MISS);
}
-void tca03_create_max_requests_func()
+RUN_CYNARA_TEST(tca03_create_max_requests)
{
std::string testNo("03");
cynara_check_id id;
client.assertStatus(READWRITE);
}
-void tca04_request_and_process_func()
+RUN_CYNARA_TEST(tca04_request_and_process)
{
std::string testNo("04");
cynara_check_id id;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca05_request_and_cancel1_func()
+RUN_CYNARA_TEST(tca05_request_and_cancel1)
{
std::string testNo("05");
int subtest = 1;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca05_request_and_cancel2_func()
+RUN_CYNARA_TEST(tca05_request_and_cancel2)
{
std::string testNo("05");
int subtest = 2;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca05_request_and_cancel3_func()
+RUN_CYNARA_TEST(tca05_request_and_cancel3)
{
std::string testNo("05");
int subtest = 3;
client.cancel(id, CYNARA_API_INVALID_PARAM);
}
-void tca06_cancel_fail_func()
+RUN_CYNARA_TEST(tca06_cancel_fail)
{
cynara_check_id id = 0xDEAD;
client.cancel(id, CYNARA_API_INVALID_PARAM);
}
-void tca07_request_with_data_insertion_func()
+RUN_CYNARA_TEST(tca07_request_with_data_insertion)
{
std::string testNo("07");
Admin admin;
client.checkCache(data[1], CYNARA_API_CACHE_MISS);
}
-void tca08_disconnect1_func()
+RUN_CYNARA_TEST(tca08_disconnect1)
{
std::string testNo("08");
int subtest = 1;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca08_disconnect2_func()
+RUN_CYNARA_TEST(tca08_disconnect2)
{
std::string testNo("08");
int subtest = 2;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca08_disconnect3_func()
+RUN_CYNARA_TEST(tca08_disconnect3)
{
std::string testNo("08");
int subtest = 2;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca09_disconnect_and_cancel1_func()
+RUN_CYNARA_TEST(tca09_disconnect_and_cancel1)
{
std::string testNo("09");
int subtest = 1;
client.assertStatus(READ);
}
-void tca09_disconnect_and_cancel2_func()
+RUN_CYNARA_TEST(tca09_disconnect_and_cancel2)
{
std::string testNo("09");
int subtest = 2;
client.assertStatus(READ);
}
-void tca10_double_request_func()
+RUN_CYNARA_TEST(tca10_double_request)
{
std::string testNo("10");
cynara_check_id id, id2;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca11_double_request_with_restart_func()
+RUN_CYNARA_TEST(tca11_double_request_with_restart)
{
std::string testNo("11");
cynara_check_id id, id2;
client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
}
-void tca12_multiple_connections_without_requests_func()
+RUN_CYNARA_TEST(tca12_multiple_connections_without_requests)
{
std::string testNo("12");
<< after << " / " << afterTimestamp.tv_sec << "."
<< afterTimestamp.tv_usec);
}
-
-RUNNER_TEST_GROUP_INIT(cynara_async_tests)
-
-RUN_CYNARA_TEST(tca01_initialize)
-RUN_CYNARA_TEST(tca02_empty_cache_miss)
-RUN_CYNARA_TEST(tca03_create_max_requests)
-RUN_CYNARA_TEST(tca04_request_and_process)
-RUN_CYNARA_TEST(tca05_request_and_cancel1)
-RUN_CYNARA_TEST(tca05_request_and_cancel2)
-RUN_CYNARA_TEST(tca05_request_and_cancel3)
-RUN_CYNARA_TEST(tca06_cancel_fail)
-RUN_CYNARA_TEST(tca07_request_with_data_insertion)
-RUN_CYNARA_TEST(tca08_disconnect1)
-RUN_CYNARA_TEST(tca08_disconnect2)
-RUN_CYNARA_TEST(tca08_disconnect3)
-RUN_CYNARA_TEST(tca09_disconnect_and_cancel1)
-RUN_CYNARA_TEST(tca09_disconnect_and_cancel2)
-RUN_CYNARA_TEST(tca10_double_request)
-RUN_CYNARA_TEST(tca11_double_request_with_restart)
-RUN_CYNARA_TEST(tca12_multiple_connections_without_requests)
} // anonymous namespace
+
+RUNNER_TEST_GROUP_INIT(cynara_db_tests)
+
/**
* @brief Lockdown initialization failure caused by fake guard existence
* @test Expected result: refuse to write data to storage as long as guard file creation fails
* 4. Retry to make a change (ALLOW) in default bucket (data dump should proceed)
* 5. Check if database is saved correctly
*/
-void tcdb01_lockdown_init_failure_func()
+RUN_CYNARA_TEST(tcdb01_lockdown_init_failure)
{
Admin admin;
Client cynara;
* 4. Try to make a change (DENY) in default bucket (data dump should fail)
* 5. Reload Cynara - policies loaded from default bucket should still be ALLOW
*/
-void tcdb02_write_to_backup_failure_func()
+RUN_CYNARA_TEST(tcdb02_write_to_backup_failure)
{
Admin admin;
Client cynara;
* 5. Reload Cynara - policies should be loaded from primary (revalidated) database
* 6. Check if all backup files were removed
*/
-void tcdb03_invalid_and_valid_backup_removal_func()
+RUN_CYNARA_TEST(tcdb03_invalid_and_valid_backup_removal)
{
Admin admin;
Client cynara;
* 1. Write sample policy to database (and let it save to storage)
* 2. Compare freshly saved files with samples from test patterns directory
*/
-void tcdb04_dumped_file_binary_comparison_func()
+RUN_CYNARA_TEST(tcdb04_dumped_file_binary_comparison)
{
Admin admin;
Client cynara;
* 2. Reload Cynara
* 3. Check if any of mentioned above files still remained
*/
-void tcdb05_non_indexed_files_removal_func()
+RUN_CYNARA_TEST(tcdb05_non_indexed_files_removal)
{
std::vector<std::string> filenames = { "_broken-backup~", "_non-indexed-bucket",
"some-file-that-doesnt-belong-here" };
restartCynaraServiceAndSockets();
compareDbs(defDb);
}
-
-RUNNER_TEST_GROUP_INIT(cynara_db_tests)
-
-RUN_CYNARA_TEST(tcdb01_lockdown_init_failure)
-RUN_CYNARA_TEST(tcdb02_write_to_backup_failure)
-RUN_CYNARA_TEST(tcdb03_invalid_and_valid_backup_removal)
-RUN_CYNARA_TEST(tcdb04_dumped_file_binary_comparison)
-RUN_CYNARA_TEST(tcdb05_non_indexed_files_removal)
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file test_case.h
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version 1.0
+ * @brief This file is the header file of TestCase class
+ */
+
+#ifndef DPL_TEST_CASE_H
+#define DPL_TEST_CASE_H
+
+#include <string>
+
+#include <dpl/test/performance_result.h>
+
+namespace DPL {
+namespace Test {
+
+class TestCase
+{
+public:
+ TestCase(const std::string &name)
+ : m_name(name) {}
+ virtual ~TestCase() {}
+
+ bool operator <(const TestCase &other) const {
+ return m_name < other.m_name;
+ }
+ bool operator ==(const TestCase &other) const {
+ return m_name == other.m_name;
+ }
+
+ const std::string& GetName() const {
+ return m_name;
+ }
+ PerformanceResultPtr GetPerformance() const {
+ return m_performance;
+ }
+ void SetPerformance(PerformanceResultPtr performance) {
+ m_performance = performance;
+ }
+
+ virtual void Test() = 0;
+ virtual void Init() = 0;
+ virtual void Finish() = 0;
+
+private:
+ std::string m_name;
+ PerformanceResultPtr m_performance;
+};
+
+typedef TestCase* TestCasePtr;
+
+} // namespace Test
+} // namespace DPL
+
+#endif // DPL_TEST_CASE_H
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file test_case_extended.h
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version 1.0
+ * @brief This file is the header file of TestCaseExtended class
+ */
+
+#ifndef DPL_TEST_CASE_EXTENDED_H
+#define DPL_TEST_CASE_EXTENDED_H
+
+#include <cstddef>
+#include <functional>
+#include <string>
+#include <tuple>
+
+#include <dpl/test/test_case.h>
+
+namespace DPL {
+namespace Test {
+namespace Operations {
+
+template<size_t N, class T>
+void init(T &t, const std::string &testName) {
+ (void) t;
+ (void) testName;
+}
+
+template<size_t N, class T>
+void finish(T &t) {
+ (void) t;
+}
+
+template<size_t N, class T, typename First, typename ...Rest>
+void init(T &t, const std::string &testName) {
+ std::get<N>(t).init(testName);
+ init<N+1, T, Rest...>(t, testName);
+}
+
+template<size_t N, class T, typename First, typename ...Rest>
+void finish(T &t) {
+ std::get<N>(t).finish();
+ finish<N-1, T, Rest...>(t);
+}
+
+} // namespace Operations
+
+template<typename ...Args>
+class TestCaseExtended
+ : public TestCase
+{
+public:
+ TestCaseExtended(const std::string &name,
+ const std::function<void(std::tuple<Args...> &t)> &testFunc)
+ : TestCase(name), m_testFunc(testFunc) {}
+
+private:
+ virtual void Init() { Operations::init<0, std::tuple<Args...>, Args...>(m_tuple, GetName()); }
+ virtual void Finish() { Operations::finish<sizeof...(Args)-1, std::tuple<Args...>, Args...>(m_tuple); }
+ virtual void Test() { m_testFunc(m_tuple); }
+
+ std::tuple<Args...> m_tuple;
+ std::function<void(std::tuple<Args...> &t)> m_testFunc;
+};
+
+} // namespace Test
+} // namespace DPL
+
+#endif // DPL_TEST_CASE_EXTENDED_H
* @file test_runner.h
* @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
* @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
* @version 1.0
* @brief This file is the header file of test runner
*/
#include <cstdlib>
#include <cstring>
#include <exception>
+#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <dpl/gdbbacktrace.h>
#include <dpl/singleton.h>
#include <dpl/test/performance_result.h>
+#include <dpl/test/test_case.h>
+#include <dpl/test/test_case_extended.h>
#include <dpl/test/test_exception.h>
#include <dpl/test/test_failed.h>
#include <dpl/test/test_ignored.h>
void addFailReason(const std::string &reason);
- typedef void (*TestCase)();
+ ~TestRunner();
private:
- struct TestCaseStruct
- {
- std::string name;
- TestCase proc;
- PerformanceResultPtr performance;
-
- bool operator <(const TestCaseStruct &other) const
- {
- return name < other.name;
- }
-
- bool operator ==(const TestCaseStruct &other) const
- {
- return name == other.name;
- }
-
- TestCaseStruct(const std::string &n, TestCase p) :
- name(n),
- proc(p)
- {}
- };
-
- typedef std::list<TestCaseStruct> TestCaseStructList;
- typedef std::map<std::string, TestCaseStructList> TestCaseGroupMap;
+ typedef std::list<TestCasePtr> TestCaseList;
+ typedef std::map<std::string, TestCaseList> TestCaseGroupMap;
+ typedef std::set<TestCasePtr> TestCaseSet;
+
TestCaseGroupMap m_testGroups;
+ TestCaseSet m_testCaseSet;
+
+ TestCasePtr m_currentTestCase;
- TestCaseStruct * m_currentTestCase;
std::string m_currentGroup;
bool filterByXML(std::map<std::string, bool> & casesMap);
void normalizeXMLTag(std::string& str, const std::string& testcase);
- void RunTestCase(const TestCaseStruct& testCase);
+ void RunTestCase(TestCasePtr testCase);
- void setCurrentTestCase(TestCaseStruct* testCase);
- TestCaseStruct *getCurrentTestCase();
+ void setCurrentTestCase(TestCasePtr testCase);
+ TestCasePtr getCurrentTestCase();
void RunTests();
void CollectResult(const std::string& id, const TestResult &result);
public:
- void RegisterTest(const char *testName, TestCase proc);
void InitGroup(const char* name);
-
+ void RegisterTest(TestCasePtr testCase);
int ExecTestRunner(int argc, char *argv[]);
typedef std::vector<std::string> ArgsList;
int ExecTestRunner(ArgsList args);
};
typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
+
+TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::string &reason);
+
}
} // namespace DPL
const int DPL_UNUSED Static##GroupName##InitVar = \
Static##GroupName##Init();
-#define RUNNER_TEST(Proc) \
- void Proc(); \
- static int Static##Proc##Init() \
- { \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc()
-
+#define RUNNER_TEST(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
/**
* ASSERT MACROS
/*
* @file test_runner_child.h
* @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
* @version 1.0
* @brief This file is the header file of test runner
*/
#ifndef DPL_TEST_RUNNER_CHILD_H
#define DPL_TEST_RUNNER_CHILD_H
+#include <functional>
+#include <memory>
+#include <tuple>
+
+#include <dpl/availability.h>
+#include <dpl/test/test_case_extended.h>
#include <dpl/test/test_runner.h>
namespace DPL {
int m_pipefd[2];
};
-void RunChildProc(TestRunner::TestCase procChild);
+void RunChildProc(const std::function<void(void)> &testFunc);
} // namespace Test
} // namespace DPL
-#define RUNNER_CHILD_TEST(Proc) \
- void Proc(); \
- void Proc##Child(); \
- static int Static##Proc##Init() \
- { \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunChildProc(&Proc##Child); \
- } \
- void Proc##Child()
+#define RUNNER_CHILD_TEST(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunChildProc(std::bind(Proc##Child, optionalArgsTuple)); \
+ } \
+ void Proc##Child(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
#endif // DPL_TEST_RUNNER_CHILD_H
/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifndef DPL_TEST_RUNNER_MULTIPROCESS_H
#define DPL_TEST_RUNNER_MULTIPROCESS_H
+#include <ctime>
+#include <functional>
+#include <memory>
+#include <string>
+#include <tuple>
+
+#include <dpl/availability.h>
#include <dpl/test/test_runner_child.h>
namespace DPL {
Status receive(std::string &data, bool &empty, time_t deadline);
};
-void RunMultiProc(TestRunner::TestCase procMulti);
+void RunMultiProc(const std::function<void(void)>& testFunc);
} // namespace Test
} // namespace DPL
-#define RUNNER_MULTIPROCESS_TEST(Proc) \
- void Proc(); \
- void Proc##Multi(); \
- static int Static##Proc##Init() \
- { \
- DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
- return 0; \
- } \
- const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
- void Proc(){ \
- DPL::Test::RunMultiProc(&Proc##Multi); \
- } \
- void Proc##Multi()
+#define RUNNER_MULTIPROCESS_TEST(Proc, ...) \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple); \
+ static int Static##Proc##Init() \
+ { \
+ DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \
+ new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \
+ return 0; \
+ } \
+ const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
+ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \
+ DPL::Test::RunMultiProc(std::bind(Proc##Multi, optionalArgsTuple)); \
+ } \
+ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
#endif // DPL_TEST_RUNNER_MULTIPROCESS_H
#include <pcrecpp.h>
#include <algorithm>
#include <cstdio>
-#include <memory.h>
+#include <exception>
+#include <functional>
+#include <memory>
+#include <string>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
}
-
namespace DPL {
namespace Test {
-void TestRunner::RegisterTest(const char *testName, TestCase proc)
+TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::string &reason) {
+ try {
+ func();
+ } catch (const DPL::Test::TestFailed &e) {
+ reason = e.GetMessage();
+ return TestResult::FailStatus::FAILED;
+ } catch (const DPL::Test::TestIgnored &e) {
+ reason = e.GetMessage();
+ return TestResult::FailStatus::IGNORED;
+ } catch (const std::exception &e) {
+ reason = e.what();
+ return TestResult::FailStatus::FAILED;
+ } catch (...) {
+ reason = "Unknown exception";
+ return TestResult::FailStatus::FAILED;
+ }
+ reason = std::string();
+ return TestResult::FailStatus::NONE;
+}
+
+void TestRunner::RegisterTest(TestCasePtr testCase)
{
- m_testGroups[m_currentGroup].push_back(TestCaseStruct(testName, proc));
+ m_testGroups[m_currentGroup].push_back(testCase);
+ m_testCaseSet.insert(testCase);
}
void TestRunner::InitGroup(const char* name)
{
if(!cit->second.empty())
{
- for(TestCaseStructList::const_iterator cj = cit->second.begin(); cj != cit->second.end(); ++cj)
+ for(TestCaseList::const_iterator cj = cit->second.begin(); cj != cit->second.end(); ++cj)
{
- std::string name = cj->name;
+ std::string name = (*cj)->GetName();
std::string::size_type st = name.find('_');
if(st != std::string::npos)
{
bool TestRunner::filterByXML(std::map<std::string, bool> & casesMap)
{
for (auto &group : m_testGroups) {
- TestCaseStructList newList;
+ TestCaseList newList;
for (auto &tc : group.second)
{
- if (casesMap.find(tc.name) != casesMap.end()) {
- casesMap[tc.name] = true;
+ if (casesMap.find(tc->GetName()) != casesMap.end()) {
+ casesMap[tc->GetName()] = true;
newList.push_back(tc);
}
}
return true;
}
-void TestRunner::RunTestCase(const TestCaseStruct& testCase)
+void TestRunner::RunTestCase(TestCasePtr testCase)
{
- setCurrentTestCase(&(const_cast<TestCaseStruct &>(testCase)));
+ setCurrentTestCase(testCase);
m_deferDeepness = 0U;
- try {
- testCase.proc();
- } catch (const TestFailed &e) {
- // Simple test failure
- CollectResult(testCase.name,
- TestResult(TestResult::FailStatus::FAILED,
- getConcatedFailReason(e.GetMessage())));
-
- setCurrentTestCase(nullptr);
- return;
- } catch (const TestIgnored &e) {
- if (m_runIgnored) {
- // Simple test have to be implemented
- CollectResult(testCase.name,
- TestResult(TestResult::FailStatus::IGNORED, e.GetMessage()));
- }
+ std::string initReason;
+ TestResult::FailStatus initStatus = TryCatch(std::bind(&TestCase::Init, testCase),
+ initReason);
+ if (initStatus != TestResult::FailStatus::NONE) {
+ CollectResult(testCase->GetName(),
+ TestResult(initStatus, getConcatedFailReason(initReason), testCase->GetPerformance()));
setCurrentTestCase(nullptr);
return;
- } catch (const std::exception &) {
- // std exception failure
- CollectResult(testCase.name,
- TestResult(TestResult::FailStatus::FAILED, "std exception"));
+ }
- setCurrentTestCase(nullptr);
- return;
- } catch (...) {
- // Unknown exception failure
- CollectResult(testCase.name,
- TestResult(TestResult::FailStatus::FAILED, "unknown exception"));
- setCurrentTestCase(nullptr);
- return;
+ std::string testReason;
+ TestResult::FailStatus testStatus = TryCatch(std::bind(&TestCase::Test, testCase),
+ testReason);
+ testReason = getConcatedFailReason(testReason);
+ std::string finishReason;
+ TestResult::FailStatus finishStatus = TryCatch(std::bind(&TestCase::Finish, testCase),
+ finishReason);
+ finishReason = getConcatedFailReason(finishReason);
+
+ switch (finishStatus) {
+ case TestResult::FailStatus::FAILED:
+ testStatus = TestResult::FailStatus::FAILED;
+ if (!testReason.empty())
+ testReason += "\n";
+ testReason += finishReason;
+ break;
+ case TestResult::FailStatus::IGNORED:
+ if (testStatus == TestResult::FailStatus::NONE)
+ testStatus = TestResult::FailStatus::IGNORED;
+ if (!testReason.empty())
+ testReason += "\n";
+ testReason += finishReason;
+ case TestResult::FailStatus::NONE:
+ break;
+ default:
+ Assert(false && "Unhandled fail status");
}
- // Everything OK
- CollectResult(testCase.name,
- TestResult(TestResult::FailStatus::NONE,
- std::string(),
- testCase.performance));
+ CollectResult(testCase->GetName(),
+ TestResult(testStatus, testReason, testCase->GetPerformance()));
setCurrentTestCase(nullptr);
}
fprintf(stderr, "%sFound %d testcases...%s\n", GREEN_BEGIN, count, GREEN_END);
fprintf(stderr, "%s%s%s\n", GREEN_BEGIN, "Running tests...", GREEN_END);
for (auto &group : m_testGroups) {
- TestCaseStructList list = group.second;
+ TestCaseList list = group.second;
if (!list.empty()) {
for (auto &collector : m_collectors) {
collector.second->CollectCurrentTestGroupName(group.first);
}
- list.sort();
+ list.sort([](const TestCasePtr &a, const TestCasePtr &b) { return (*a < *b); });
- for (TestCaseStructList::const_iterator iterator = list.begin();
+ for (TestCaseList::const_iterator iterator = list.begin();
iterator != list.end();
++iterator)
{
- TestCaseStruct test = *iterator;
- if (m_startTestId == test.name) {
+ TestCasePtr test = *iterator;
+ if (m_startTestId == test->GetName()) {
m_startTestId = "";
}
fprintf(stderr, "%s%s%s\n\n", GREEN_BEGIN, "Finished", GREEN_END);
}
-TestRunner::TestCaseStruct *TestRunner::getCurrentTestCase()
+TestCasePtr TestRunner::getCurrentTestCase()
{
return m_currentTestCase;
}
-void TestRunner::setCurrentTestCase(TestCaseStruct* testCase)
+void TestRunner::setCurrentTestCase(TestCasePtr testCase)
{
m_currentTestCase = testCase;
}
void TestRunner::beginPerformance(std::chrono::system_clock::duration maxDurationInMicroseconds)
{
- TestCaseStruct* testCase = getCurrentTestCase();
+ TestCasePtr testCase = getCurrentTestCase();
if (!testCase)
return;
- if (!testCase->performance)
- testCase->performance.reset(new PerformanceResult(maxDurationInMicroseconds));
+ if (!testCase->GetPerformance())
+ testCase->SetPerformance(
+ std::unique_ptr<PerformanceResult> \
+ (new PerformanceResult(maxDurationInMicroseconds)));
}
void TestRunner::endPerformance()
{
- TestCaseStruct* testCase = getCurrentTestCase();
+ TestCasePtr testCase = getCurrentTestCase();
if (!testCase)
return;
- testCase->performance->Finish();
+ testCase->GetPerformance()->Finish();
}
ConstPerformanceResultPtr TestRunner::getCurrentTestCasePerformanceResult()
{
- TestCaseStruct* testCase = getCurrentTestCase();
+ TestCasePtr testCase = getCurrentTestCase();
if (!testCase)
return nullptr;
- return testCase->performance;
+ return testCase->GetPerformance();
}
void TestRunner::setCurrentTestCasePerformanceResult(const PerformanceResultPtr &performance)
{
- TestCaseStruct* testCase = getCurrentTestCase();
+ TestCasePtr testCase = getCurrentTestCase();
if (!testCase)
return;
- testCase->performance = performance;
+ testCase->SetPerformance(performance);
}
void TestRunner::addFailReason(const std::string &reason)
return reason + ret;
}
+TestRunner::~TestRunner()
+{
+ for(auto &t : m_testCaseSet)
+ delete t;
+}
+
void TestRunner::CollectResult(const std::string& id, const TestResult& result)
{
+ if (result.GetFailStatus() == TestResult::FailStatus::IGNORED && m_runIgnored)
+ return;
+
std::for_each(m_collectors.begin(),
m_collectors.end(),
[&](const TestResultsCollectors::value_type & collector)
arg.erase(0, startCmd.length());
for (auto &group : m_testGroups) {
for (auto &tc : group.second) {
- if (tc.name == arg) {
+ if (tc->GetName() == arg) {
m_startTestId = arg;
break;
}
TestCaseGroupMap::iterator found = m_testGroups.find(arg);
if (found != m_testGroups.end()) {
std::string name = found->first;
- TestCaseStructList newList = found->second;
+ TestCaseList newList = found->second;
m_testGroups.clear();
m_testGroups[name] = newList;
} else {
} else if (arg.find(listInGroup) == 0) {
arg.erase(0, listInGroup.length());
for (auto &test : m_testGroups[arg]) {
- printf("ID:%s\n", test.name.c_str());
+ printf("ID:%s\n", test->GetName().c_str());
}
return 0;
} else if (arg.find(allowChildLogs) == 0) {
pcrecpp::RE re(arg.c_str());
for (auto &group : m_testGroups) {
- TestCaseStructList newList;
+ TestCaseList newList;
for (auto &tc : group.second)
{
- if (re.PartialMatch(tc.name)) {
+ if (re.PartialMatch(tc->GetName())) {
newList.push_back(tc);
}
}
{
for (auto &group : m_testGroups) {
for (auto &tc : group.second) {
- printf("ID:%s:%s\n", group.first.c_str(), tc.name.c_str());
+ printf("ID:%s:%s\n", group.first.c_str(), tc->GetName().c_str());
}
}
return 0;
* @brief This file is the implementation file of test runner
*/
#include <stddef.h>
+#include <dpl/assert.h>
#include <dpl/test/test_failed.h>
#include <dpl/test/test_ignored.h>
#include <dpl/test/test_runner.h>
return SUCCESS;
}
-void RunChildProc(TestRunner::TestCase procChild)
+void RunChildProc(const std::function<void(void)> &testFunc)
{
PipeWrapper pipe;
if (!pipe.isReady()) {
// End Runner after current test
TestRunnerSingleton::Instance().Terminate();
- int code = CHILD_TEST_PASS;
- std::string msg;
-
bool allowLogs = TestRunnerSingleton::Instance().GetAllowChildLogs();
close(STDIN_FILENO);
pipe.setUsage(PipeWrapper::WRITEONLY);
- try {
- procChild();
- } catch (const DPL::Test::TestFailed &e) {
- msg = e.GetMessage();
- code = CHILD_TEST_FAIL;
- } catch (const DPL::Test::TestIgnored &e) {
- msg = e.GetMessage();
- code = CHILD_TEST_IGNORED;
- } catch (...) { // catch all exception generated by "user" code
- msg = "unhandled exeception";
- code = CHILD_TEST_FAIL;
+ int code;
+ std::string msg;
+ switch (TryCatch(testFunc, msg)) {
+ case TestResult::FailStatus::FAILED:
+ code = CHILD_TEST_FAIL;
+ break;
+ case TestResult::FailStatus::IGNORED:
+ code = CHILD_TEST_IGNORED;
+ break;
+ case TestResult::FailStatus::NONE:
+ code = CHILD_TEST_PASS;
+ break;
+ default:
+ Assert(false && "Unhandled fail status");
}
if (allowLogs) {
*/
#include <sys/file.h>
+#include <dpl/assert.h>
#include <dpl/exception.h>
#include <dpl/test/test_failed.h>
#include <dpl/test/test_ignored.h>
return ERROR;
}
-void RunMultiProc(TestRunner::TestCase procMulti)
+void RunMultiProc(const std::function<void(void)> &testFunc)
{
SimplePipeWrapper pipe;
- int code = MULTI_TEST_PASS;
- std::string msg = "";
int pipeReturn;
int waitStatus;
}
// pipe
- try {
- procMulti();
- } catch (const TestFailed &e) {
- code = MULTI_TEST_FAILED;
- msg = e.GetMessage();
- } catch (const TestIgnored &e) {
- code = MULTI_TEST_IGNORED;
- msg = e.GetMessage();
- } catch (const std::exception &) {
- code = MULTI_TEST_FAILED;
- msg = "std exception";
- } catch (...) {
- // Unknown exception failure
- code = MULTI_TEST_FAILED;
- msg = "unknown exception";
+ int code;
+ std::string msg;
+ switch (TryCatch(testFunc, msg)) {
+ case TestResult::FailStatus::FAILED:
+ code = MULTI_TEST_FAILED;
+ break;
+ case TestResult::FailStatus::IGNORED:
+ code = MULTI_TEST_IGNORED;
+ break;
+ case TestResult::FailStatus::NONE:
+ code = MULTI_TEST_PASS;
+ break;
+ default:
+ Assert(false && "Unhandled fail status");
}
while (true) {
WORLD_READ
WORLD_EXECUTE)
-execute_process(COMMAND ln -s /usr/bin/wrt-client ${CMAKE_CURRENT_BINARY_DIR}/${TEST_APP_WGT} )
-
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TEST_APP_WGT}
- DESTINATION /usr/bin)
+INSTALL(FILES ${TEST_APP_EFL}
+ DESTINATION /usr/bin
+ RENAME ${TEST_APP_WGT}
+ PERMISSIONS OWNER_READ
+ OWNER_WRITE
+ OWNER_EXECUTE
+ GROUP_READ
+ GROUP_EXECUTE
+ WORLD_READ
+ WORLD_EXECUTE)
SET(LPC_TARGET_TEST "libprivilege-control-test")
#include <privilege-control.h>
#include <tests_common.h>
#include <unistd.h>
+#include <tzplatform_config.h>
// How many open file descriptors should ftw() function use?
#define FTW_MAX_FDS 16
#define APPID_DIR "test_APP_ID_dir"
#define GENERATED_APP_ID "User" // TODO to be replaced in the future
+const uid_t TZ_APP_UID = tzplatform_getuid(TZ_USER_NAME);
+const gid_t TZ_APP_GID = tzplatform_getgid(TZ_USER_NAME);
+
#define PERM_TO_REDEFINE "Test::RedefinePermission"
#define PERM_SUB_TO_REDEFINE "Test::RedefinePermission::Sub"
int result;
+ /* Remove the group file to make sure other tests do not affect current one. This is because all
+ apps get the same label "User" */
+ const char* db_file = tzplatform_mkpath(TZ_SYS_DB,".privilege_control_app_gids.db");
+ RUNNER_ASSERT_MSG(db_file, "Failed to get groups db path");
+ result = unlink(db_file);
+ RUNNER_ASSERT_MSG(result == 0, "Removing group db failed " << strerror(errno));
+
DB_BEGIN
result = perm_app_uninstall(app_id);
RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
std::set<unsigned> groups_before;
- read_user_gids(groups_before, APP_UID);
+ read_user_gids(groups_before, TZ_APP_UID);
result = perm_app_set_privilege(app_id, type, app_path);
RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
*/
RUNNER_CHILD_TEST_SMACK(privilege_control05_set_app_privilege_wgt)
{
- test_set_app_privilege(WGT_APP_ID, APP_TYPE_WGT, PRIVS_WGT, "wgt", WGT_APP_PATH,
+ test_set_app_privilege(GENERATED_APP_ID, APP_TYPE_WGT, PRIVS_WGT, "wgt", WGT_APP_PATH,
LIBPRIVILEGE_TEST_DAC_FILE_WGT, rules_wgt);
}
*/
RUNNER_CHILD_TEST_SMACK(privilege_control05_set_app_privilege_osp)
{
- test_set_app_privilege(OSP_APP_ID, APP_TYPE_OSP, PRIVS_OSP, "tpk", OSP_APP_PATH,
+ test_set_app_privilege(GENERATED_APP_ID, APP_TYPE_OSP, PRIVS_OSP, "tpk", OSP_APP_PATH,
LIBPRIVILEGE_TEST_DAC_FILE_OSP, rules_osp);
}
RUNNER_CHILD_TEST_SMACK(privilege_control05_set_app_privilege_efl)
{
- test_set_app_privilege(EFL_APP_ID, APP_TYPE_EFL, PRIVS_EFL,
+ test_set_app_privilege(GENERATED_APP_ID, APP_TYPE_EFL, PRIVS_EFL,
"rpm", EFL_APP_PATH,
LIBPRIVILEGE_TEST_DAC_FILE_EFL, rules_efl);
}
" Permissions shouldn't be added. Result: " << result);
std::set<unsigned> groups_before;
- read_user_gids(groups_before, APP_UID);
+ read_user_gids(groups_before, TZ_APP_UID);
result = perm_app_set_privilege(app_id, type, app_path);
RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
DB_END
std::set<unsigned> groups_before;
- read_user_gids(groups_before, APP_UID);
+ read_user_gids(groups_before, TZ_APP_UID);
//Set app privileges
result = perm_app_set_privilege(APP_ID, nullptr, APP_SET_PRIV_PATH);
RUNNER_ASSERT_MSG(label == nullptr, "new_label_from_self shouldn't allocate memory for label.");
//Check if DAC privileges really set
- RUNNER_ASSERT_MSG(getuid() == APP_UID, "Wrong UID");
- RUNNER_ASSERT_MSG(getgid() == APP_GID, "Wrong GID");
+ RUNNER_ASSERT_MSG(getuid() == TZ_APP_UID, "Wrong UID");
+ RUNNER_ASSERT_MSG(getgid() == TZ_APP_GID, "Wrong GID");
result = strcmp(getenv("HOME"), APP_HOME_DIR);
RUNNER_ASSERT_MSG(result == 0, "Wrong HOME DIR. Result: " << result);
// Verify that all permissions to public dir have been added
// correctly, also to other app
- result = smack_have_access(APP_ID, shared_dir_auto_label.c_str(), "rwxatl");
+ result = smack_have_access(GENERATED_APP_ID, shared_dir_auto_label.c_str(), "rwxatl");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to Public RO dir are granted. Loop index: "
<< i);
- result = smack_have_access(TEST_OSP_FEATURE_APP_ID, shared_dir_auto_label.c_str(), "rx" );
+ /* all apps are getting the label "User" at the moment. Calling smack_have_access with
+ "User" as an argument is no different from previous call */
+ /*result = smack_have_access(TEST_OSP_FEATURE_APP_ID, shared_dir_auto_label.c_str(), "rx" );
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to Public RO dir are granted. Loop index: "
- << i);
+ << i);*/
break;
}
// Verify that setting app has rwx permission to app dir
// and rx permissions to app
- result = smack_have_access(APP_ID, shared_dir_auto_label.c_str(), "rwxatl");
+ result = smack_have_access(GENERATED_APP_ID, shared_dir_auto_label.c_str(), "rwxatl");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to App-Setting dir are granted. "
<< APP_ID << " "<< shared_dir_auto_label << " rwxatl "
<< "Loop index: " << i);
- result = smack_have_access(APP_TEST_SETTINGS_ASP1, shared_dir_auto_label.c_str(), "rwx");
+ /* all apps are getting the label "User" at the moment. Calling smack_have_access with
+ "User" as an argument is no different from previous call */
+ /*result = smack_have_access(APP_TEST_SETTINGS_ASP1, shared_dir_auto_label.c_str(), "rwx");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to App-Setting dir are granted. "
<< APP_TEST_SETTINGS_ASP1 << " " << shared_dir_auto_label << " rwx. "
<< "Loop index: " << i);
- result = smack_have_access(APP_TEST_SETTINGS_ASP1, APP_ID, "rx");
+ result = smack_have_access(APP_TEST_SETTINGS_ASP1, GENERATED_APP_ID, "rx");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to App-Setting dir are granted. "
- << APP_TEST_SETTINGS_ASP1 << " " << APP_ID << " rx"
- << "Loop index: " << i);
+ << APP_TEST_SETTINGS_ASP1 << " " << GENERATED_APP_ID << " rx"
+ << "Loop index: " << i);*/
// Verify that all permissions to public dir have been added
// correctly, also to other app
- result = smack_have_access(APP_ID, LABEL_FOR_PUBLIC_SHARED_DIRS, "rwxatl");
+ result = smack_have_access(GENERATED_APP_ID, LABEL_FOR_PUBLIC_SHARED_DIRS, "rwxatl");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to Group RW dir are granted. Loop index: "
<< i);
// check if api-features permissions are added properly
result = check_all_accesses(smack,
(const rules_t) {
- { APP_ID, TEST_OSP_FEATURE_APP_ID, "rxl" },
- { APP_ID, TEST_WGT_FEATURE_APP_ID, "rwxl" } } );
+ { GENERATED_APP_ID, TEST_OSP_FEATURE_APP_ID, "rxl" },
+ { GENERATED_APP_ID, TEST_WGT_FEATURE_APP_ID, "rwxl" } } );
RUNNER_ASSERT_MSG(result == 1,
"Not all permisions from api features added. Loop index: "
<< i);
// revoke permissions
- result = perm_app_revoke_permissions(APP_ID);
+ result = perm_app_revoke_permissions(GENERATED_APP_ID);
RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error in perm_app_revoke_permissions. Loop index: " << i
<< ". Result: " << result);
// generate app ids: test_APP0, test_APP1, test_APP2 etc.:
for (int i = 0; i < app_count; ++i)
{
- result = sprintf(app_ids[i], APP_ID "%d", i);
+ /* Libprivilege-control assigns "User" label to all apps. Replace it when individual labels
+ are supported. */
+ result = sprintf(app_ids[i], GENERATED_APP_ID);
RUNNER_ASSERT_MSG(result > 0, "Cannot generate name for app nr: " << i);
}
DB_END
+ // All apps have the same label "User" so this check makes no sense.
// Verify that some previously installed app does not have
// any acces to app 0 and app 5 PRIVATE folders
- for (int j = 0; j < app_count; ++j)
+ /*for (int j = 0; j < app_count; ++j)
{
// Apps 1-9 should not have any access to app 0
if (j != 0)
") has access to private label of: " << app_ids[5] <<
". It may not be shared. Loop index: " << i << ".");
}
- } // End for Verify PRIVATE
+ }*/ // End for Verify PRIVATE
// Verify that apps 1, 2 and 6 have all accesses to GROUP_RW folders
result = check_all_accesses(smack,
RUNNER_ASSERT_MSG(result == 1,
"Not all accesses to owned Public RO dir are granted. App id: "
<< app_ids[j] << " Loop index: " << i);
+ // All apps have the same label "User" so this check makes no sense.
// Verify that there are no extra permissions to public dirs
- result = check_no_accesses(smack,
+ /*result = check_no_accesses(smack,
(const rules_t) {
{ app_ids[j], shared_dir7_auto_label.c_str(), "w" },
{ app_ids[j], shared_dir7_auto_label.c_str(), "t" },
{ app_ids[j], shared_dir8_auto_label.c_str(), "t" } } );
RUNNER_ASSERT_MSG(result == 1,
"Unexpected extra permissions added for app:" << app_ids[j]
- << ". Loop index: " << i);
+ << ". Loop index: " << i);*/
}
if (j == 7)
{
RUNNER_ASSERT_MSG(result == 1,
"Not all accesses to owned Public RO dir are granted. App id: "
<< app_ids[j] << " Loop index: " << i);
+ // All apps have the same label "User" so this check makes no sense.
// Verify that there are no extra permissions to public dirs
- result = check_no_accesses(smack,
+ /*result = check_no_accesses(smack,
(const rules_t) {
{ app_ids[j], shared_dir3_auto_label.c_str(), "w" },
{ app_ids[j], shared_dir3_auto_label.c_str(), "t" },
{ app_ids[j], shared_dir8_auto_label.c_str(), "t" } } );
RUNNER_ASSERT_MSG(result == 1,
"Unexpected extra permissions added for app:" << app_ids[j]
- << ". Loop index: " << i);
+ << ". Loop index: " << i);*/
}
if (j == 8)
{
RUNNER_ASSERT_MSG(result == 1,
"Not all accesses to owned Public RO dir are granted. App id: "
<< app_ids[j] << " Loop index: " << i);
+ // All apps have the same label "User" so this check makes no sense.
// Verify that there are no extra permissions to other public dirs
- result = check_no_accesses(smack,
+ /*result = check_no_accesses(smack,
(const rules_t) {
{ app_ids[j], shared_dir3_auto_label.c_str(), "w" },
{ app_ids[j], shared_dir3_auto_label.c_str(), "t" },
{ app_ids[j], shared_dir7_auto_label.c_str(), "t" } } );
RUNNER_ASSERT_MSG(result == 1,
"Unexpected extra permissions added for app:" << app_ids[j]
- << ". Loop index: " << i);
+ << ". Loop index: " << i);*/
}
result = check_all_accesses(smack,
"Not all accesses to App-Setting dir are granted."
<< app_ids[9] << " " << setting_dir9_auto_label
<< " Loop index: " << i);
- result = smack_have_access(APP_TEST_SETTINGS_ASP1, app_ids[4], "rx");
+ // All apps have the same label "User" so this check makes no sense.
+ /*result = smack_have_access(APP_TEST_SETTINGS_ASP1, app_ids[4], "rx");
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to App-Setting dir are granted."
<< APP_TEST_SETTINGS_ASP1 << " " << app_ids[4]
RUNNER_ASSERT_MSG(result == expected_smack_result,
"Not all accesses to App-Setting dir are granted."
<< APP_TEST_SETTINGS_ASP1 << " " << setting_dir9_auto_label
- << " Loop index: " << i);
+ << " Loop index: " << i);*/
DB_END
+ // All apps have the same label "User" so this check makes no sense.
// Check if permissions are removed properly
- for (int j = 0; j < app_count; ++j)
+ /*for (int j = 0; j < app_count; ++j)
{
// To all other apps
for (int k = 0; k < app_count; ++k)
"Not all permisions revoked. Subject: " << app_ids[j]
<< " Object: " << app_ids[k] << " Loop index: " << i);
}
- }
+ }*/
DB_BEGIN
RUNNER_CHILD_TEST(security_manager_10_user_cynara_policy)
{
+ RUNNER_IGNORED_MSG("temporarily disabled due to gumd timeouts");
const char *const MAIN_BUCKET = "MAIN";
const char *const MANIFESTS_BUCKET = "MANIFESTS";
const char *const ADMIN_BUCKET = "ADMIN";
RUNNER_CHILD_TEST(security_manager_11_security_manager_cmd_install)
{
+ RUNNER_IGNORED_MSG("temporarily disabled due to gumd timeouts");
int ret;
const int SUCCESS = 0;
const int FAILURE = 256;
RUNNER_CHILD_TEST(security_manager_12_security_manager_cmd_users)
{
+ RUNNER_IGNORED_MSG("temporarily disabled due to gumd timeouts");
int ret;
const int SUCCESS = 0;
const int FAILURE = 256;