--- /dev/null
+/*
+ * 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);
+}
+