Add tests for application defined privileges 41/113741/5
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 3 Feb 2017 15:49:29 +0000 (16:49 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 20 Feb 2017 17:51:32 +0000 (18:51 +0100)
Change-Id: Idbceecaabab13449089006b086e95655d822257b

src/security-manager-tests/CMakeLists.txt
src/security-manager-tests/test_cases_app_defined_privilege.cpp [new file with mode: 0644]

index fad06f1..b986d9a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-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.
@@ -41,6 +41,7 @@ SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_commons.cpp
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_file_operations.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases.cpp
+    ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_app_defined_privilege.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_credentials.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_dyntransition.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_nss.cpp
diff --git a/src/security-manager-tests/test_cases_app_defined_privilege.cpp b/src/security-manager-tests/test_cases_app_defined_privilege.cpp
new file mode 100644 (file)
index 0000000..85f57f2
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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 <functional>
+#include <string>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include <cynara-client.h>
+#include <dpl/test/test_runner.h>
+#include <sm_api.h>
+#include <sm_commons.h>
+#include <sm_request.h>
+#include <tests_common.h>
+#include <tzplatform.h>
+#include <app_install_helper.h>
+#include <scoped_installer.h>
+
+RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_APP_DEFINED_PRIVILEGE)
+
+using namespace SecurityManagerTest;
+
+RUNNER_CHILD_TEST(app_define_01_global_install)
+{
+    const std::string privilege = "http://tizen.org/applicationDefinedPrivilege/alamakota";
+    const std::string providerAppId = "app_def_01_provider_appid";
+    const std::string consumerAppId = "app_def_01_client_appid";
+    const std::string ownerId = "5001";
+    const std::string session = "S0M3S3SSI0N";
+
+    struct cynara *m_cynara = nullptr;
+
+    AppInstallHelper provider(providerAppId);
+    AppInstallHelper consumer(consumerAppId);
+
+    std::string consumerLabel = consumer.generateAppLabel();
+
+    provider.addAppDefinedPrivilege(privilege);
+    consumer.addPrivilege(privilege);
+
+    ScopedInstaller req1(provider);
+    ScopedInstaller req2(consumer);
+
+    int ret = cynara_initialize(&m_cynara, nullptr);
+    RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+                         "cynara_initialize failed. ret: " << ret);
+    RUNNER_ASSERT_MSG(m_cynara != nullptr, "cynara struct was not initialized");
+
+    ret = cynara_check(
+                    m_cynara,
+                    consumerLabel.c_str(),
+                    session.c_str(),
+                    ownerId.c_str(),
+                    privilege.c_str());
+
+    cynara_finish(m_cynara);
+
+    RUNNER_ASSERT_MSG(ret == CYNARA_API_ACCESS_ALLOWED,
+                         "cynara_check returned wrong value: "
+                             << ret << " != " << CYNARA_API_ACCESS_ALLOWED << "."
+                             << " client: " << consumerLabel << ","
+                             << " session: " << session << ","
+                             << " user: " << ownerId << ","
+                             << " privilege: " << privilege);
+}
+
+RUNNER_CHILD_TEST(app_define_02_global_install)
+{
+    const std::string privilege = "http://tizen.org/licensedPrivilege/alamakota";
+    const std::string providerAppId = "app_def_02_provider_appid";
+    const std::string consumerAppId = "app_def_02_client_appid";
+    const std::string ownerId = "5001";
+    const std::string session = "S0M33S3SSI0N";
+
+    struct cynara *m_cynara = nullptr;
+
+    AppInstallHelper provider(providerAppId);
+    AppInstallHelper consumer(consumerAppId);
+
+    std::string consumerLabel = consumer.generateAppLabel();
+
+    provider.addAppDefinedPrivilege(privilege);
+    consumer.addPrivilege(privilege);
+
+    ScopedInstaller req1(provider);
+    ScopedInstaller req2(consumer);
+
+    int ret = cynara_initialize(&m_cynara, nullptr);
+    RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+                         "cynara_initialize failed. ret: " << ret);
+    RUNNER_ASSERT_MSG(m_cynara != nullptr, "cynara struct was not initialized");
+
+    ret = cynara_check(
+                    m_cynara,
+                    consumerLabel.c_str(),
+                    session.c_str(),
+                    ownerId.c_str(),
+                    privilege.c_str());
+
+    cynara_finish(m_cynara);
+
+    RUNNER_ASSERT_MSG(ret == CYNARA_API_ACCESS_ALLOWED,
+                         "cynara_check returned wrong value: "
+                             << ret << " != " << CYNARA_API_ACCESS_ALLOWED << "."
+                             << " client: " << consumerLabel << ","
+                             << " session: " << session << ","
+                             << " user: " << ownerId << ","
+                             << " privilege: " << privilege);
+}
+