2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
5 * @file security_server_tests_label.cpp
6 * @author Pawel Polawski (p.polawski@samsung.com)
7 * @author Mariusz Domanski (m.domanski@samsung.com)
9 * @brief Test cases for security server
14 #include <sys/types.h>
16 #include <sys/smack.h>
21 #include <security-server.h>
22 #include <dpl/test/test_runner.h>
24 #include "tests_common.h"
27 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_LABEL);
29 RUNNER_TEST_SMACK(tc_security_server_get_smacklabel_cookie) {
34 char *label_smack = NULL;
35 char *label_ss = NULL;
38 int COOKIESIZE = security_server_get_cookie_size();
39 RUNNER_ASSERT_MSG(20 == COOKIESIZE, "Wrong cookie size from security-server");
40 SLOGD("%s %d", "Cookie size:", COOKIESIZE);
42 cookie = (char*) calloc(COOKIESIZE, 1);
43 RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
46 SLOGD("%s %d", "This binary PID is:", mypid);
48 res = smack_new_label_from_self(&label_smack);
50 if (NULL != label_smack)
56 RUNNER_ASSERT_MSG(false, "Error in getting self SMACK label");
59 res = security_server_request_cookie(cookie, COOKIESIZE);
60 if (SECURITY_SERVER_API_SUCCESS != res) {
61 if (NULL != label_smack)
67 RUNNER_ASSERT_MSG(false, "Error in requesting cookie from security-server");
70 SLOGD("%s", "Received cookie:");
71 printhex((unsigned char*) cookie, COOKIESIZE);
73 label_ss = security_server_get_smacklabel_cookie(cookie);
74 if (NULL == label_ss) {
75 if (NULL != label_smack)
81 RUNNER_ASSERT_MSG(false, "Error in getting label by cookie");
84 SLOGD("%s %s", "Label from SMACK:", label_smack);
85 SLOGD("%s %s", "Label from SS:", label_ss);
87 if (sizeof(label_smack) != sizeof(label_ss)) {
88 if (NULL != label_smack)
94 RUNNER_ASSERT_MSG(false, "No match in SMACK labels sizes");
97 res = strcmp(label_smack, label_ss);
99 if (NULL != label_smack)
101 if (NULL != label_ss)
105 RUNNER_ASSERT_MSG(false, "No match in SMACK labels");
108 //TODO: here could be label change using SMACK API and checking if it
109 //is changed using security-server API function based on the same cookie
113 * NOSMACK version of tc_security_server_get_smacklabel_cookie test.
115 * Most of this test goes exactly as the original one. The only difference are the labels:
116 * - We assume that libsmack tests passed and smack_new_label_from_self will return -1 and NULL
117 * label - there is no need to re-check it.
118 * - Label acquired from security_server_get_smacklabel_cookie should be an empty string.
120 RUNNER_TEST_NOSMACK(tc_security_server_get_smacklabel_cookie_nosmack) {
125 char* label_ss = NULL;
128 int COOKIESIZE = security_server_get_cookie_size();
129 RUNNER_ASSERT_MSG(20 == COOKIESIZE,
130 "Wrong cookie size from security-server. Size: " << COOKIESIZE);
132 cookie = (char*) calloc(COOKIESIZE, sizeof(char));
133 RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
135 //wrap cookie in smart ptr for garbage collection
136 std::unique_ptr<char, std::function<void(char*)> > cookie_ptr(cookie, free);
140 //Request cookie from SS
141 res = security_server_request_cookie(cookie, COOKIESIZE);
142 RUNNER_ASSERT_MSG(res == SECURITY_SERVER_API_SUCCESS,
143 "Error in requesting cookie from security-server. Result: " << res);
145 printhex((unsigned char*) cookie, COOKIESIZE);
147 //Get label; since we only use label_ss to check if it indeed is an empty string there is no
148 //need to wrap it into unique_ptr (we have only one assert before the end of the test)
149 label_ss = security_server_get_smacklabel_cookie(cookie);
150 RUNNER_ASSERT_MSG(label_ss != NULL, "Error in getting label by cookie");
152 //Check if label_ss is correct, that is only one NULL character.
153 if (label_ss[0] != '\0') {
155 RUNNER_ASSERT_MSG(false, "label_ss was not an empty string.");
161 int main(int argc, char *argv[])
164 DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);