mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-27 01:00:38 +00:00
modify sandbox config struct member type
Signed-off-by: wangfeng <wangfeng277@huawei.com>
This commit is contained in:
parent
765413ae2f
commit
604ed52292
@ -1404,4 +1404,145 @@ HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0)
|
||||
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_41 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: App_Spawn_Sandbox_42
|
||||
* @tc.desc: parse config file for fstype .
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_42, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_42 start";
|
||||
std::string mJsconfig = "{ \
|
||||
\"mount-paths\": [{ \
|
||||
\"src-path\": \"/data/app/el1/<currentUserId>/base\", \
|
||||
\"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
|
||||
\"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
|
||||
\"dac-override-sensitive\": \"true\", \
|
||||
\"fs-type\": \"sharefs\", \
|
||||
\"options\": \"support_overwrite=1\" \
|
||||
}] \
|
||||
}";
|
||||
nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
|
||||
const char *mountPath = "mount-paths";
|
||||
nlohmann::json j_secondConfig = j_config[mountPath][0];
|
||||
OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
|
||||
|
||||
std::string fsType = OHOS::AppSpawn::SandboxUtils::GetSandboxFsType(j_secondConfig);
|
||||
int ret = strcmp(fsType.c_str(), "sharefs");
|
||||
if (SandboxUtils::deviceTypeEnable_ == true) {
|
||||
EXPECT_EQ(ret, 0);
|
||||
} else {
|
||||
EXPECT_NE(ret, 0);
|
||||
}
|
||||
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_42 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: App_Spawn_Sandbox_43
|
||||
* @tc.desc: get sandbox mount config when section is common.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_43, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_43 start";
|
||||
std::string mJsconfig = "{ \
|
||||
\"mount-paths\": [{ \
|
||||
\"src-path\": \"/data/app/el1/<currentUserId>/base\", \
|
||||
\"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
|
||||
\"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
|
||||
\"dac-override-sensitive\": \"true\", \
|
||||
\"fs-type\": \"sharefs\", \
|
||||
\"options\": \"support_overwrite=1\" \
|
||||
}] \
|
||||
}";
|
||||
nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
|
||||
const char *mountPath = "mount-paths";
|
||||
nlohmann::json j_secondConfig = j_config[mountPath][0];
|
||||
|
||||
OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
|
||||
OHOS::AppSpawn::SandboxUtils::SandboxMountConfig mountConfig;
|
||||
std::string section = "common";
|
||||
OHOS::AppSpawn::SandboxUtils::GetSandboxMountConfig(section, j_secondConfig, mountConfig);
|
||||
int ret = strcmp(mountConfig.fsType.c_str(), "sharefs");
|
||||
EXPECT_EQ(ret, 0);
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_43 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: App_Spawn_Sandbox_44
|
||||
* @tc.desc: get sandbox mount config when section is permission.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_44, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_44 start";
|
||||
std::string mJsconfig = "{ \
|
||||
\"mount-paths\": [{ \
|
||||
\"src-path\": \"/data/app/el1/<currentUserId>/base\", \
|
||||
\"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
|
||||
\"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
|
||||
\"dac-override-sensitive\": \"true\", \
|
||||
\"fs-type\": \"sharefs\", \
|
||||
\"options\": \"support_overwrite=1\" \
|
||||
}] \
|
||||
}";
|
||||
nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
|
||||
const char *mountPath = "mount-paths";
|
||||
nlohmann::json j_secondConfig = j_config[mountPath][0];
|
||||
|
||||
OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
|
||||
OHOS::AppSpawn::SandboxUtils::SandboxMountConfig mountConfig;
|
||||
std::string section = "permission";
|
||||
OHOS::AppSpawn::SandboxUtils::GetSandboxMountConfig(section, j_secondConfig, mountConfig);
|
||||
int ret = strcmp(mountConfig.fsType.c_str(), "sharefs");
|
||||
if (SandboxUtils::deviceTypeEnable_ == true) {
|
||||
EXPECT_EQ(ret, 0);
|
||||
} else {
|
||||
EXPECT_NE(ret, 0);
|
||||
}
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_44 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: App_Spawn_Sandbox_45
|
||||
* @tc.desc: parse config file for options.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_45 start";
|
||||
std::string mJsconfig = "{ \
|
||||
\"mount-paths\": [{ \
|
||||
\"src-path\": \"/data/app/el1/<currentUserId>/base\", \
|
||||
\"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
|
||||
\"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
|
||||
\"dac-override-sensitive\": \"true\", \
|
||||
\"fs-type\": \"sharefs\", \
|
||||
\"options\": \"support_overwrite=1\" \
|
||||
}] \
|
||||
}";
|
||||
nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
|
||||
const char *mountPath = "mount-paths";
|
||||
nlohmann::json j_secondConfig = j_config[mountPath][0];
|
||||
|
||||
OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
|
||||
std::string options = OHOS::AppSpawn::SandboxUtils::GetSandboxOptions(j_secondConfig);
|
||||
int ret = strcmp(options.c_str(), "support_overwrite=1");
|
||||
if (SandboxUtils::deviceTypeEnable_ == true) {
|
||||
EXPECT_EQ(ret, 0);
|
||||
} else {
|
||||
EXPECT_NE(ret, 0);
|
||||
}
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_45 end";
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -38,8 +38,7 @@ public:
|
||||
static std::set<std::string> GetMountPermissionNames();
|
||||
typedef struct {
|
||||
unsigned long mountFlags;
|
||||
const char *optionsPoint;
|
||||
const char *fsTypePoint;
|
||||
std::string optionsPoint;
|
||||
std::string fsType;
|
||||
std::string sandboxPath;
|
||||
} SandboxMountConfig;
|
||||
@ -107,8 +106,8 @@ private:
|
||||
static int32_t GetMountPermissionFlags(const std::string permissionName);
|
||||
static bool GetSandboxDacOverrideEnable(nlohmann::json &config);
|
||||
static unsigned long GetSandboxMountFlags(nlohmann::json &config);
|
||||
static const char *GetSandboxFsType(nlohmann::json &config);
|
||||
static const char *GetSandboxOptions(nlohmann::json &config);
|
||||
static std::string GetSandboxFsType(nlohmann::json &config);
|
||||
static std::string GetSandboxOptions(nlohmann::json &config);
|
||||
static std::string GetSandboxPath(const ClientSocket::AppProperty *appProperty, nlohmann::json &mntPoint,
|
||||
const std::string §ion, std::string sandboxRoot);
|
||||
static void GetSandboxMountConfig(const std::string §ion, nlohmann::json &mntPoint,
|
||||
|
@ -443,7 +443,7 @@ unsigned long SandboxUtils::GetSandboxMountFlags(nlohmann::json &config)
|
||||
return mountFlags;
|
||||
}
|
||||
|
||||
const char *SandboxUtils::GetSandboxFsType(nlohmann::json &config)
|
||||
std::string SandboxUtils::GetSandboxFsType(nlohmann::json &config)
|
||||
{
|
||||
std::string fsType;
|
||||
if (GetSandboxDacOverrideEnable(config) && (deviceTypeEnable_ == true)
|
||||
@ -452,11 +452,10 @@ const char *SandboxUtils::GetSandboxFsType(nlohmann::json &config)
|
||||
} else {
|
||||
fsType = "";
|
||||
}
|
||||
const char *fsTypePoint = fsType.empty() ? nullptr : fsType.c_str();
|
||||
return fsTypePoint;
|
||||
return fsType;
|
||||
}
|
||||
|
||||
const char *SandboxUtils::GetSandboxOptions(nlohmann::json &config)
|
||||
std::string SandboxUtils::GetSandboxOptions(nlohmann::json &config)
|
||||
{
|
||||
std::string options;
|
||||
if (GetSandboxDacOverrideEnable(config) && (deviceTypeEnable_ == true) &&
|
||||
@ -465,8 +464,7 @@ const char *SandboxUtils::GetSandboxOptions(nlohmann::json &config)
|
||||
} else {
|
||||
options = "";
|
||||
}
|
||||
const char *optionsPoint = options.empty() ? nullptr : options.c_str();
|
||||
return optionsPoint;
|
||||
return options;
|
||||
}
|
||||
|
||||
void SandboxUtils::GetSandboxMountConfig(const std::string §ion, nlohmann::json &mntPoint,
|
||||
@ -474,12 +472,10 @@ void SandboxUtils::GetSandboxMountConfig(const std::string §ion, nlohmann::j
|
||||
{
|
||||
if (section.compare(g_permissionPrefix) == 0) {
|
||||
mountConfig.optionsPoint = GetSandboxOptions(mntPoint);
|
||||
mountConfig.fsTypePoint = GetSandboxFsType(mntPoint);
|
||||
mountConfig.fsType = (mountConfig.fsTypePoint != nullptr) ? mountConfig.fsTypePoint : "";
|
||||
mountConfig.fsType = GetSandboxFsType(mntPoint);
|
||||
} else {
|
||||
mountConfig.fsType = (mntPoint.find(g_fsType) != mntPoint.end()) ? mntPoint[g_fsType].get<std::string>() : "";
|
||||
mountConfig.fsTypePoint = mountConfig.fsType.empty() ? nullptr : mountConfig.fsType.c_str();
|
||||
mountConfig.optionsPoint = nullptr;
|
||||
mountConfig.optionsPoint = "";
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -536,8 +532,8 @@ int SandboxUtils::DoAllMntPointsMount(const ClientSocket::AppProperty *appProper
|
||||
/* if app mount failed for special strategy, we need deal with common mount config */
|
||||
int ret = HandleSpecialAppMount(appProperty, srcPath, sandboxPath, mountConfig.fsType, mountFlags);
|
||||
if (ret < 0) {
|
||||
ret = DoAppSandboxMountOnce(srcPath.c_str(), sandboxPath.c_str(), mountConfig.fsTypePoint,
|
||||
mountFlags, mountConfig.optionsPoint, mountSharedFlag);
|
||||
ret = DoAppSandboxMountOnce(srcPath.c_str(), sandboxPath.c_str(), mountConfig.fsType.c_str(),
|
||||
mountFlags, mountConfig.optionsPoint.c_str(), mountSharedFlag);
|
||||
}
|
||||
if (ret) {
|
||||
std::string actionStatus = g_statusCheck;
|
||||
|
Loading…
Reference in New Issue
Block a user