diff --git a/interfaces/innerkits/appverify/test/BUILD.gn b/interfaces/innerkits/appverify/test/BUILD.gn index 3ea425f74715f57539815b5acfc899d3b17ebc06..94f5880007c336f19178b682e2b3fe5b010fc8f9 100644 --- a/interfaces/innerkits/appverify/test/BUILD.gn +++ b/interfaces/innerkits/appverify/test/BUILD.gn @@ -77,7 +77,42 @@ ohos_unittest("verify_test") { "//base/security/appverify/test/resource/appverify/ohos_test.xml" } +config("app_verify_config") { + include_dirs = + [ "//base/security/appverify/interfaces/innerkits/appverify/include" ] +} + +ohos_unittest("app_verify_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + use_exceptions = true + module_out_path = module_output_path + + sources = [ "unittest/src/app_verify_test.cpp" ] + configs = [ ":app_verify_config" ] + + ldflags = [ "-Wl,--export-dynamic" ] + + external_deps = [ + "appverify:libhapverify", + "cJSON:cjson", + "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_core", + "openssl:libcrypto_shared", + "samgr:samgr_proxy", + ] +} + group("unittest") { testonly = true - deps = [ ":verify_test" ] + deps = [ + ":app_verify_test", + ":verify_test", + ] } diff --git a/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h b/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h index 0b496aa1a0f1b0424b61f230989ef6fa42e6b5f2..9d5c745df1c7a8a8121b2917823698e35ea6625e 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h @@ -18,4 +18,7 @@ #include int32_t ReadFileFullyFromOffsetTest001(void); +int32_t InitWithFd001(void); +int32_t InitWithFd002(void); +int32_t InitWithFd003(void); #endif // RANDOM_ACCESS_FILE_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/src/app_verify_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/app_verify_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a358725d6683d0d360551a3c286d33dab0cb6e2b --- /dev/null +++ b/interfaces/innerkits/appverify/test/unittest/src/app_verify_test.cpp @@ -0,0 +1,65 @@ +/* + * 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. + */ +#define private public + +#include +#include +#include +#include +#include + +#include "common/hap_file_data_source.h" +#include "common/random_access_file.h" +#include "init/device_type_manager.h" + +using namespace testing::ext; +using namespace OHOS::Security::Verify; + +namespace { +class MockDeviceTypeManager : public DeviceTypeManager { +public: + MOCK_METHOD0(GetDeviceType, bool()); +}; + +class AppVerifyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AppVerifyTest::SetUpTestCase() {} + +void AppVerifyTest::TearDownTestCase() {} + +void AppVerifyTest::SetUp() {} + +void AppVerifyTest::TearDown() {} + +/** + * @tc.name: Test ReadFileFromOffsetAndDigestUpdateV2 function + * @tc.desc: The static function will return each reading result; + * @tc.type: FUNC + */ +HWTEST_F(AppVerifyTest, ReadFileFromOffsetAndDigestUpdateV2001, TestSize.Level1) +{ + DeviceTypeManager& deviceTypeManager = DeviceTypeManager::GetInstance(); + bool originDeviceType = deviceTypeManager.deviceType; + deviceTypeManager.deviceType = true; + EXPECT_FALSE(deviceTypeManager.GetDeviceTypeInfo()); + deviceTypeManager.deviceType = originDeviceType; +} +} // namespace \ No newline at end of file diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp index 364efa7f65b98af495b7fa2cb393b5f45123db65..0e1a27689d56ad35664d1e1e30394dd6c8136299 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp @@ -15,8 +15,10 @@ #include "hap_verify_test.h" +#include #include #include +#include #include @@ -266,7 +268,7 @@ HWTEST_F(HapVerifyTest, HapVerify003, TestSize.Level0) * @tc.desc: The static function will return verify result of signed file; * @tc.type: FUNC */ -HWTEST_F(HapVerifyTest, HapVerify004, TestSize.Level0) +HWTEST_F(HapVerifyTest, HapVerify004, TestSize.Level1) { std::string filePath = "temp_test_file.hap"; int32_t filefd = -1; @@ -274,4 +276,32 @@ HWTEST_F(HapVerifyTest, HapVerify004, TestSize.Level0) std::string appIdentifier; ASSERT_TRUE(ParseBundleNameAndAppIdentifier(filefd, bundleName, appIdentifier) == OPEN_FILE_ERROR); } + +/** + * @tc.name: HapVerifyTest.HapVerify005 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(HapVerifyTest, HapVerify005, TestSize.Level1) +{ + std::string filePath = "temp_test_file.hap"; + std::string bundleName; + std::string appIdentifier; + ASSERT_FALSE(ParseBundleNameAndAppIdentifier(1, bundleName, appIdentifier) == VERIFY_SOURCE_INIT_FAIL); +} + +/** + * @tc.name: HapVerifyTest.HapVerify005 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(HapVerifyTest, HapVerify006, TestSize.Level1) +{ + std::string filePath = "/data/update/ticket/verify_test.p7b"; + int fd = open(filePath.c_str(), O_RDONLY); + std::string bundleName; + std::string appIdentifier; + EXPECT_FALSE(ParseBundleNameAndAppIdentifier(fd, bundleName, appIdentifier) == VERIFY_SOURCE_INIT_FAIL); + close(fd); +} } diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_v2_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_v2_test.cpp index 375fa0f261ed3783f35015b34b7042de0e5b476c..9641ceea01e15050d69460a132b129ee473fd632 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_v2_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_v2_test.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#define private public + #include "hap_verify_v2_test.h" #include diff --git a/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp index 4d795386e7a0e4fbe43e518f728a619ee51481d6..d62afc0958c415a0517f5e9a4d9ff95912f1d6f5 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp @@ -13,9 +13,11 @@ * limitations under the License. */ -#include "random_access_file_test.h" +#define private public +#include #include +#include #include @@ -119,4 +121,28 @@ HWTEST_F(RandomAccessFileTest, ReadFileFullyFromOffsetTest001, TestSize.Level1) ASSERT_TRUE(ret == READ_OFFSET_OUT_OF_RANGE); buffer.reset(nullptr); } + +/** + * @tc.name: Test InitWithFd function + * @tc.desc: The static function will return each reading result; + * @tc.type: FUNC + */ +HWTEST_F(RandomAccessFileTest, InitWithFd001, TestSize.Level1) +{ + RandomAccessFile randomAccessFile; + const int32_t fileFd = -1; + EXPECT_FALSE(randomAccessFile.InitWithFd(fileFd)); +} + +/** + * @tc.name: Test InitWithFd function + * @tc.desc: The static function will return each reading result; + * @tc.type: FUNC + */ +HWTEST_F(RandomAccessFileTest, InitWithFd002, TestSize.Level1) +{ + RandomAccessFile randomAccessFile; + const int32_t fileFd = 0; + EXPECT_FALSE(randomAccessFile.InitWithFd(fileFd)); +} }