From: Zofia Abramowska Date: Thu, 7 Sep 2017 14:47:20 +0000 (+0200) Subject: Move label generation to global commons X-Git-Tag: security-manager_5.5_testing~14^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c195d9cd27b7283f8f6918d0b2fe50e83e24e43;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Move label generation to global commons Change-Id: Ic38d65e29394dc5b8e784a8af6b105460e52a259 --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4fd89535..cfb01ee7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -33,6 +33,7 @@ SET(COMMON_TARGET_TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/common/timeout.cpp ${PROJECT_SOURCE_DIR}/src/common/temp_test_user.cpp ${PROJECT_SOURCE_DIR}/src/common/cynara_helpers_creds.cpp + ${PROJECT_SOURCE_DIR}/src/common/label_generator.cpp ) #system and local includes diff --git a/src/common/label_generator.cpp b/src/common/label_generator.cpp new file mode 100644 index 00000000..6fc5140f --- /dev/null +++ b/src/common/label_generator.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +// Common implementation details +std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid) +{ + std::string label = "User::Pkg::" + pkgId; + if (isHybrid) { + label += "::App::" + appId; + } + return label; +} + +std::string generatePathRWLabel(const std::string &pkgId) +{ + return "User::Pkg::" + pkgId; +} + +std::string generatePathROLabel(const std::string &pkgId) +{ + return generatePathRWLabel(pkgId) + "::RO"; +} + +std::string generatePathSharedROLabel(const std::string &pkgId) +{ + return generatePathRWLabel(pkgId) + "::SharedRO"; +} + +std::string generatePathTrustedLabel(int64_t authorId) +{ + return "User::Author::" + std::to_string(authorId); +} + +std::string getPublicPathLabel() +{ + return "User::Home"; +} diff --git a/src/common/label_generator.h b/src/common/label_generator.h new file mode 100644 index 00000000..8c99ed42 --- /dev/null +++ b/src/common/label_generator.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid = false); +std::string generatePathRWLabel(const std::string &pkgId); +std::string generatePathROLabel(const std::string &pkgId); +std::string generatePathSharedROLabel(const std::string &pkgId); +std::string generatePathTrustedLabel(int64_t authorId); +std::string getPublicPathLabel(); diff --git a/src/security-manager-tests/common/app_install_helper.cpp b/src/security-manager-tests/common/app_install_helper.cpp index f1865fe1..b9f3073c 100644 --- a/src/security-manager-tests/common/app_install_helper.cpp +++ b/src/security-manager-tests/common/app_install_helper.cpp @@ -26,8 +26,8 @@ #include #include -#include #include +#include #include "app_install_helper.h" diff --git a/src/security-manager-tests/common/sm_commons.cpp b/src/security-manager-tests/common/sm_commons.cpp index bd583a23..d6b0ee86 100644 --- a/src/security-manager-tests/common/sm_commons.cpp +++ b/src/security-manager-tests/common/sm_commons.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,45 +45,10 @@ #include #include #include "tzplatform.h" +#include using namespace SecurityManagerTest; -// Common implementation details - -std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid) -{ - std::string label = "User::Pkg::" + pkgId; - if (isHybrid) { - label += "::App::" + appId; - } - return label; -} - -std::string generatePathRWLabel(const std::string &pkgId) -{ - return "User::Pkg::" + pkgId; -} - -std::string generatePathROLabel(const std::string &pkgId) -{ - return generatePathRWLabel(pkgId) + "::RO"; -} - -std::string generatePathSharedROLabel(const std::string &pkgId) -{ - return generatePathRWLabel(pkgId) + "::SharedRO"; -} - -std::string generatePathTrustedLabel(int64_t authorId) -{ - return "User::Author::" + std::to_string(authorId); -} - -std::string getPublicPathLabel() -{ - return "User::Home"; -} - // Common DB/nftw checks // nftw doesn't allow passing user data to functions. Work around by using global variable diff --git a/src/security-manager-tests/common/sm_commons.h b/src/security-manager-tests/common/sm_commons.h index 346c1f70..02e9a132 100644 --- a/src/security-manager-tests/common/sm_commons.h +++ b/src/security-manager-tests/common/sm_commons.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,13 +35,6 @@ DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr); const int FTW_MAX_FDS = 16; -std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid = false); -std::string generatePathRWLabel(const std::string &pkgId); -std::string generatePathROLabel(const std::string &pkgId); -std::string generatePathSharedROLabel(const std::string &pkgId); -std::string generatePathTrustedLabel(int64_t authorId); -std::string getPublicPathLabel(); - typedef std::vector privileges_t; int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/, diff --git a/src/security-manager-tests/test_cases.cpp b/src/security-manager-tests/test_cases.cpp index 3d802307..406d3036 100644 --- a/src/security-manager-tests/test_cases.cpp +++ b/src/security-manager-tests/test_cases.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/src/security-manager-tests/test_cases_credentials.cpp b/src/security-manager-tests/test_cases_credentials.cpp index 90d74a96..6571f9c8 100644 --- a/src/security-manager-tests/test_cases_credentials.cpp +++ b/src/security-manager-tests/test_cases_credentials.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/src/security-manager-tests/test_cases_dyntransition.cpp b/src/security-manager-tests/test_cases_dyntransition.cpp index e2b2ba6e..3c8c607b 100644 --- a/src/security-manager-tests/test_cases_dyntransition.cpp +++ b/src/security-manager-tests/test_cases_dyntransition.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ struct UidGidMsg { static void testSetLabelForSelf(const std::string &appName, const std::string &pkgName, bool expected_success) { + //FIXME : replace this with SM API std::string label = generateProcessLabel(appName, pkgName); int result = smack_set_label_for_self(label.c_str()); if (expected_success) diff --git a/src/security-manager-tests/test_cases_register_paths.cpp b/src/security-manager-tests/test_cases_register_paths.cpp index 9a125552..88e08963 100644 --- a/src/security-manager-tests/test_cases_register_paths.cpp +++ b/src/security-manager-tests/test_cases_register_paths.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #include #include +#include #include #include #include