Exclude policy-test at docker-build
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 14 Oct 2019 04:26:08 +0000 (13:26 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Thu, 17 Oct 2019 05:04:06 +0000 (14:04 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/apix/manager/CMakeLists.txt
src/apix/manager/tests/manager_tests.cpp
src/apix/manager/tests/tizen/policy_tests.cpp [new file with mode: 0644]
tools/codegen/templates/default.cpp.in

index 3d466f3fae0e96cb0d9882effb15c457971d8d40..cdaba61ce7070c07c53c3206d5ed2d478c359790 100644 (file)
@@ -16,4 +16,9 @@ ADD_APIX_LIBRARY(manager manager.cpp
                                                 manager_impl.cpp)
 
 FILE(GLOB MANAGER_TESTS "tests/*.cpp")
+
+IF(DEFINED GBS_BUILD)
+       FILE(GLOB TIZEN_POLICYD_TESTS "tests/tizen/*.cpp")
+ENDIF(DEFINED GBS_BUILD)
+
 ADD_APIX_TEST(${MANAGER_TESTS})
index b1b266ee25d5dd286d17dd57e58d73259fdd6eb8..30cac9a93dff68eed1cc383db54837c8d501f906 100644 (file)
@@ -21,8 +21,6 @@
 #include <osquery/notification.h>
 #include <osquery/logger.h>
 
-#include <policyd/core/policy-manager.h>
-
 using namespace osquery;
 
 class ManagerTests : public testing::Test {};
@@ -38,50 +36,6 @@ TEST_F(ManagerTests, test_manager_execute) {
        LOG(INFO) << "\t seconds: " << rows[0]["seconds"];
 }
 
-TEST_F(ManagerTests, test_manager_execute_policy) {
-       std::string query = "SELECT * FROM policy";
-       auto rows = OsqueryManager::execute(query);
-       EXPECT_TRUE(rows.size() > 0);
-
-       LOG(INFO) << "[Test] policy table rows:";
-       for (auto& r : rows) {
-               LOG(INFO) << "\t name: " << r["name"];
-               LOG(INFO) << "\t value: " << r["value"];
-       }
-
-       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-
-       LOG(INFO) << "[Test] policy table rows with where clause:";
-       for (auto& r : rows) {
-               LOG(INFO) << "\t name: " << r["name"];
-               LOG(INFO) << "\t value: " << r["value"];
-       }
-
-       EXPECT_EQ(rows.size(), 1);
-}
-
-TEST_F(ManagerTests, test_manager_execute_policy_update) {
-       auto& manager = policyd::PolicyManager::Instance();
-       manager.enroll("admin", 0);
-
-       std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       auto rows = OsqueryManager::execute(query);
-       /// Initial policy value
-       EXPECT_EQ(rows[0]["value"], std::to_string(1));
-
-       query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-       EXPECT_EQ(rows.size(), 0);
-
-       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-       /// Initial policy value
-       EXPECT_EQ(rows[0]["value"], std::to_string(3));
-
-       manager.disenroll("admin", 0);
-}
-
 TEST_F(ManagerTests, test_manager_subscribe) {
        int called = 0;
        auto callback = [&](const Row& row) {
diff --git a/src/apix/manager/tests/tizen/policy_tests.cpp b/src/apix/manager/tests/tizen/policy_tests.cpp
new file mode 100644 (file)
index 0000000..e3a5a57
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (c) 2019 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 <gtest/gtest.h>
+
+#include <osquery_manager.h>
+
+#include <osquery/logger.h>
+
+#include <policyd/core/policy-manager.h>
+
+using namespace osquery;
+
+class PolicydTests : public testing::Test {};
+
+TEST_F(PolicydTests, select) {
+       std::string query = "SELECT * FROM policy";
+       auto rows = OsqueryManager::execute(query);
+       EXPECT_TRUE(rows.size() > 0);
+
+       LOG(INFO) << "[Test] policy table rows:";
+       for (auto& r : rows) {
+               LOG(INFO) << "\t name: " << r["name"];
+               LOG(INFO) << "\t value: " << r["value"];
+       }
+
+       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+
+       LOG(INFO) << "[Test] policy table rows with where clause:";
+       for (auto& r : rows) {
+               LOG(INFO) << "\t name: " << r["name"];
+               LOG(INFO) << "\t value: " << r["value"];
+       }
+
+       EXPECT_EQ(rows.size(), 1);
+}
+
+TEST_F(PolicydTests, update) {
+       auto& manager = policyd::PolicyManager::Instance();
+       manager.enroll("admin", 0);
+
+       std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       auto rows = OsqueryManager::execute(query);
+       /// Initial policy value
+       EXPECT_EQ(rows[0]["value"], std::to_string(1));
+
+       query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+       EXPECT_EQ(rows.size(), 0);
+
+       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+       /// Initial policy value
+       EXPECT_EQ(rows[0]["value"], std::to_string(3));
+
+       manager.disenroll("admin", 0);
+}
index 61c26bb43bd41d989126c4c17ec32d6366d2d020..d28ed882be45cd8ca91bd2f42b466f85bd84ced0 100644 (file)
@@ -29,9 +29,8 @@ osquery::TableRows {{function}}(QueryContext& context);
 {% if function_update != "" %}\
 osquery::QueryData {{function_update}}(QueryContext& context,
                                        const PluginRequest& request);
-/// patch end
-
 {% endif %}\
+/// patch end
 
 {% else %}\
 osquery::QueryData {{function}}(QueryContext& context);
@@ -40,12 +39,10 @@ osquery::QueryData {{function}}(QueryContext& context);
 {% if function_update != "" %}\
 osquery::QueryData {{function_update}}(QueryContext& context,
                                        const PluginRequest& request);
-/// patch end
-
 {% endif %}\
+/// patch end
 
 {% endif %}\
-
 {% else %}
 class {{class_name}} {
  public: