SM : Check if askuser is disabled in app policy tests 62/143062/2
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 8 Aug 2017 09:13:46 +0000 (11:13 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 8 Aug 2017 09:46:59 +0000 (11:46 +0200)
Change-Id: I2148b8eccddd561ac2514ab10348b885f2fdc48d

src/security-manager-tests/common/sm_commons.cpp
src/security-manager-tests/common/sm_commons.h
src/security-manager-tests/common/tzplatform.cpp
src/security-manager-tests/common/tzplatform.h
src/security-manager-tests/test_cases_app_policy.cpp

index 8f4b740..bd583a2 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <algorithm>
 #include <cstring>
+#include <fcntl.h>
 #include <ftw.h>
 #include <grp.h>
 #include <string>
@@ -457,6 +458,21 @@ void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int
         runAccessTest(label, uid, gid, testPath, accessType);
 }
 
+bool isAskuserDisabled() {
+    static bool isAskuserDisabled = false;
+    static bool isChecked = false;
+
+    if (isChecked)
+        return isAskuserDisabled;
+
+    std::string sysShare = TzPlatformConfig::getPath(TZ_SYS_SHARE);
+    std::string askDisableFile = sysShare + "/askuser_disable";
+
+    isAskuserDisabled = (access(askDisableFile.c_str(), F_OK) != -1);
+    isChecked = true;
+    return isAskuserDisabled;
+}
+
 bool isPrivilegePrivacy(const std::string &priv) {
     return (1 == privilege_info_is_privacy(priv.c_str()));
 }
index 804e887..346c1f7 100644 (file)
@@ -78,6 +78,7 @@ void runAccessTest(const std::string &label, uid_t uid, gid_t gid,
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int accessType);
 void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int accessType);
 
+bool isAskuserDisabled();
 bool isPrivilegePrivacy(const std::string &priv);
 int countPrivacyPrivileges(const PrivilegeVector &privs);
 int countPrivacyPrivileges(const std::vector<std::string> &privs);
index 522f74e..3d3dce7 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <pwd.h>
 #include <sys/types.h>
-#include <tzplatform_config.h>
 
 #include <dpl/test/test_runner.h>
 #include <memory.h>
@@ -79,5 +78,17 @@ const std::string globalAppDir()
     return appDir;
 }
 
+const std::string getPath(enum tzplatform_variable id) {
+    struct tzplatform_context *tzCtxPtr = nullptr;
+
+    RUNNER_ASSERT_MSG(0 == tzplatform_context_create(&tzCtxPtr), "Couldn't create tzplatform context");
+    TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
+
+    const char *path = tzplatform_context_getenv(tzCtxPtr, id);
+    RUNNER_ASSERT_MSG(nullptr != path,
+                          "tzplatform_context_getenv failed for getting " << static_cast<int>(id));
+    return path;
+}
+
 }
 
index 443fae3..fff4f5e 100644 (file)
 
 #include <string>
 
+#include <tzplatform_config.h>
+
 #include <temp_test_user.h>
 
 namespace TzPlatformConfig {
 
+const std::string getPath(enum tzplatform_variable id);
+
 uid_t getGlobalUserId(void);
 
 uid_t getGlobalGroupId(void);
index 0ead253..afd9a09 100644 (file)
@@ -45,7 +45,9 @@ RUNNER_CHILD_TEST(security_manager_ap1_app_policy_fetch_for_self) {
 
     unsigned expectedPolicyCount = countPrivacyPrivileges(app.getPrivileges());
 
-    RUNNER_ASSERT_MSG(expectedPolicyCount > 0, "Application won't be installed with any privacy privileges, fix test");
+    // If askuser is disabled there will be no privacy policy to expect
+    RUNNER_ASSERT_MSG(isAskuserDisabled() || expectedPolicyCount > 0,
+            "Application won't be installed with any privacy privileges, fix test");
 
     ScopedInstaller appInstall(app);
 
@@ -65,6 +67,10 @@ RUNNER_CHILD_TEST(security_manager_ap1_app_policy_fetch_for_self) {
 
             std::vector<PolicyEntry> policyEntries;
             Api::getPolicyForSelf(filter, policyEntries);
+            if (isAskuserDisabled()) {
+                //further checks do not make sense, but we've checked if app has permission to perform policy fetch
+                continue;
+            }
 
             RUNNER_ASSERT_MSG(policyEntries.size() != 0, "Policy is empty");
             RUNNER_ASSERT_MSG(policyEntries.size() == 1,