From: Zofia Abramowska Date: Wed, 11 Sep 2013 15:03:27 +0000 (+0200) Subject: Moving ss-label to ss-client-smack X-Git-Tag: security-manager_5.5_testing~350 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a25a36ffa927fae4cdf599309f361cab9abcd68c;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Moving ss-label to ss-client-smack [Issue#] N/A [Feature/Bug] N/A [Cause] Unnecessary separate binary for one test. [Solution] Moved ss-label to ss-client-smack test cases. [Verification] Build. Install. Run ss-client-smack (should be 8 passing tests). Change-Id: I63e194dfa3eae7f07ead130f85820ecf018a5e19 --- diff --git a/packaging/security-tests.spec b/packaging/security-tests.spec index 8b6f77b..b799c52 100644 --- a/packaging/security-tests.spec +++ b/packaging/security-tests.spec @@ -74,7 +74,6 @@ osp-installer -u V5LKqDFBXm /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 diff --git a/tests/security-server-tests/CMakeLists.txt b/tests/security-server-tests/CMakeLists.txt index 4fd4e4a..1bae78d 100644 --- a/tests/security-server-tests/CMakeLists.txt +++ b/tests/security-server-tests/CMakeLists.txt @@ -34,7 +34,6 @@ PKG_CHECK_MODULES(SEC_SRV_TESTS_DEP # 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") @@ -49,10 +48,6 @@ SET(SEC_SRV_CLIENT_SMACK_SOURCES ${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 @@ -88,7 +83,6 @@ ADD_DEFINITIONS("-I/usr/include/dbus-1.0/dbus") #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}) @@ -100,10 +94,6 @@ TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_CLIENT_SMACK_TESTS} ${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) @@ -127,7 +117,6 @@ TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_MEASURER} # 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) diff --git a/tests/security-server-tests/security_server_tests_client_smack.cpp b/tests/security-server-tests/security_server_tests_client_smack.cpp index 5b73036..38f447e 100644 --- a/tests/security-server-tests/security_server_tests_client_smack.cpp +++ b/tests/security-server-tests/security_server_tests_client_smack.cpp @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -31,6 +32,8 @@ #include "tests_common.h" +#define PROPER_COOKIE_SIZE 20 + #define ENVIRONMENT \ do { \ const char *subject_label = "mylabel"; \ @@ -61,6 +64,7 @@ "Cannot prepare environment for test"); \ } while (0) + /** * Unique_ptr typedef for NOSMACK version of tc06 test */ @@ -792,6 +796,98 @@ RUNNER_CHILD_TEST(tc17_security_server_get_gid_by_cookie) } +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 > 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/////////// //////////////////// diff --git a/tests/security-server-tests/security_server_tests_label.cpp b/tests/security-server-tests/security_server_tests_label.cpp deleted file mode 100644 index df983f6..0000000 --- a/tests/security-server-tests/security_server_tests_label.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* -* 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 -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#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 > 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; -}