From 06678b8f7d633fa261684474f015cdc36340e245 Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Fri, 13 Dec 2013 18:38:40 +0100 Subject: [PATCH] Fix tests in security-server-test-client smack. [Issue#] 724 [Bug/Problem] Enabling socket labels in security-server crashes some tests. [Cause] Test cases did not set up smack labels. [Solution] Fix set up of smack labels. [Verification] Build, run tests. Change-Id: I6c56e8df90d47c7d183fa2ac279c157682d0103f --- .../security_server_tests_client_smack.cpp | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) 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 3c571d3..5d35cd7 100644 --- a/tests/security-server-tests/security_server_tests_client_smack.cpp +++ b/tests/security-server-tests/security_server_tests_client_smack.cpp @@ -30,6 +30,9 @@ #include +#include +#include + #include "tests_common.h" #define PROPER_COOKIE_SIZE 20 @@ -134,7 +137,9 @@ RUNNER_CHILD_TEST_SMACK(tc03_security_server_request_cookie_too_small_buffer_siz */ RUNNER_CHILD_TEST_SMACK(tc04_security_server_get_gid) { - ENVIRONMENT; + SecurityServer::AccessProvider provider("tc04mylabel"); + provider.allowFunction("security_server_get_gid", TRACE_FROM_HERE); + provider.applyAndSwithToUser(APP_UID, APP_GID, TRACE_FROM_HERE); int ret = security_server_get_gid("abc123xyz_pysiaczek"); LogDebug("ret = " << ret); @@ -160,18 +165,10 @@ RUNNER_CHILD_TEST_SMACK(tc05_check_privilege_by_cookie) const char *access_rights_ext = "rw"; const char *subject_label = "tc05subjectlabel"; - smack_accesses *handle; - - RUNNER_ASSERT(0 == smack_accesses_new(&handle)); - - RUNNER_ASSERT(0 == smack_accesses_add(handle, - subject_label, - object_label, - access_rights)); - - RUNNER_ASSERT(0 == smack_accesses_apply(handle)); - - smack_accesses_free(handle); + SmackAccess access; + access.add(subject_label, object_label, access_rights, TRACE_FROM_HERE); + access.add(subject_label, "security-server::api-cookie-check", "w", TRACE_FROM_HERE); + access.apply(TRACE_FROM_HERE); RUNNER_ASSERT(0 == smack_set_label_for_self(subject_label)); @@ -302,14 +299,9 @@ RUNNER_MULTIPROCESS_TEST_SMACK(tc07_check_privilege_by_sockfd) int result1 = -1; int result2 = -1; - smack_accesses *handle; - RUNNER_ASSERT(0 == smack_accesses_new(&handle)); - RUNNER_ASSERT(0 == smack_accesses_add(handle, - subject_label, - object_label, - access_rights)); - RUNNER_ASSERT(0 == smack_accesses_apply(handle)); - smack_accesses_free(handle); + SmackAccess access; + access.add(subject_label, object_label, access_rights, TRACE_FROM_HERE); + access.apply(TRACE_FROM_HERE); int pid = fork(); RUNNER_ASSERT(-1 != pid); @@ -341,9 +333,6 @@ RUNNER_MULTIPROCESS_TEST_SMACK(tc07_check_privilege_by_sockfd) exit(0); } else { // parent - - RUNNER_ASSERT_MSG(drop_root_privileges() == 0, "uid = " << getuid()); - sleep(1); int sockfd = connect_to_testserver(); RUNNER_ASSERT_MSG(sockfd >= 0, "connect_to_testserver() failed"); -- 2.7.4