/usr/bin/libsmack-test
/usr/bin/libprivilege-control-test
/usr/bin/security-server-tests-client-smack
-/usr/bin/security-server-tests-label
/usr/bin/security-server-tests-server
/usr/bin/security-server-tests-password
/usr/bin/security-server-tests-dbus
# Targets definition
SET(TARGET_SEC_SRV_CLIENT_SMACK_TESTS "security-server-tests-client-smack")
-SET(TARGET_SEC_SRV_LABEL_TESTS "security-server-tests-label")
SET(TARGET_SEC_SRV_TC_SERVER_TESTS "security-server-tests-server")
SET(TARGET_SEC_SRV_PWD_TESTS "security-server-tests-password")
SET(TARGET_SEC_SRV_MT_TESTS "security-server-tests-mt")
${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_mockup.cpp
)
-SET(SEC_SRV_LABEL_SOURCES
- ${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_tests_label.cpp
- )
-
SET(SEC_SRV_TC_SERVER_SOURCES
${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_tests_server.cpp
${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_tests_weird_arguments.cpp
#LINK_DIRECTORIES(${SEC_SRV_PKGS_LIBRARY_DIRS})
ADD_EXECUTABLE(${TARGET_SEC_SRV_CLIENT_SMACK_TESTS} ${SEC_SRV_CLIENT_SMACK_SOURCES})
-ADD_EXECUTABLE(${TARGET_SEC_SRV_LABEL_TESTS} ${SEC_SRV_LABEL_SOURCES})
ADD_EXECUTABLE(${TARGET_SEC_SRV_TC_SERVER_TESTS} ${SEC_SRV_TC_SERVER_SOURCES})
ADD_EXECUTABLE(${TARGET_SEC_SRV_PWD_TESTS} ${SEC_SRV_PWD_SOURCES})
ADD_EXECUTABLE(${TARGET_SEC_SRV_MT_TESTS} ${SEC_SRV_MT_SOURCES})
${SEC_SRV_TESTS_DEP_LIBRARIES}
tests-common)
-TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_LABEL_TESTS}
- ${SEC_SRV_TESTS_DEP_LIBRARIES}
- tests-common)
-
TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_TC_SERVER_TESTS}
${SEC_SRV_TESTS_DEP_LIBRARIES}
tests-common)
# Installation
INSTALL(TARGETS ${TARGET_SEC_SRV_CLIENT_SMACK_TESTS} DESTINATION /usr/bin)
-INSTALL(TARGETS ${TARGET_SEC_SRV_LABEL_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_TC_SERVER_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_PWD_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_MT_TESTS} DESTINATION /usr/bin)
*/
#include <unistd.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/smack.h>
#include "tests_common.h"
+#define PROPER_COOKIE_SIZE 20
+
#define ENVIRONMENT \
do { \
const char *subject_label = "mylabel"; \
"Cannot prepare environment for test"); \
} while (0)
+
/**
* Unique_ptr typedef for NOSMACK version of tc06 test
*/
}
+RUNNER_TEST_SMACK(tc18_security_server_get_smacklabel_cookie) {
+ int res;
+
+ pid_t mypid;
+
+ char *label_smack = NULL;
+ char *label_ss = NULL;
+ char *cookie = NULL;
+
+ int cookie_size = security_server_get_cookie_size();
+ RUNNER_ASSERT_MSG(PROPER_COOKIE_SIZE == cookie_size, "Wrong cookie size from security-server");
+
+ mypid = getpid();
+
+ cookie = (char*) calloc(cookie_size, 1);
+ RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
+
+ res = security_server_request_cookie(cookie, cookie_size);
+ if (res != SECURITY_SERVER_API_SUCCESS) {
+ free(cookie);
+ RUNNER_ASSERT_MSG(res == SECURITY_SERVER_API_SUCCESS, "Error in requesting cookie from security-server");
+ }
+
+ label_ss = security_server_get_smacklabel_cookie(cookie);
+ free(cookie);
+ RUNNER_ASSERT_MSG(label_ss != NULL, "Error in getting label by cookie");
+
+
+ std::string label_cookie(label_ss);
+ free(label_ss);
+
+ res = smack_new_label_from_self(&label_smack);
+ if (res < 0) {
+ free(label_smack);
+ RUNNER_ASSERT_MSG(res == 0, "Error in getting self SMACK label");
+ }
+ std::string label_self(label_smack ? label_smack : "");
+ free(label_smack);
+
+ RUNNER_ASSERT_MSG(label_self == label_cookie, "No match in SMACK labels");
+
+
+ //TODO: here could be label change using SMACK API and checking if it
+ //is changed using security-server API function based on the same cookie
+}
+
+/**
+ * NOSMACK version of tc_security_server_get_smacklabel_cookie test.
+ *
+ * Most of this test goes exactly as the original one. The only difference are the labels:
+ * - We assume that libsmack tests passed and smack_new_label_from_self will return -1 and NULL
+ * label - there is no need to re-check it.
+ * - Label acquired from security_server_get_smacklabel_cookie should be an empty string.
+ */
+RUNNER_TEST_NOSMACK(tc_security_server_get_smacklabel_cookie_nosmack) {
+ int res;
+
+ pid_t mypid;
+
+ char* label_ss = NULL;
+ char* cookie = NULL;
+
+ int cookie_size = security_server_get_cookie_size();
+ RUNNER_ASSERT_MSG(PROPER_COOKIE_SIZE == cookie_size,
+ "Wrong cookie size from security-server. Size: " << cookie_size);
+
+ cookie = (char*) calloc(cookie_size, sizeof(char));
+ RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
+
+ mypid = getpid();
+
+ //Request cookie from SS
+ res = security_server_request_cookie(cookie, cookie_size);
+ std::unique_ptr<char, std::function<void(char*)> > cookie_ptr(cookie, free);
+ cookie = NULL;
+ if (res != SECURITY_SERVER_API_SUCCESS) {
+ RUNNER_ASSERT_MSG(res == SECURITY_SERVER_API_SUCCESS,
+ "Error in requesting cookie from security-server. Result: " << res);
+ }
+
+ label_ss = security_server_get_smacklabel_cookie(cookie_ptr.get());
+ RUNNER_ASSERT_MSG(label_ss != NULL, "Error in getting label by cookie");
+
+ //Check if label_ss is correct, that is only one NULL character.
+ if (label_ss[0] != '\0') {
+ free(label_ss);
+ RUNNER_ASSERT_MSG(label_ss[0] == '\0', "label_ss was not an empty string.");
+ }
+
+ free(label_ss);
+}
+
////////////////////
/////MAIN///////////
////////////////////
+++ /dev/null
-/*
-* Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
-*/
-/*
-* @file security_server_tests_label.cpp
-* @author Pawel Polawski (p.polawski@samsung.com)
-* @author Mariusz Domanski (m.domanski@samsung.com)
-* @version 1.0
-* @brief Test cases for security server
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/smack.h>
-
-#include <memory>
-#include <functional>
-
-#include <security-server.h>
-#include <dpl/test/test_runner.h>
-#include <dlog.h>
-#include "tests_common.h"
-#include "test.h"
-
-RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_LABEL);
-
-RUNNER_TEST_SMACK(tc_security_server_get_smacklabel_cookie) {
- int res;
-
- pid_t mypid;
-
- char *label_smack = NULL;
- char *label_ss = NULL;
- char *cookie = NULL;
-
- int COOKIESIZE = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG(20 == COOKIESIZE, "Wrong cookie size from security-server");
- SLOGD("%s %d", "Cookie size:", COOKIESIZE);
-
- cookie = (char*) calloc(COOKIESIZE, 1);
- RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
-
- mypid = getpid();
- SLOGD("%s %d", "This binary PID is:", mypid);
-
- res = smack_new_label_from_self(&label_smack);
- if (res < 0) {
- if (NULL != label_smack)
- free(label_smack);
- if (NULL != label_ss)
- free(label_ss);
- if (NULL != cookie)
- free(cookie);
- RUNNER_ASSERT_MSG(false, "Error in getting self SMACK label");
- }
-
- res = security_server_request_cookie(cookie, COOKIESIZE);
- if (SECURITY_SERVER_API_SUCCESS != res) {
- if (NULL != label_smack)
- free(label_smack);
- if (NULL != label_ss)
- free(label_ss);
- if (NULL != cookie)
- free(cookie);
- RUNNER_ASSERT_MSG(false, "Error in requesting cookie from security-server");
- }
-
- SLOGD("%s", "Received cookie:");
- printhex((unsigned char*) cookie, COOKIESIZE);
-
- label_ss = security_server_get_smacklabel_cookie(cookie);
- if (NULL == label_ss) {
- if (NULL != label_smack)
- free(label_smack);
- if (NULL != label_ss)
- free(label_ss);
- if (NULL != cookie)
- free(cookie);
- RUNNER_ASSERT_MSG(false, "Error in getting label by cookie");
- }
-
- SLOGD("%s %s", "Label from SMACK:", label_smack);
- SLOGD("%s %s", "Label from SS:", label_ss);
-
- if (sizeof(label_smack) != sizeof(label_ss)) {
- if (NULL != label_smack)
- free(label_smack);
- if (NULL != label_ss)
- free(label_ss);
- if (NULL != cookie)
- free(cookie);
- RUNNER_ASSERT_MSG(false, "No match in SMACK labels sizes");
- }
-
- res = strcmp(label_smack, label_ss);
- if (0 != res) {
- if (NULL != label_smack)
- free(label_smack);
- if (NULL != label_ss)
- free(label_ss);
- if (NULL != cookie)
- free(cookie);
- RUNNER_ASSERT_MSG(false, "No match in SMACK labels");
- }
-
- //TODO: here could be label change using SMACK API and checking if it
- //is changed using security-server API function based on the same cookie
-}
-
-/**
- * NOSMACK version of tc_security_server_get_smacklabel_cookie test.
- *
- * Most of this test goes exactly as the original one. The only difference are the labels:
- * - We assume that libsmack tests passed and smack_new_label_from_self will return -1 and NULL
- * label - there is no need to re-check it.
- * - Label acquired from security_server_get_smacklabel_cookie should be an empty string.
- */
-RUNNER_TEST_NOSMACK(tc_security_server_get_smacklabel_cookie_nosmack) {
- int res;
-
- pid_t mypid;
-
- char* label_ss = NULL;
- char* cookie = NULL;
-
- int COOKIESIZE = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG(20 == COOKIESIZE,
- "Wrong cookie size from security-server. Size: " << COOKIESIZE);
-
- cookie = (char*) calloc(COOKIESIZE, sizeof(char));
- RUNNER_ASSERT_MSG(NULL != cookie, "Memory allocation error");
-
- //wrap cookie in smart ptr for garbage collection
- std::unique_ptr<char, std::function<void(char*)> > cookie_ptr(cookie, free);
-
- mypid = getpid();
-
- //Request cookie from SS
- res = security_server_request_cookie(cookie, COOKIESIZE);
- RUNNER_ASSERT_MSG(res == SECURITY_SERVER_API_SUCCESS,
- "Error in requesting cookie from security-server. Result: " << res);
-
- printhex((unsigned char*) cookie, COOKIESIZE);
-
- //Get label; since we only use label_ss to check if it indeed is an empty string there is no
- //need to wrap it into unique_ptr (we have only one assert before the end of the test)
- label_ss = security_server_get_smacklabel_cookie(cookie);
- RUNNER_ASSERT_MSG(label_ss != NULL, "Error in getting label by cookie");
-
- //Check if label_ss is correct, that is only one NULL character.
- if (label_ss[0] != '\0') {
- free(label_ss);
- RUNNER_ASSERT_MSG(false, "label_ss was not an empty string.");
- }
-
- free(label_ss);
-}
-
-int main(int argc, char *argv[])
-{
- int status =
- DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
-
- return status;
-}