Add ScopedAppLauncher 13/229813/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 3 Apr 2020 20:00:22 +0000 (22:00 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Thu, 9 Apr 2020 16:26:11 +0000 (16:26 +0000)
Needed to check smack rules while app is running

Change-Id: I6ef63fc76dd27fb6119245541dc2fd9544ff98fe

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

index cf08aa4..57ed71f 100644 (file)
@@ -58,6 +58,7 @@ SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/policy_configuration.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/sm_commons.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/template_parser.cpp
+    ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/scoped_app_launcher.cpp
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_client.cpp
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_admin.cpp
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/plugins/plugins.cpp
diff --git a/src/security-manager-tests/common/scoped_app_launcher.cpp b/src/security-manager-tests/common/scoped_app_launcher.cpp
new file mode 100644 (file)
index 0000000..8647535
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2020 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 <scoped_app_launcher.h>
+#include <sm_api.h>
+#include <sm_commons.h>
+#include <tests_common.h>
+
+using namespace SecurityManagerTest;
+
+ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper& app)
+{
+    SynchronizationPipe syncPipe;
+
+    m_pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(m_pid >= 0, "Fork failed");
+    if (m_pid != 0) {
+        m_syncPipe.claimParentEp();
+        m_syncPipe.wait();
+    } else {
+        m_syncPipe.claimChildEp();
+
+        RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(app.getUID(), app.getGID()) == 0,
+                                "launcher failed");
+        Api::prepareAppCandidate();
+        Api::prepareApp(app.getAppId().c_str());
+
+        m_syncPipe.post();
+        m_syncPipe.wait();
+        exit(0);
+    }
+}
+
+ScopedAppLauncher::~ScopedAppLauncher()
+{
+    m_syncPipe.post();
+    waitPid(m_pid);
+}
diff --git a/src/security-manager-tests/common/scoped_app_launcher.h b/src/security-manager-tests/common/scoped_app_launcher.h
new file mode 100644 (file)
index 0000000..496df68
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+#pragma once
+
+#include <app_install_helper.h>
+#include <synchronization_pipe.h>
+
+class ScopedAppLauncher final {
+public:
+    ScopedAppLauncher(const AppInstallHelper& app);
+    ~ScopedAppLauncher();
+
+    ScopedAppLauncher(const ScopedAppLauncher&) = delete;
+    ScopedAppLauncher& operator=(const ScopedAppLauncher&) = delete;
+
+private:
+    SynchronizationPipe m_syncPipe;
+    pid_t m_pid;
+};