!1262 修改storage_service失败用例

Merge pull request !1262 from lvyuanyuan/myfeature
This commit is contained in:
openharmony_ci 2024-09-12 02:31:33 +00:00 committed by Gitee
commit 138426e742
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 300 additions and 89 deletions

View File

@ -343,6 +343,7 @@ group("storage_daemon_unit_test") {
"crypto/test/fscrypt_key_v1_ext_test:fscrypt_key_v1_ext_test",
"crypto/test/iam_client_test:iam_client_test",
"crypto/test/iam_client_user_auth_framework_test:iam_client_user_auth_framework_test",
"crypto/test/key_backup_test:key_backup_test",
"crypto/test/key_manager_test:key_manager_test",
"file_sharing/test:file_sharing_test",
"ipc/test:storage_daemon_ipc_test",

View File

@ -15,6 +15,8 @@
#include <gtest/gtest.h>
#include "directory_ex.h"
#include "storage_daemon_client.h"
#include "ipc/istorage_daemon.h"
#include "storage_service_errno.h"
@ -134,8 +136,15 @@ HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_MountD
std::string relativePath = "account";
std::string networkId = "testnetworkid";
std::string deviceId = "testdevid";
std::string path = "/mnt/data/" + std::to_string(userId) + "/hmdfs/";
OHOS::ForceRemoveDirectory(path);
int32_t ret = storageDaemonClient_->MountDfsDocs(userId, relativePath, networkId, deviceId);
EXPECT_EQ(ret, E_PREPARE_DIR);
OHOS::ForceCreateDirectory(path);
ret = storageDaemonClient_->MountDfsDocs(userId, relativePath, networkId, deviceId);
EXPECT_EQ(ret, E_MOUNT);
OHOS::ForceRemoveDirectory(path);
GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_MountDfsDocs_001 end";
}
@ -299,7 +308,7 @@ HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_Genera
std::string keyId = "keyId";
int32_t ret = storageDaemonClient_->GenerateAppkey(userid, appUid, keyId);
EXPECT_EQ(ret, -ENOENT);
EXPECT_EQ(ret, -ENOTSUP);
ret = storageDaemonClient_->DeleteAppkey(userid, keyId);
EXPECT_EQ(ret, -ENOENT);

View File

@ -0,0 +1,61 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# 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.
import("//build/test.gni")
import("//foundation/filemanagement/storage_service/storage_service_aafwk.gni")
ohos_unittest("KeyBackupTest") {
branch_protector_ret = "pac_ret"
sanitize = {
integer_overflow = true
cfi = true
cfi_cross_dso = true
debug = false
blocklist = "${storage_service_path}/cfi_blocklist.txt"
}
module_out_path = "storage_service/storage_daemon"
defines = [
"STORAGE_LOG_TAG = \"StorageDaemon\"",
"LOG_DOMAIN = 0xD004301",
"USER_CRYPTO_MIGRATE_KEY",
"private = public",
]
include_dirs = [
"${storage_daemon_path}/include/crypto",
"${storage_service_common_path}/include",
]
sources = [
"${storage_daemon_path}/crypto/src/key_backup.cpp",
"key_backup_test.cpp",
]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
deps += [ "${storage_daemon_path}:storage_common_utils" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"huks:libhukssdk",
]
}
group("key_backup_test") {
testonly = true
deps = [ ":KeyBackupTest" ]
}

View File

@ -0,0 +1,133 @@
/*
* Copyright (C) 2022-2024 Huawei Device Co., Ltd.
* 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 "key_backup.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "directory_ex.h"
using namespace std;
using namespace testing::ext;
using namespace testing;
namespace OHOS::StorageDaemon {
constexpr static mode_t DEFAULT_WRITE_FILE_PERM = 0644;
constexpr static uint32_t MAX_FILE_NUM = 5;
constexpr uint32_t INVALID_LOOP_NUM = 0xFFFFFFFF;
class KeyBackupTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void KeyBackupTest::SetUpTestCase(void)
{
GTEST_LOG_(INFO) << "SetUpTestCase Start";
}
void KeyBackupTest::TearDownTestCase(void)
{
GTEST_LOG_(INFO) << "TearDownTestCase Start";
}
void KeyBackupTest::SetUp(void)
{
GTEST_LOG_(INFO) << "SetUp Start";
}
void KeyBackupTest::TearDown(void)
{
GTEST_LOG_(INFO) << "TearDown Start";
}
/**
* @tc.name: KeyBackup_GetBackupDir_000
* @tc.desc: Verify the GetBackupDir function.
* @tc.type: FUNC
* @tc.require: IAHHWW
*/
HWTEST_F(KeyBackupTest, KeyBackup_GetBackupDir_000, TestSize.Level1)
{
GTEST_LOG_(INFO) << "KeyBackup_GetBackupDir_000 Start";
std::string origDir = DEVICE_EL1_DIR;
std::string backupDir;
EXPECT_EQ(KeyBackup::GetInstance().GetBackupDir(origDir, backupDir), 0);
EXPECT_EQ(backupDir, DEVICE_EL1_DIR + BACKUP_NAME);
origDir = "test";
backupDir.clear();
EXPECT_EQ(KeyBackup::GetInstance().GetBackupDir(origDir, backupDir), -1);
EXPECT_EQ(backupDir, "");
origDir = "/test";
EXPECT_EQ(KeyBackup::GetInstance().GetBackupDir(origDir, backupDir), -1);
EXPECT_EQ(backupDir, "");
origDir = "test/path/";
EXPECT_EQ(KeyBackup::GetInstance().GetBackupDir(origDir, backupDir), 0);
EXPECT_EQ(backupDir, "test/path_bak/");
GTEST_LOG_(INFO) << "KeyBackup_GetBackupDir_000 end";
}
/**
* @tc.name: KeyBackup_GetLoopMaxNum_001
* @tc.desc: Verify the GetLoopMaxNum function.
* @tc.type: FUNC
* @tc.require: IAHHWW
*/
HWTEST_F(KeyBackupTest, KeyBackup_GetLoopMaxNum_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "KeyBackup_GetLoopMaxNum_001 Start";
EXPECT_EQ(KeyBackup::GetInstance().GetLoopMaxNum(MAX_FILE_NUM + 1), INVALID_LOOP_NUM);
EXPECT_EQ(KeyBackup::GetInstance().GetLoopMaxNum(MAX_FILE_NUM), 31);
GTEST_LOG_(INFO) << "KeyBackup_GetLoopMaxNum_001 end";
}
/**
* @tc.name: KeyBackup_HandleCopyDir_001
* @tc.desc: Verify the HandleCopyDir function.
* @tc.type: FUNC
* @tc.require: IAHHWW
*/
HWTEST_F(KeyBackupTest, KeyBackup_HandleCopyDir_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "KeyBackup_HandleCopyDir_001 Start";
string toPath = "/data/test/KeyBackup/test3";
string fromPath = "/data/test/KeyBackup/test2/";
EXPECT_FALSE(access(toPath.c_str(), F_OK) == 0);
EXPECT_FALSE(access(fromPath.c_str(), F_OK) == 0);
EXPECT_EQ(KeyBackup::GetInstance().HandleCopyDir(fromPath, toPath), -1);
string baseDir = "/data/test/KeyBackup/";
EXPECT_EQ(KeyBackup::GetInstance().MkdirParent(baseDir, DEFAULT_WRITE_FILE_PERM), 0);
EXPECT_EQ(KeyBackup::GetInstance().HandleCopyDir(fromPath, toPath), 0);
EXPECT_EQ(KeyBackup::GetInstance().MkdirParent(fromPath, DEFAULT_WRITE_FILE_PERM), 0);
EXPECT_TRUE(access(fromPath.c_str(), F_OK) == 0);
EXPECT_EQ(KeyBackup::GetInstance().HandleCopyDir(fromPath, toPath), 0);
struct FileAttr attr;
struct FileAttr attr2;
EXPECT_EQ(KeyBackup::GetInstance().GetAttr(toPath, attr), 0);
EXPECT_EQ(KeyBackup::GetInstance().GetAttr(fromPath, attr2), 0);
EXPECT_EQ(attr.mode, attr2.mode);
EXPECT_TRUE(OHOS::ForceRemoveDirectory(baseDir));
EXPECT_FALSE(access(baseDir.c_str(), F_OK) == 0);
GTEST_LOG_(INFO) << "KeyBackup_HandleCopyDir_001 end";
}
}

View File

@ -61,10 +61,7 @@ ohos_unittest("KeyManagerTest") {
"//third_party/googletest:gtest_main",
]
deps += [
"${storage_daemon_path}:storage_common_utils",
#"${storage_daemon_path}/libfscrypt:libfscryptutils",
]
deps += [ "${storage_daemon_path}:storage_common_utils" ]
external_deps = [
"c_utils:utils",

View File

@ -24,8 +24,11 @@
#include "base_key_mock.h"
#include "directory_ex.h"
#include "fscrypt_control_mock.h"
#include "fscrypt_key_v2_mock.h"
#include "fscrypt_key_v2.h"
#include "key_control_mock.h"
#include "fscrypt_key_v2.h"
#include "mount_manager_mock.h"
#include "storage_service_errno.h"
#include "utils/file_utils.h"
@ -33,6 +36,10 @@
using namespace std;
using namespace testing::ext;
using namespace testing;
namespace {
constexpr const char *UECE_PATH = "/dev/fbex_uece";
}
namespace OHOS::StorageDaemon {
class KeyManagerSupTest : public testing::Test {
@ -43,6 +50,9 @@ public:
void TearDown();
static inline shared_ptr<MountManagerMoc> mountManagerMoc_ = nullptr;
static inline shared_ptr<FscryptKeyV2Moc> fscryptKeyMock_ = nullptr;
static inline shared_ptr<KeyControlMoc> keyControlMock_ = nullptr;
static inline shared_ptr<BaseKeyMoc> baseKeyMock_ = nullptr;
static inline shared_ptr<FscryptControlMoc> fscryptControlMock_ = nullptr;
};
void KeyManagerSupTest::SetUpTestCase(void)
@ -52,6 +62,12 @@ void KeyManagerSupTest::SetUpTestCase(void)
MountManagerMoc::mountManagerMoc = mountManagerMoc_;
fscryptKeyMock_ = make_shared<FscryptKeyV2Moc>();
FscryptKeyV2Moc::fscryptKeyV2Moc = fscryptKeyMock_;
fscryptControlMock_ = make_shared<FscryptControlMoc>();
FscryptControlMoc::fscryptControlMoc = fscryptControlMock_;
keyControlMock_ = make_shared<KeyControlMoc>();
KeyControlMoc::keyControlMoc = keyControlMock_;
baseKeyMock_ = make_shared<BaseKeyMoc>();
BaseKeyMoc::baseKeyMoc = baseKeyMock_;
}
void KeyManagerSupTest::TearDownTestCase(void)
@ -61,6 +77,12 @@ void KeyManagerSupTest::TearDownTestCase(void)
mountManagerMoc_ = nullptr;
FscryptKeyV2Moc::fscryptKeyV2Moc = nullptr;
fscryptKeyMock_ = nullptr;
FscryptControlMoc::fscryptControlMoc = nullptr;
fscryptControlMock_ = nullptr;
KeyControlMoc::keyControlMoc = nullptr;
keyControlMock_ = nullptr;
BaseKeyMoc::baseKeyMoc = nullptr;
baseKeyMock_ = nullptr;
}
void KeyManagerSupTest::SetUp(void)
@ -113,34 +135,45 @@ HWTEST_F(KeyManagerSupTest, KeyManager_GenerateAppkey_001, TestSize.Level1)
unsigned int user = 800;
string keyId;
bool existUece = true;
if (access(UECE_PATH, F_OK) != 0) {
existUece = false;
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -ENOTSUP);
std::ofstream file(UECE_PATH);
EXPECT_GT(open(UECE_PATH, O_RDWR), 0);
}
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl4Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -ENOENT);
string basePath = "/data/app/el2/" + to_string(user);
string path = basePath + "/base";
EXPECT_TRUE(OHOS::ForceCreateDirectory(path));
auto el2Key = KeyManager::GetInstance()->GetUserElKey(user, EL2_KEY);
bool exist = true;
if (el2Key == nullptr) {
exist = false;
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -ENOENT);
KeyManager::GetInstance()->SaveUserElKey(user, EL2_KEY, elKey);
}
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL4_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*keyControlMock_, KeyCtrlGetFscryptVersion(_)).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*fscryptKeyMock_, GenerateAppkey(_, _, _)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -EFAULT);
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
EXPECT_CALL(*fscryptKeyMock_, GenerateAppkey(_, _, _)).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), 0);
if (!exist) {
KeyManager::GetInstance()->userEl2Key_.erase(user);
}
KeyManager::GetInstance()->userEl4Key_.erase(user);
KeyManager::GetInstance()->userEl4Key_[user] = nullptr;
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -ENOENT);
KeyManager::GetInstance()->userEl4Key_.erase(user);
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->GenerateAppkey(user, 100, keyId), -ENOENT);
EXPECT_TRUE(OHOS::ForceRemoveDirectory(basePath));
ASSERT_TRUE(OHOS::ForceRemoveDirectory(keyDir));
if (!existUece) {
OHOS::RemoveFile(UECE_PATH);
}
GTEST_LOG_(INFO) << "KeyManager_GenerateAppkey_001 end";
}
@ -157,29 +190,29 @@ HWTEST_F(KeyManagerSupTest, KeyManager_DeleteAppkey_001, TestSize.Level1)
string keyId;
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl4Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(user, keyId), -ENOENT);
unsigned int userExist = 100;
auto el2Key = KeyManager::GetInstance()->GetUserElKey(userExist, EL2_KEY);
bool exist = true;
if (el2Key == nullptr) {
exist = false;
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(userExist, keyId), -ENOENT);
KeyManager::GetInstance()->SaveUserElKey(userExist, EL2_KEY, elKey);
}
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
EXPECT_CALL(*fscryptKeyMock_, DeleteAppkey(_)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(userExist, keyId), -EFAULT);
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
EXPECT_CALL(*fscryptKeyMock_, DeleteAppkey(_)).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(userExist, keyId), 0);
if (!exist) {
KeyManager::GetInstance()->userEl2Key_.erase(userExist);
}
string basePath = "/data/app/el2/" + to_string(user);
string path = basePath + "/base";
EXPECT_TRUE(OHOS::ForceCreateDirectory(path));
EXPECT_CALL(*mountManagerMoc_, CheckMountFileByUser(_)).WillOnce(Return(true));
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL4_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*keyControlMock_, KeyCtrlGetFscryptVersion(_)).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*fscryptKeyMock_, DeleteAppkey(_)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(user, keyId), -EFAULT);
EXPECT_CALL(*fscryptKeyMock_, DeleteAppkey(_)).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(user, keyId), 0);
KeyManager::GetInstance()->userEl4Key_.erase(user);
KeyManager::GetInstance()->userEl4Key_[user] = nullptr;
EXPECT_EQ(KeyManager::GetInstance()->DeleteAppkey(user, keyId), -ENOENT);
KeyManager::GetInstance()->userEl4Key_.erase(user);
EXPECT_TRUE(OHOS::ForceRemoveDirectory(basePath));
ASSERT_TRUE(OHOS::ForceRemoveDirectory(keyDir));
GTEST_LOG_(INFO) << "KeyManager_DeleteAppkey_001 end";
}
}

View File

@ -282,7 +282,7 @@ HWTEST_F(KeyManagerTest, KeyManager_ActiveCeSceSeceUserKey_001, TestSize.Level1)
KeyManager::GetInstance()->userEl2Key_[user] = tmpKey;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->ActiveCeSceSeceUserKey(user, EL2_KEY, token, secret), 0);
int eL6Key = 6;
KeyType type = static_cast<KeyType>(eL6Key);
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
@ -324,7 +324,7 @@ HWTEST_F(KeyManagerTest, KeyManager_ActiveCeSceSeceUserKey_002, TestSize.Level1)
unsigned int user = 1;
std::vector<uint8_t> token = {};
std::vector<uint8_t> secret = {};
std::string keyUeceDir = UECE_DIR + "/" + std::to_string(user);
std::string keyDir = USER_EL5_DIR + "/" + std::to_string(user);
EXPECT_TRUE(OHOS::ForceCreateDirectory(keyDir));
@ -467,7 +467,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SetDirectoryElPolicy, TestSize.Level1)
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->SetDirectoryElPolicy(user, type, vec), -ENOENT);
std::shared_ptr<BaseKey> tmpKey = std::dynamic_pointer_cast<BaseKey>(std::make_shared<FscryptKeyV2>("test"));
KeyManager::GetInstance()->userEl1Key_[user] = tmpKey;
vec.push_back({1, "/test"});
@ -592,7 +592,7 @@ HWTEST_F(KeyManagerTest, KeyManager_UpdateKeyContext_001, TestSize.Level1)
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).Times(3).WillOnce(Return(false))\
.WillOnce(Return(false)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->UpdateKeyContext(userId), 0);
KeyManager::GetInstance()->saveESecretStatus[userId] = true;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).Times(4).WillOnce(Return(false))\
.WillOnce(Return(false)).WillOnce(Return(false)).WillOnce(Return(true));
@ -642,7 +642,7 @@ HWTEST_F(KeyManagerTest, KeyManager_RestoreUserKey_000, TestSize.Level1)
GTEST_LOG_(INFO) << "KeyManager_RestoreUserKey_000 Start";
uint32_t userId = 1;
KeyType type = EL1_KEY;
#ifdef USER_CRYPTO_MIGRATE_KEY
int eL6Key = 6;
type = static_cast<KeyType>(eL6Key);
@ -951,7 +951,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SaveUserElKey_001, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl1Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GetUserElKey(user, EL1_KEY), nullptr);
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL1_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
@ -981,7 +981,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SaveUserElKey_002, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl2Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GetUserElKey(user, EL2_KEY), nullptr);
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL2_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
@ -1011,7 +1011,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SaveUserElKey_003, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl3Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GetUserElKey(user, EL3_KEY), nullptr);
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL3_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
@ -1041,7 +1041,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SaveUserElKey_004, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl4Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GetUserElKey(user, EL4_KEY), nullptr);
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL4_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
@ -1071,7 +1071,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SaveUserElKey_005, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
KeyManager::GetInstance()->userEl5Key_.erase(user);
EXPECT_EQ(KeyManager::GetInstance()->GetUserElKey(user, EL5_KEY), nullptr);
string keyDir = KeyManager::GetInstance()->GetKeyDirByUserAndType(user, EL5_KEY);
ASSERT_TRUE(OHOS::ForceCreateDirectory(keyDir));
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
@ -1157,7 +1157,7 @@ HWTEST_F(KeyManagerTest, KeyManager_InactiveUserElKey_001, TestSize.Level1)
shared_ptr<FscryptKeyV2> elKey = make_shared<FscryptKeyV2>("/data/test");
userElxKey_[user] = elKey;
EXPECT_CALL(*fscryptKeyMock_, InactiveKey(_, _)).WillOnce(Return(false));
EXPECT_EQ(KeyManager::GetInstance()->InactiveUserElKey(user, userElxKey_), -EFAULT);
@ -1292,7 +1292,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SetDirectoryElPolicy_001, TestSize.Level1)
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->SetDirectoryElPolicy(user, EL1_KEY, vec), -ENOENT);
KeyManager::GetInstance()->userEl1Key_[user] = elKey;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_CALL(*fscryptControlMock_, LoadAndSetPolicy(_, _)).WillOnce(Return(-1));
@ -1321,7 +1321,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SetDirectoryElPolicy_002, TestSize.Level1)
vec.push_back(file);
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->SetDirectoryElPolicy(user, EL2_KEY, vec), -ENOENT);
KeyManager::GetInstance()->userEl2Key_[user] = elKey;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_CALL(*fscryptControlMock_, LoadAndSetPolicy(_, _)).WillOnce(Return(0));
@ -1347,7 +1347,7 @@ HWTEST_F(KeyManagerTest, KeyManager_SetDirectoryElPolicy_003, TestSize.Level1)
KeyManager::GetInstance()->userEl2Key_[user] = elKey;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_EQ(KeyManager::GetInstance()->SetDirectoryElPolicy(user, EL3_KEY, vec), -ENOENT);
KeyManager::GetInstance()->userEl3Key_[user] = elKey;
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_CALL(*fscryptControlMock_, LoadAndSetPolicy(_, _)).WillOnce(Return(0));
@ -1571,34 +1571,6 @@ HWTEST_F(KeyManagerTest, KeyManager_ProcUpgradeKey_002, TestSize.Level1)
GTEST_LOG_(INFO) << "KeyManager_ProcUpgradeKey_0200 end";
}
/**
* @tc.name: KeyManager_InitGlobalUserKeys_001
* @tc.desc: Verify the KeyManager InitGlobalUserKeys function.
* @tc.type: FUNC
* @tc.require: SR000H0CM9
*/
HWTEST_F(KeyManagerTest, KeyManager_InitGlobalUserKeys_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "KeyManager_InitGlobalUserKeys_0100 start";
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(false));
auto ret = KeyManager::GetInstance()->InitGlobalUserKeys();
EXPECT_EQ(ret, 0);
EXPECT_CALL(*fscryptControlMock_, GetFscryptVersionFromPolicy()).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*keyControlMock_, KeyCtrlGetFscryptVersion(_)).WillOnce(Return(FSCRYPT_V2));
EXPECT_CALL(*fscryptControlMock_, KeyCtrlHasFscryptSyspara()).WillOnce(Return(true));
EXPECT_CALL(*baseKeyMock_, InitKey(_)).WillOnce(Return(true));
#ifdef USER_CRYPTO_MIGRATE_KEY
EXPECT_CALL(*baseKeyMock_, StoreKey(_, _)).WillOnce(Return(false));
#else
EXPECT_CALL(*baseKeyMock_, StoreKey(_)).WillOnce(Return(false));
#endif
EXPECT_CALL(*baseKeyMock_, ClearKey(_)).WillOnce(Return(true));
ret = KeyManager::GetInstance()->InitGlobalUserKeys();
EXPECT_NE(ret, 0);
GTEST_LOG_(INFO) << "KeyManager_InitGlobalUserKeys_0100 end";
}
/**
* @tc.name: KeyManager_GenerateUserKeys_001
* @tc.desc: Verify the KeyManager GenerateUserKeys function.

View File

@ -20,6 +20,8 @@
#include <mntent.h>
#include <unordered_map>
#include "directory_ex.h"
#include "crypto/app_clone_key_manager.h"
#include "ipc/istorage_daemon.h"
#include "ipc/storage_daemon.h"
@ -311,8 +313,17 @@ HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_MountDfsDocs_001,
std::string relativePath = "account";
std::string networkId = "testnetworkid";
std::string deviceId = "testdevid";
std::string path = "/mnt/data/" + std::to_string(userId) + "/hmdfs/";
OHOS::ForceRemoveDirectory(path);
auto ret = storageDaemon_->MountDfsDocs(userId, relativePath, networkId, deviceId);
EXPECT_EQ(ret, E_PREPARE_DIR);
OHOS::ForceCreateDirectory(path);
ret = storageDaemon_->MountDfsDocs(userId, relativePath, networkId, deviceId);
EXPECT_EQ(ret, E_MOUNT);
OHOS::ForceRemoveDirectory(path);
GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_MountDfsDocs_001 end";
}

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");