#include <cynara_test_helpers.h>
#include <cynara_test_helpers_dbus.h>
#include <cynara-creds-gdbus.h>
+#include <cynara-creds-self.h>
class ProcessCredentials {
public:
<< "; expected = " << expectedPid);
}, "tccgd04");
}
+
+RUNNER_TEST_GROUP_INIT(cynara_creds_self)
+
+void testCredsClientSelf(cynara_client_creds method, const std::string &expected) {
+ char *client;
+ int ret = cynara_creds_self_get_client(method, &client);
+ CStringPtr clientPtr(client);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS, "cynara_creds_self_get_client failed with " << ret);
+ RUNNER_ASSERT_MSG(expected == client, "expected client doesn't match, expected: " << expected
+ << ", got : " << client);
+}
+
+void testCredsUserSelf(cynara_user_creds method, const std::string &expected) {
+ char *user;
+ int ret = cynara_creds_self_get_user(method, &user);
+ CStringPtr clientPtr(user);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS, "cynara_creds_self_get_user failed with " << ret);
+ RUNNER_ASSERT_MSG(expected == user, "expected user doesn't match, expected: " << expected
+ << ", got : " << user);
+}
+
+void testSelfClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
+ std::string label = "test-label";
+ change_label(label.c_str());
+ testCredsClientSelf(method, label);
+}
+
+void testSelfClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
+ pid_t pid = getpid();
+ testCredsClientSelf(method, std::to_string(pid));
+}
+
+void testSelfUserUid(cynara_user_creds method = USER_METHOD_UID) {
+ uid_t uid = getuid();
+ testCredsUserSelf(method, std::to_string(uid));
+}
+
+void testSelfUserGid(cynara_user_creds method = USER_METHOD_GID) {
+ gid_t gid = getgid();
+ testCredsUserSelf(method, std::to_string(gid));
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl01_self_credentials_client_smack) {
+ testSelfClientSmack();
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl02_self_credentials_client_pid) {
+ testSelfClientPid();
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl03_self_credentials_user_uid) {
+ testSelfUserUid();
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl04_self_credentials_user_gid) {
+ testSelfUserGid();
+}
+
+cynara_client_creds getClientDefaultMethod() {
+ cynara_client_creds def;
+ int ret = cynara_creds_get_default_client_method(&def);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_creds_get_default_client_method failed with " << ret);
+ return def;
+}
+
+cynara_user_creds getUserDefaultMethod() {
+ cynara_user_creds def;
+ int ret = cynara_creds_get_default_user_method(&def);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_creds_get_default_user_method failed with " << ret);
+ return def;
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl05_self_credentials_client_default) {
+ auto method = getClientDefaultMethod();
+ switch(method) {
+ case CLIENT_METHOD_SMACK:
+ testSelfClientSmack(CLIENT_METHOD_DEFAULT);
+ break;
+ case CLIENT_METHOD_PID:
+ testSelfClientPid(CLIENT_METHOD_DEFAULT);
+ break;
+ default:
+ RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value " << method);
+ }
+}
+
+RUNNER_CHILD_TEST_SMACK(tccsl06_self_credentials_user_default) {
+ auto method = getUserDefaultMethod();
+ switch(method) {
+ case USER_METHOD_UID:
+ testSelfUserUid(USER_METHOD_DEFAULT);
+ break;
+ case USER_METHOD_GID:
+ testSelfUserGid(USER_METHOD_DEFAULT);
+ break;
+ default:
+ RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value " << method);
+ }
+}