diff --git a/services/storage_daemon/BUILD.gn b/services/storage_daemon/BUILD.gn index 87cc2159c255ca701a9765a48effb71d682d79e0..2efc6de094dddc6c36980414c8e25165090fd0b1 100644 --- a/services/storage_daemon/BUILD.gn +++ b/services/storage_daemon/BUILD.gn @@ -312,6 +312,7 @@ group("storage_daemon_unit_test") { testonly = true deps = [ "client/test:storage_daemon_client_test", + "crypto/test/anco_test:anco_crypto_test", "file_sharing/test:file_sharing_test", "ipc/test:storage_daemon_ipc_test", "quota/test:storage_daemon_quota_test", diff --git a/services/storage_daemon/crypto/test/anco_test/BUILD.gn b/services/storage_daemon/crypto/test/anco_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8c5817a3b0cacafdd715636e6706e49ce2936777 --- /dev/null +++ b/services/storage_daemon/crypto/test/anco_test/BUILD.gn @@ -0,0 +1,49 @@ +# 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("AncoKeyManagerTest") { + module_out_path = "storage_service/storage_daemon" + + defines = [ + "STORAGE_LOG_TAG = \"StorageDaemon\"", + "LOG_DOMAIN = 0xD004301", + ] + + include_dirs = [ + "${storage_daemon_path}/include", + "${storage_daemon_path}/include/crypto", + "${storage_service_common_path}/include", + ] + + sources = [ "anco_key_manager_test.cpp" ] + + deps = [ "//third_party/googletest:gtest_main" ] + + deps += [ + "${storage_daemon_path}/crypto:libsdcrypto", + "${storage_daemon_path}/libfscrypt:libfscryptutils", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "huks:libhukssdk", + ] +} + +group("anco_crypto_test") { + testonly = true + deps = [ ":AncoKeyManagerTest" ] +} diff --git a/services/storage_daemon/crypto/test/anco_test/anco_key_manager_test.cpp b/services/storage_daemon/crypto/test/anco_test/anco_key_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e277a641dc215f80434171325c3998b434e3de86 --- /dev/null +++ b/services/storage_daemon/crypto/test/anco_test/anco_key_manager_test.cpp @@ -0,0 +1,93 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include + +#include "anco_key_manager.h" +#include "storage_service_errno.h" + +namespace OHOS { +namespace StorageDaemon { +using namespace testing::ext; +using namespace OHOS::StorageDaemon; + +class AncoKeyManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + + +void AncoKeyManagerTest::SetUpTestCase(void) +{ + // input testsuit setup step,setup invoked before all testcases +} + +void AncoKeyManagerTest::TearDownTestCase(void) +{ + // input testsuit teardown step,teardown invoked after all testcases +} + +void AncoKeyManagerTest::SetUp(void) +{ + // input testcase setup step,setup invoked before each testcases +} + +void AncoKeyManagerTest::TearDown(void) +{ + // input testcase teardown step,teardown invoked after each testcases +} + +/** + * @tc.name: SetAnDirectoryElpolicy_0100 + * @tc.desc: Verify the SetAnDirectoryElpolicy_0100 function. + * @tc.type: FUNC + * @tc.require: SR20231213615940 + */ +HWTEST_F(AncoKeyManagerTest, Set_Anco_Directory_El_Policy_utils_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AnKeyManagerTest_SetAnDirectoryElpolicy_0100 start"; + const std::string path = ""; + const std::string policyType = ""; + const uint32_t user = 0; + EXPECT_EQ(AncoKeyManager::GetInstance()->SetAncoDirectoryElPolicy(path, policyType, user), + OHOS::E_OPEN_JSON_FILE_ERROR); + GTEST_LOG_(INFO) << "AnKeyManagerTest_SetAnDirectoryElpolicy_0100 end"; +} + +/** + * @tc.name: SetAnDirectoryElpolicy_0200 + * @tc.desc: Verify the SetAnDirectoryElpolicy_0200 function. + * @tc.type: FUNC + * @tc.require: SR20231213615940 + */ +HWTEST_F(AncoKeyManagerTest, Set_Anco_Directory_El_Policy_utils_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AnKeyManagerTest_SetAnDirectoryElpolicy_0200 start"; + const std::string path = "/data/virt_serivce/rgm_manager/rgm_homs/config/storage/test.json"; + const std::string policyType = "encryption=Require_Sys_EL1"; + const uint32_t user = 0; + auto result = AncoKeyManager::GetInstance()->SetAncoDirectoryElPolicy(path, policyType, user); + EXPECT_NE(result, OHOS::E_OK); + GTEST_LOG_(INFO) << "AnKeyManagerTest_SetAnDirectoryElpolicy_0100 end"; +} +} // namespace StorageDaemon +} // namespace OHOS \ No newline at end of file