Changing function appDirPath to generate proper application path using
pkgId and appId values. Previous implementation tried to install all
applications directly into TZ_USER_APP directory, which was incorrect.
Change-Id: Iabdffd20ca37b6e2fb2c9ecb50d9ba58b16a857b
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
void mkdirSafe(const std::string &path, mode_t mode)
{
void mkdirSafe(const std::string &path, mode_t mode)
{
- RUNNER_ASSERT_ERRNO_MSG(0 == mkdir(path.c_str(), mode),
+ RUNNER_ASSERT_ERRNO_MSG(0 == mkdir(path.c_str(), mode) || errno == EEXIST,
"mkdir for <" << path << "> with mode <" << mode << "> failed");
}
"mkdir for <" << path << "> with mode <" << mode << "> failed");
}
+void mktreeSafe(const std::string &path, mode_t mode)
+{
+ // Create subsequent parent directories
+ // Assume that path is absolute - i.e. starts with '/'
+ for (size_t pos = 0; (pos = path.find("/", pos + 1)) != std::string::npos; )
+ mkdirSafe(path.substr(0, pos).c_str(), mode);
+
+ mkdirSafe(path, mode);
+}
+
void creatSafe(const std::string &path, mode_t mode)
{
RUNNER_ASSERT_ERRNO_MSG(-1 != creat(path.c_str(), mode),
void creatSafe(const std::string &path, mode_t mode)
{
RUNNER_ASSERT_ERRNO_MSG(-1 != creat(path.c_str(), mode),
std::string formatCstr(const char *cstr);
int files_compare(int fd1, int fd2);
void mkdirSafe(const std::string &path, mode_t mode);
std::string formatCstr(const char *cstr);
int files_compare(int fd1, int fd2);
void mkdirSafe(const std::string &path, mode_t mode);
+void mktreeSafe(const std::string &path, mode_t mode);
void creatSafe(const std::string &path, mode_t mode);
void symlinkSafe(const std::string &targetPath, const std::string &linkPath);
void removeDir(const std::string &path);
void creatSafe(const std::string &path, mode_t mode);
void symlinkSafe(const std::string &targetPath, const std::string &linkPath);
void removeDir(const std::string &path);
return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
}
return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
}
-static const std::string appDirPath(const TemporaryTestUser &user)
+static const std::string appDirPath(const TemporaryTestUser &user,
+ const std::string &appId, const std::string &pkgId)
{
struct tzplatform_context *tzCtxPtr = nullptr;
{
struct tzplatform_context *tzCtxPtr = nullptr;
"tzplatform_context_getenv failed"
<< "for getting sys rw app of user <" << user.getUserName() << ">");
"tzplatform_context_getenv failed"
<< "for getting sys rw app of user <" << user.getUserName() << ">");
+ return std::string(appDir) + "/" + pkgId + "/" + appId;
}
static const std::string nonAppDirPath(const TemporaryTestUser &user)
}
static const std::string nonAppDirPath(const TemporaryTestUser &user)
mode_t execFileMode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
mode_t normalFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
mode_t execFileMode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
mode_t normalFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
- mkdirSafe(dir, dirMode);
+ mktreeSafe(dir, dirMode);
creatSafe(dir + "/" + EXEC_FILE, execFileMode);
creatSafe(dir + "/" + NORMAL_FILE, normalFileMode);
symlinkSafe(dir + "/" + EXEC_FILE, dir + "/" + LINK_PREFIX + EXEC_FILE);
creatSafe(dir + "/" + EXEC_FILE, execFileMode);
creatSafe(dir + "/" + NORMAL_FILE, normalFileMode);
symlinkSafe(dir + "/" + EXEC_FILE, dir + "/" + LINK_PREFIX + EXEC_FILE);
dir + "/" + LINK_PREFIX + "non_app_" + NORMAL_FILE);
}
dir + "/" + LINK_PREFIX + "non_app_" + NORMAL_FILE);
}
-static void generateAppDir(const TemporaryTestUser &user)
+static void generateAppDir(const TemporaryTestUser &user,
+ const std::string &appId, const std::string &pkgId)
- const std::string dir = appDirPath(user);
+ const std::string dir = appDirPath(user, appId, pkgId);
const std::string nonAppDir = nonAppDirPath(user);
createInnerAppDir(dir, nonAppDir);
const std::string nonAppDir = nonAppDirPath(user);
createInnerAppDir(dir, nonAppDir);
createTestDir(dir + "/inner_dir");
}
createTestDir(dir + "/inner_dir");
}
-static void createTestDirs(const TemporaryTestUser &user)
+static void createTestDirs(const TemporaryTestUser &user,
+ const std::string &appId, const std::string &pkgId)
+ generateAppDir(user, appId, pkgId);
generateNonAppDir(user);
}
generateNonAppDir(user);
}
-static void removeTestDirs(const TemporaryTestUser &user)
+static void removeTestDirs(const TemporaryTestUser &user,
+ const std::string &appId, const std::string &pkgId)
- removeDir(appDirPath(user));
+ removeDir(appDirPath(user, appId, pkgId));
removeDir(nonAppDirPath(user));
}
removeDir(nonAppDirPath(user));
}
TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
testUser.create();
TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
testUser.create();
- removeTestDirs(testUser);
- createTestDirs(testUser);
+ removeTestDirs(testUser, sm_app_id, sm_pkg_id);
+ createTestDirs(testUser, sm_app_id, sm_pkg_id);
- const std::string userAppDirPath = appDirPath(testUser);
+ const std::string userAppDirPath = appDirPath(testUser, sm_app_id, sm_pkg_id);
//switch user to non-root
result = drop_root_privileges(testUser.getUid(), testUser.getGid());
//switch user to non-root
result = drop_root_privileges(testUser.getUid(), testUser.getGid());
TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
testUser.create();
TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
testUser.create();
- removeTestDirs(testUser);
- createTestDirs(testUser);
+ removeTestDirs(testUser, sm_app_id, sm_pkg_id);
+ createTestDirs(testUser, sm_app_id, sm_pkg_id);
- install_and_check(sm_app_id, sm_pkg_id, testUser, appDirPath(testUser), true);
+ install_and_check(sm_app_id, sm_pkg_id, testUser, appDirPath(testUser, sm_app_id, sm_pkg_id), true);
//switch user to non-root - root may not uninstall apps for specified users
result = drop_root_privileges(testUser.getUid(), testUser.getGid());
//switch user to non-root - root may not uninstall apps for specified users
result = drop_root_privileges(testUser.getUid(), testUser.getGid());
test_user.create();
test_user.getUidString(uid_string);
test_user.create();
test_user.getUidString(uid_string);
- removeTestDirs(test_user);
- createTestDirs(test_user);
+ removeTestDirs(test_user, sm_app_id, sm_pkg_id);
+ createTestDirs(test_user, sm_app_id, sm_pkg_id);
install_app(sm_app_id, sm_pkg_id, test_user.getUid());
install_app(sm_app_id, sm_pkg_id, test_user.getUid());
test_user.create();
test_user.getUidString(uid_string);
test_user.create();
test_user.getUidString(uid_string);
- removeTestDirs(test_user);
- createTestDirs(test_user);
+ removeTestDirs(test_user, sm_app_id, sm_pkg_id);
+ createTestDirs(test_user, sm_app_id, sm_pkg_id);
addUserRequest.setUid(test_user.getUid());
addUserRequest.setUserType(SM_USER_TYPE_NORMAL);
addUserRequest.setUid(test_user.getUid());
addUserRequest.setUserType(SM_USER_TYPE_NORMAL);
TemporaryTestUser test_user(new_user_name, GUM_USERTYPE_NORMAL, true);
test_user.create();
TemporaryTestUser test_user(new_user_name, GUM_USERTYPE_NORMAL, true);
test_user.create();
- removeTestDirs(test_user);
- createTestDirs(test_user);
+ removeTestDirs(test_user, app_id, pkg_id);
+ createTestDirs(test_user, app_id, pkg_id);
install_app(app_id, pkg_id, test_user.getUid());
install_app(app_id, pkg_id, test_user.getUid());