Merge remote-tracking branch 'tizen/security-manager' into appdefined 83/126683/1
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 24 Apr 2017 16:20:32 +0000 (18:20 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 24 Apr 2017 16:49:36 +0000 (18:49 +0200)
Change-Id: I430ce5badf02a457c2f1dac9b3871d6e2ae3c65c

1  2 
src/security-manager-tests/common/scoped_installer.h
src/security-manager-tests/test_cases.cpp

@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 + * Copyright (c) 2016-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.
  #include <sm_api.h>
  #include <temp_test_user.h>
  #include <synchronization_pipe.h>
+ #include <dpl/test/safe_cleanup.h>
  
  class ScopedInstaller {
  public:
      ScopedInstaller(const AppInstallHelper &app, bool requestUid = true)
          : m_appId(app.getAppId()),
            m_uid(app.getUID()),
+           m_installType(app.getInstallType()),
            m_shouldUninstall(true),
            m_requestUid(requestUid),
            m_creatorPid(getpid())
          for (const auto& typePaths : app.getFilesMap())
              for (const auto& path : typePaths.second)
                  instReq.addPath(path, typePaths.first);
 -        for (const auto &priv : app.getPrivileges()) {
 +        for (const auto &priv : app.getPrivileges())
              instReq.addPrivilege(priv.c_str());
 -        }
 +        for (const auto &priv : app.getAppDefinedPrivileges())
 +            instReq.addAppDefinedPrivilege(priv);
 +
          SecurityManagerTest::Api::install(instReq);
      }
  
@@@ -72,6 -72,7 +74,7 @@@
      ScopedInstaller(ScopedInstaller &&other)
          : m_appId(std::move(other.m_appId)),
            m_uid(other.m_uid),
+           m_installType(other.m_installType),
            m_shouldUninstall(other.m_shouldUninstall),
            m_requestUid(other.m_requestUid),
            m_creatorPid(other.m_creatorPid)
@@@ -85,7 -86,9 +88,9 @@@
  
      virtual ~ScopedInstaller() {
          if (m_creatorPid == getpid())
-             uninstallApp();
+         {
+             SafeCleanup::run([this]{ uninstallApp(); });
+         }
      }
  
      void uninstallApp() {
          uninstReq.setAppId(m_appId);
          if (m_requestUid)
              uninstReq.setUid(m_uid);
+         if (m_installType != SM_APP_INSTALL_NONE)
+             uninstReq.setInstallType(m_installType);
          SecurityManagerTest::Api::uninstall(uninstReq);
          m_shouldUninstall = false;
      }
  protected:
      std::string m_appId;
      uid_t m_uid;
+     app_install_type m_installType;
      bool m_shouldUninstall;
      bool m_requestUid;
      pid_t m_creatorPid;
@@@ -471,16 -471,14 +471,14 @@@ RUNNER_TEST(security_manager_09_app_ins
      install(users[1], pkgId[0], appId[0], version[0], author[0], hybrid[1], SECURITY_MANAGER_ERROR_INPUT_PARAM);
      // uid_1, pkg_0, app_0, version_0, author_1, not hybrid -> fail (author of app_0 must be the same)
      install(users[1], pkgId[0], appId[0], version[0], author[1], hybrid[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
-     // uid_1, pkg_0, app_0, version_1, author_0, not hybrid -> fail (version of app_0 must be the same)
-     install(users[1], pkgId[0], appId[0], version[1], author[0], hybrid[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+     // uid_1, pkg_0, app_0, version_1, author_0, not hybrid -> ok (version upgrade)
+     install(users[1], pkgId[0], appId[0], version[1], author[0], hybrid[0], SECURITY_MANAGER_SUCCESS);
      // uid_1, pkg_1, app_0, version_0, author_0, not hybrid -> fail (pkg of app_0 must be the same)
      install(users[1], pkgId[1], appId[0], version[0], author[0], hybrid[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
      // uid_0, pkg_0, app_0, version_0, author_0, not hybrid -> ok (the same app again)
      install(users[0], pkgId[0], appId[0], version[0], author[0], hybrid[0], SECURITY_MANAGER_SUCCESS, false);
      // uid_0, pkg_1, app_0, version_0, author_0, not hybrid -> fail (app_name + uid must be unique)
      install(users[0], pkgId[1], appId[0], version[0], author[0], hybrid[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
-     // uid_0, pkg_0, app_0, version_1, author_0, not hybrid -> fail (app_name + uid must be unique)
-     install(users[0], pkgId[0], appId[0], version[1], author[0], hybrid[0],  SECURITY_MANAGER_ERROR_INPUT_PARAM);
      // uid_0, pkg_0, app_0, version_0, author_1, not hybrid -> fail (app_name + uid must be unique)
      install(users[0], pkgId[0], appId[0], version[0], author[1], hybrid[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
  }
@@@ -510,8 -508,7 +508,8 @@@ RUNNER_TEST(security_manager_20_user_cy
  {
      // FIXME - whitebox - cynara
      const char *const MAIN_BUCKET = "MAIN";
 -    const char *const MANIFESTS_BUCKET = "MANIFESTS";
 +    const char *const MANIFESTS_GLOBAL_BUCKET = "MANIFESTS_GLOBAL";
 +    const char *const MANIFESTS_LOCAL_BUCKET = "MANIFESTS_LOCAL";
      const char *const ADMIN_BUCKET = "ADMIN";
      const char *const USER_TYPE_NORMAL_BUCKET = "USER_TYPE_NORMAL";
      CynaraTestAdmin::Admin admin;
      CynaraTestAdmin::CynaraPoliciesContainer emptyContainer;
  
      admin.listPolicies(MAIN_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
 -    admin.listPolicies(MANIFESTS_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
 +    admin.listPolicies(MANIFESTS_GLOBAL_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
 +    admin.listPolicies(MANIFESTS_LOCAL_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
      admin.listPolicies(CYNARA_ADMIN_DEFAULT_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
      admin.listPolicies(ADMIN_BUCKET, CYNARA_ADMIN_WILDCARD, uid_string.c_str(), CYNARA_ADMIN_WILDCARD, emptyContainer, CYNARA_API_SUCCESS);
  }