Cynara: Redo gdbus helpers tests
[platform/core/test/security-tests.git] / src / cynara-tests / test_cases_helpers.cpp
1 /*
2  * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        test_cases_helpers.cpp
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  * @brief       Tests for cynara-helper-credentials-socket and cynara-helper-credentials-dbus
21  */
22
23 #include <cstdlib>
24 #include <functional>
25 #include <string>
26 #include <sys/types.h>
27 #include <sys/un.h>
28 #include <unistd.h>
29 #include <utility>
30
31 #include <dbus/dbus.h>
32 #include <glib-object.h>
33 #include <gio/gio.h>
34
35 #include <tests_common.h>
36 #include <access_provider.h>
37 #include <dpl/test/test_runner.h>
38 #include <memory.h>
39 #include <synchronization_pipe.h>
40 #include <tests_common.h>
41 #include <uds.h>
42 #include <passwd_access.h>
43
44 #include <cynara_test_helpers.h>
45 #include <cynara_test_helpers_dbus.h>
46 #include <cynara-creds-gdbus.h>
47 #include <cynara-creds-self.h>
48
49 class ProcessCredentials {
50 public:
51     ProcessCredentials() {}
52
53     const std::string &label(void) const {
54         return m_label;
55     }
56
57     uid_t uid(void) const {
58         return PasswdAccess::uid(APP_USER);
59     }
60
61     gid_t gid(void) const {
62         return PasswdAccess::gid("users");
63     }
64
65 private:
66     std::string m_label = "cynara_helpers";
67 };
68
69 pid_t runInChild(const std::function<void(void)> &process) {
70     pid_t pid = fork();
71     RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
72
73     if (pid == 0) {
74         process();
75         exit(EXIT_SUCCESS);
76     }
77
78     return pid;
79 }
80
81 cynara_client_creds getClientDefaultMethod() {
82     cynara_client_creds def;
83     int ret = cynara_creds_get_default_client_method(&def);
84     RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
85                       "cynara_creds_get_default_client_method failed with " << ret);
86     return def;
87 }
88
89 cynara_user_creds getUserDefaultMethod() {
90     cynara_user_creds def;
91     int ret = cynara_creds_get_default_user_method(&def);
92     RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
93                       "cynara_creds_get_default_user_method failed with " << ret);
94     return def;
95 }
96
97
98 void udsServer(SynchronizationPipe &pipe, const struct sockaddr_un &sockaddr,
99                const struct ProcessCredentials &peerCredentials) {
100     SecurityServer::AccessProvider ap(peerCredentials.label());
101     ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
102     pipe.claimChildEp();
103
104     int sock = UDSHelpers::createServer(&sockaddr);
105     SockUniquePtr sockPtr(&sock);
106     pipe.post();
107     int clientSock = UDSHelpers::acceptClient(sock);
108
109     UDSHelpers::waitForDisconnect(clientSock);
110 }
111
112 typedef std::function<void(int sock, pid_t pid,
113         const ProcessCredentials &peerCredentials)> SocketAssertionFn;
114
115 void socketTestTemplate(SocketAssertionFn assertion, const std::string &scope) {
116     const auto sockaddr = UDSHelpers::makeAbstractAddress("helper_" + scope + ".socket");
117     const ProcessCredentials peerCredentials;
118
119     SynchronizationPipe pipe;
120
121     pid_t pid = runInChild(std::bind(udsServer, std::ref(pipe), std::cref(sockaddr),
122                            std::cref(peerCredentials)));
123
124     pipe.claimParentEp();
125     pipe.wait();
126     int sock = UDSHelpers::createClient(&sockaddr);
127     SockUniquePtr sockPtr(&sock);
128
129     assertion(sock, pid, peerCredentials);
130 }
131
132 RUNNER_TEST_GROUP_INIT(cynara_creds_socket)
133
134 void testSocketClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
135     socketTestTemplate([method] (int sock, pid_t, const ProcessCredentials &peerCredentials) {
136         CStringPtr label(CynaraHelperCredentials::socketGetClient(sock, method));
137         RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
138                           "Labels don't match ret = " << label.get()
139                           << "; expected = " << peerCredentials.label());
140     }, "tccs01");
141 }
142
143 void testSocketClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
144     socketTestTemplate([method] (int sock, pid_t pid, const ProcessCredentials &) {
145         CStringPtr clientPidStr(CynaraHelperCredentials::socketGetClient(sock, method));
146         pid_t clientPid = std::stoi(clientPidStr.get());
147         RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
148                           << "; expected = " << pid);
149     }, "tccs02");
150 }
151
152 RUNNER_MULTIPROCESS_TEST_SMACK(tccs01_socket_credentials_client_smack)
153 {
154     testSocketClientSmack();
155 }
156
157 RUNNER_MULTIPROCESS_TEST(tccs02_socket_credentials_client_pid)
158 {
159     testSocketClientPid();
160 }
161
162 RUNNER_MULTIPROCESS_TEST_SMACK(tccs03_socket_credentials_client_default)
163 {
164     auto method = getClientDefaultMethod();
165     switch(method) {
166     case CLIENT_METHOD_SMACK:
167         testSocketClientSmack(CLIENT_METHOD_DEFAULT);
168         break;
169     case CLIENT_METHOD_PID:
170         testSocketClientPid(CLIENT_METHOD_DEFAULT);
171         break;
172     default:
173         RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value "
174                         << method);
175     }
176 }
177
178 void testSocketUserUid(cynara_user_creds method = USER_METHOD_UID) {
179     socketTestTemplate([method] (int sock, pid_t, const ProcessCredentials &peerCredentials) {
180         CStringPtr uidStr(CynaraHelperCredentials::socketGetUser(sock, method));
181         uid_t uid = std::stoul(uidStr.get());
182         RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
183                           << "; expected = "<< peerCredentials.uid());
184     }, "tccs04");
185 }
186
187 void testSocketUserGid(cynara_user_creds method = USER_METHOD_GID) {
188     socketTestTemplate([method] (int sock, pid_t, const ProcessCredentials &peerCredentials) {
189         CStringPtr gidStr(CynaraHelperCredentials::socketGetUser(sock, method));
190         gid_t gid = std::stoul(gidStr.get());
191         RUNNER_ASSERT_MSG(peerCredentials.gid() == gid, "GIDs don't match ret = " << gid
192                           << "; expected = "<< peerCredentials.gid());
193     }, "tccs05");
194 }
195
196 RUNNER_MULTIPROCESS_TEST(tccs04_socket_credentials_user_uid)
197 {
198     testSocketUserUid();
199 }
200
201 RUNNER_MULTIPROCESS_TEST(tccs05_socket_credentials_user_gid)
202 {
203     testSocketUserGid();
204 }
205
206 RUNNER_MULTIPROCESS_TEST(tccs06_socket_credentials_user_default)
207 {
208     auto method = getUserDefaultMethod();
209     switch(method) {
210     case USER_METHOD_UID:
211         testSocketUserUid(USER_METHOD_DEFAULT);
212         break;
213     case USER_METHOD_GID:
214         testSocketUserGid(USER_METHOD_DEFAULT);
215         break;
216     default:
217         RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value "
218                  << method);
219     }
220 }
221
222 RUNNER_MULTIPROCESS_TEST(tccs07_socket_credentials_pid)
223 {
224     socketTestTemplate([] (int sock, pid_t expectedPid, const ProcessCredentials &) {
225         pid_t peerPid(CynaraHelperCredentials::socketGetPid(sock));
226         RUNNER_ASSERT_MSG(peerPid == expectedPid, "Pids don't match ret = " << peerPid
227                           << "; expected = "<< expectedPid);
228     }, "tccs05");
229 }
230
231 // TODO: Create utility namespace for DBus, maybe?
232 DBusConnectionPtr createDBusConnection(const std::string &name) {
233     DBusError err;
234
235     dbus_error_init(&err);
236     DBusConnection *conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
237     RUNNER_ASSERT_MSG(dbus_error_is_set(&err) != 1, "Error in dbus_bus_get: " << err.message);
238     dbus_connection_set_exit_on_disconnect(conn, FALSE);
239
240     DBusConnectionPtr ret(conn, [] (DBusConnection *conn) {
241         dbus_connection_close(conn);
242         dbus_connection_unref(conn);
243     });
244
245     if (name.empty() == false) {
246         dbus_bus_request_name(conn, name.c_str(), DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
247         RUNNER_ASSERT_MSG(dbus_error_is_set(&err) != TRUE,
248                           "Error in dbus_bus_request_name: " << err.message);
249     }
250
251     return ret;
252 }
253
254 void dbusServer(SynchronizationPipe &pipe, const std::string &requestedName,
255                 const ProcessCredentials &peerCredentials) {
256     // for DBus connection, System must have access to our peer creds as well.
257     SecurityServer::AccessProvider systemAp("System");
258     systemAp.addObjectRule(peerCredentials.label(), "rwx");
259     systemAp.apply();
260
261     SecurityServer::AccessProvider ap(peerCredentials.label());
262     ap.addObjectRule("System", "w");
263     ap.addObjectRule("System::Run", "x");
264     ap.addObjectRule("System::Shared", "rwx"); // for GDB
265     ap.addSubjectRule("System::Privileged", "rwx"); // for piping
266     ap.addObjectRule("System::Privileged", "rwx"); // for GDB and piping
267     ap.addObjectRule("User", "r"); // for /usr/lib/debug access
268     ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
269     pipe.claimChildEp();
270
271     auto conn = createDBusConnection(requestedName);
272     pipe.post();
273     pipe.wait();
274 }
275
276 typedef std::function<void(DBusConnectionPtr conn, pid_t pid,
277                            const std::string &requestedName,
278                            const ProcessCredentials &peerCredentials)> DBusAssertionFn;
279
280 void dbusTestTemplate(DBusAssertionFn assertion, const std::string &/*scope*/) {
281     std::string requestedName = "tests.dbus.cynara";
282     const ProcessCredentials peerCredentials;
283
284     SynchronizationPipe pipe;
285     pid_t pid = runInChild(std::bind(dbusServer, std::ref(pipe), std::cref(requestedName),
286                            std::cref(peerCredentials)));
287
288     pipe.claimParentEp();
289     pipe.wait();
290
291     auto conn = createDBusConnection("");
292     assertion(std::move(conn), pid, requestedName, peerCredentials);
293     pipe.post();
294 }
295
296 RUNNER_TEST_GROUP_INIT(cynara_creds_dbus)
297
298 void testDbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
299     dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t pid, const std::string &requestedName,
300                          const ProcessCredentials &) {
301         CStringPtr clientPidStr(CynaraHelperCredentials::dbusGetClient(std::move(conn),
302             requestedName.c_str(), method, CYNARA_API_SUCCESS));
303         pid_t clientPid = std::stoi(clientPidStr.get());
304         RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
305                           << "; expected = " << pid);
306     }, "tccd01");
307 }
308
309 void testDbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
310     dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
311                          const ProcessCredentials &peerCredentials) {
312         CStringPtr label(CynaraHelperCredentials::dbusGetClient(std::move(conn),
313             requestedName.c_str(), method, CYNARA_API_SUCCESS));
314         RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
315                           "Labels don't match ret = " << label.get()
316                           << "; expected = " << peerCredentials.label());
317     }, "tccd02");
318 }
319
320 RUNNER_MULTIPROCESS_TEST(tccd01_dbus_credentials_client_pid)
321 {
322     testDbusClientPid();
323 }
324
325 RUNNER_MULTIPROCESS_TEST_SMACK(tccd02_dbus_credentials_client_smack)
326 {
327     testDbusClientSmack();
328 }
329
330 RUNNER_MULTIPROCESS_TEST_SMACK(tccd03_dbus_credentials_client_default)
331 {
332     auto method = getClientDefaultMethod();
333     switch(method) {
334     case CLIENT_METHOD_SMACK:
335         testDbusClientSmack(CLIENT_METHOD_DEFAULT);
336         break;
337     case CLIENT_METHOD_PID:
338         testDbusClientPid(CLIENT_METHOD_DEFAULT);
339         break;
340     default:
341         RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value "
342                         << method);
343     }
344 }
345
346 void testDbusUserUid(cynara_user_creds method = USER_METHOD_UID) {
347     dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
348                          const ProcessCredentials &peerCredentials) {
349         CStringPtr uidStr(CynaraHelperCredentials::dbusGetUser(std::move(conn),
350             requestedName.c_str(), method, CYNARA_API_SUCCESS));
351         uid_t uid = std::stoul(uidStr.get());
352         RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
353                           << "; expected = "<< peerCredentials.uid());
354     }, "tccd04");
355 }
356
357 void testDbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
358     // Acquiring gid from dbus connection is not yet implemented for cynara helpers
359     dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
360                          const ProcessCredentials &) {
361         CStringPtr gidStr(CynaraHelperCredentials::dbusGetUser(std::move(conn),
362             requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED));
363     }, "tccd04");
364 }
365
366 RUNNER_MULTIPROCESS_TEST(tccd04_dbus_credentials_user_uid)
367 {
368     testDbusUserUid();
369 }
370
371 RUNNER_MULTIPROCESS_TEST(tccd05_dbus_credentials_user_gid)
372 {
373     testDbusUserGid();
374 }
375
376 RUNNER_MULTIPROCESS_TEST(tccd06_dbus_credentials_user_default) {
377     auto method = getUserDefaultMethod();
378     switch(method) {
379     case USER_METHOD_UID:
380         testDbusUserUid(USER_METHOD_DEFAULT);
381         break;
382     case USER_METHOD_GID:
383         testDbusUserGid(USER_METHOD_DEFAULT);
384         break;
385     default:
386         RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value "
387                         << method);
388     }
389 }
390
391 RUNNER_TEST_SMACK(tccd06_dbus_credentials_pid) {
392     dbusTestTemplate([] (DBusConnectionPtr conn, pid_t expectedPid,
393                          const std::string &requestedName, const ProcessCredentials &) {
394         auto helperPid = CynaraHelperCredentials::dbusGetPid(std::move(conn),
395             requestedName.c_str(), CYNARA_API_SUCCESS);
396         RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
397                           << "; expected = " << expectedPid);
398     }, "tccd06");
399 }
400
401 GDBusConnectionPtr createGDBusConnection() {
402     GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
403
404     return GDBusConnectionPtr(conn, [] (GDBusConnection *conn) {
405         g_object_unref(G_OBJECT(conn));
406     });
407 }
408
409
410 typedef std::function<void(GDBusConnectionPtr conn, pid_t pid,
411                            const std::string &requestedName,
412                            const ProcessCredentials &peerCredentials)> GDBusAssertionFn;
413
414 void gdbusTestTemplate(GDBusAssertionFn assertion, const std::string &/*scope*/) {
415     std::string requestedName = "tests.dbus.cynara";
416     const ProcessCredentials peerCredentials;
417
418     SynchronizationPipe pipe;
419     pid_t pid = runInChild(std::bind(dbusServer, std::ref(pipe), std::cref(requestedName),
420                            std::cref(peerCredentials)));
421
422     pipe.claimParentEp();
423     pipe.wait();
424
425     auto conn = createGDBusConnection();
426     assertion(std::move(conn), pid, requestedName, peerCredentials);
427     pipe.post();
428 }
429
430
431 RUNNER_TEST_GROUP_INIT(cynara_creds_gdbus)
432
433 void testGdbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
434     gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t pid,
435                                 const std::string &requestedName,
436                                 const ProcessCredentials &) {
437         GStringPtr clientPidStr(CynaraHelperCredentials::gdbusGetClient(std::move(conn),
438                                 requestedName.c_str(), method));
439         pid_t clientPid = std::stoi(clientPidStr.get());
440         RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
441                           << "; expected = " << pid);
442     }, "tccgd01");
443 }
444
445 void testGdbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
446     gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t,
447                                 const std::string &requestedName,
448                                 const ProcessCredentials &peerCredentials) {
449         GStringPtr label(CynaraHelperCredentials::gdbusGetClient(std::move(conn),
450                          requestedName.c_str(), method));
451         RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
452                           "Labels don't match ret = " << label.get()
453                           << "; expected = " << peerCredentials.label());
454     }, "tccgd02");
455 }
456
457 RUNNER_MULTIPROCESS_TEST(tccgd01_gdbus_credentials_client_pid)
458 {
459     testGdbusClientPid();
460 }
461
462 RUNNER_MULTIPROCESS_TEST_SMACK(tccgd02_gdbus_credentials_client_smack)
463 {
464     testGdbusClientSmack();
465 }
466
467 RUNNER_MULTIPROCESS_TEST_SMACK(tccgd03_gdbus_credentials_client_default)
468 {
469     auto method = getClientDefaultMethod();
470     switch(method) {
471     case CLIENT_METHOD_SMACK:
472         testGdbusClientSmack(CLIENT_METHOD_DEFAULT);
473         break;
474     case CLIENT_METHOD_PID:
475         testGdbusClientPid(CLIENT_METHOD_DEFAULT);
476         break;
477     default:
478         RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value "
479                         << method);
480     }
481 }
482
483 void testGdbusUserUid(cynara_user_creds method = USER_METHOD_UID) {
484     gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t,
485                                 const std::string &requestedName,
486                                 const ProcessCredentials &peerCredentials) {
487         GStringPtr uidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn),
488                           requestedName.c_str(), method));
489         uid_t uid = std::stoul(uidStr.get());
490         RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
491                           << "; expected = "<< peerCredentials.uid());
492     }, "tccgd04");
493 }
494
495 void testGdbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
496     // Getting gid for gdbus connection is not yet implemented in cynara helpers
497     gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t,
498                                 const std::string &requestedName,
499                                 const ProcessCredentials &) {
500         GStringPtr gidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn),
501                           requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED));
502     }, "tccgd04");
503 }
504
505 RUNNER_MULTIPROCESS_TEST(tccgd04_gdbus_credentials_user_uid)
506 {
507     testGdbusUserUid();
508 }
509
510 RUNNER_MULTIPROCESS_TEST(tccgd05_gdbus_credentials_user_gid)
511 {
512     testGdbusUserGid();
513 }
514
515 RUNNER_MULTIPROCESS_TEST(tccgd06_gdbus_credentials_user_default) {
516     auto method = getUserDefaultMethod();
517     switch(method) {
518     case USER_METHOD_UID:
519         testGdbusUserUid(USER_METHOD_DEFAULT);
520         break;
521     case USER_METHOD_GID:
522         testGdbusUserGid(USER_METHOD_DEFAULT);
523         break;
524     default:
525         RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value "
526                         << method);
527     }
528 }
529
530 RUNNER_MULTIPROCESS_TEST(tccgd06_gdbus_credentials_pid) {
531     gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t expectedPid,
532                           const std::string &requestedName, const ProcessCredentials &) {
533         auto helperPid = CynaraHelperCredentials::gdbusGetPid(std::move(conn),
534                          requestedName.c_str());
535         RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
536                           << "; expected = " << expectedPid);
537     }, "tccgd06");
538 }
539
540 RUNNER_TEST_GROUP_INIT(cynara_creds_self)
541
542 void testCredsClientSelf(cynara_client_creds method, const std::string &expected) {
543     char *client;
544     int ret = cynara_creds_self_get_client(method, &client);
545     CStringPtr clientPtr(client);
546     RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS, "cynara_creds_self_get_client failed with " << ret);
547     RUNNER_ASSERT_MSG(expected == client, "expected client doesn't match, expected: " << expected
548                                           << ", got : " << client);
549 }
550
551 void testCredsUserSelf(cynara_user_creds method, const std::string &expected) {
552     char *user;
553     int ret = cynara_creds_self_get_user(method, &user);
554     CStringPtr clientPtr(user);
555     RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS, "cynara_creds_self_get_user failed with " << ret);
556     RUNNER_ASSERT_MSG(expected == user, "expected user doesn't match, expected: " << expected
557                                           << ", got : " << user);
558 }
559
560 void testSelfClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
561     std::string label = "test-label";
562     change_label(label.c_str());
563     testCredsClientSelf(method, label);
564 }
565
566 void testSelfClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
567     pid_t pid = getpid();
568     testCredsClientSelf(method, std::to_string(pid));
569 }
570
571 void testSelfUserUid(cynara_user_creds method = USER_METHOD_UID) {
572     uid_t uid = getuid();
573     testCredsUserSelf(method, std::to_string(uid));
574 }
575
576 void testSelfUserGid(cynara_user_creds method = USER_METHOD_GID) {
577     gid_t gid = getgid();
578     testCredsUserSelf(method, std::to_string(gid));
579 }
580
581 RUNNER_CHILD_TEST_SMACK(tccsl01_self_credentials_client_smack) {
582     testSelfClientSmack();
583 }
584
585 RUNNER_CHILD_TEST_SMACK(tccsl02_self_credentials_client_pid) {
586     testSelfClientPid();
587 }
588
589 RUNNER_CHILD_TEST_SMACK(tccsl03_self_credentials_user_uid) {
590     testSelfUserUid();
591 }
592
593 RUNNER_CHILD_TEST_SMACK(tccsl04_self_credentials_user_gid) {
594     testSelfUserGid();
595 }
596
597 RUNNER_CHILD_TEST_SMACK(tccsl05_self_credentials_client_default) {
598     auto method = getClientDefaultMethod();
599     switch(method) {
600     case CLIENT_METHOD_SMACK:
601         testSelfClientSmack(CLIENT_METHOD_DEFAULT);
602         break;
603     case CLIENT_METHOD_PID:
604         testSelfClientPid(CLIENT_METHOD_DEFAULT);
605         break;
606     default:
607         RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value " << method);
608     }
609 }
610
611 RUNNER_CHILD_TEST_SMACK(tccsl06_self_credentials_user_default) {
612     auto method = getUserDefaultMethod();
613     switch(method) {
614     case USER_METHOD_UID:
615         testSelfUserUid(USER_METHOD_DEFAULT);
616         break;
617     case USER_METHOD_GID:
618         testSelfUserGid(USER_METHOD_DEFAULT);
619         break;
620     default:
621         RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value " << method);
622     }
623 }