From 7121108d19697aeee3774de58638b882521840f8 Mon Sep 17 00:00:00 2001 From: Lotol Date: Wed, 14 Jun 2023 12:11:23 +0000 Subject: [PATCH] =?UTF-8?q?TicketVerifyTest=20tdd=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lotol Change-Id: Ieb56cc7e5d2d6c0e7be9384a98925a0c075d991d --- interfaces/innerkits/appverify/test/BUILD.gn | 3 +- .../unittest/include/ticket_verify_test.h | 22 ++++ .../test/unittest/src/ticket_verify_test.cpp | 111 ++++++++++++++++++ test/resource/appverify/ohos_test.xml | 4 +- test/resource/appverify/verify_err.p7b | 0 test/resource/appverify/verify_test.p7b | Bin 0 -> 3466 bytes 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h create mode 100644 interfaces/innerkits/appverify/test/unittest/src/ticket_verify_test.cpp create mode 100644 test/resource/appverify/verify_err.p7b create mode 100644 test/resource/appverify/verify_test.p7b diff --git a/interfaces/innerkits/appverify/test/BUILD.gn b/interfaces/innerkits/appverify/test/BUILD.gn index e37962d..5c714ee 100644 --- a/interfaces/innerkits/appverify/test/BUILD.gn +++ b/interfaces/innerkits/appverify/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021 - 2023 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 @@ -41,6 +41,7 @@ ohos_unittest("verify_test") { "unittest/src/hap_verify_v2_test.cpp", "unittest/src/provision_verify_test.cpp", "unittest/src/random_access_file_test.cpp", + "unittest/src/ticket_verify_test.cpp", "unittest/src/trusted_root_ca_test.cpp", "unittest/src/trusted_ticket_test.cpp", ] diff --git a/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h b/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h new file mode 100644 index 0000000..23580cc --- /dev/null +++ b/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 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. + */ + +#ifndef HAP_BYTE_BUFFER_TEST_H +#define HAP_BYTE_BUFFER_TEST_H +int CheckTicketSource001(void); +int CheckTicketSource002(void); +int CheckTicketSource003(void); +int CheckTicketSource004(void); +#endif // HAP_BYTE_BUFFER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/src/ticket_verify_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/ticket_verify_test.cpp new file mode 100644 index 0000000..1c314d1 --- /dev/null +++ b/interfaces/innerkits/appverify/test/unittest/src/ticket_verify_test.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2023 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 "hap_byte_buffer_test.h" + +#include + +#include "ticket/ticket_verify.h" +#include "securec.h" + +#include "hap_signing_block_utils_test.h" +#include "test_const.h" + +using namespace testing::ext; +using namespace OHOS::Security::Verify; +namespace { +const std::string BUNDLE_NAME = "com.ohos.test"; +const std::string OVER_MAX_PATH_SIZE(4096, 'x'); +const std::string VERIFY_ERR = "verify_err"; +const std::string VERIFY_TEST = "verify_test"; +class TicketVerifyTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void TicketVerifyTest::SetUpTestCase(void) +{ +} + +void TicketVerifyTest::TearDownTestCase(void) +{ +} + +void TicketVerifyTest::SetUp() +{ +} + +void TicketVerifyTest::TearDown() +{ +} + +/** + * @tc.name: Test TicketVerify Constructor and overload function. + * @tc.desc: The static function will return an object of TicketVerify; + * @tc.type: FUNC + */ +HWTEST_F (TicketVerifyTest, CheckTicketSource001, TestSize.Level1) +{ + ProvisionInfo profileInfo; + profileInfo.bundleInfo.bundleName = OVER_MAX_PATH_SIZE; + auto res = CheckTicketSource(profileInfo); + ASSERT_EQ(res, false); +} + +/** + * @tc.name: Test TicketVerify Constructor and overload function. + * @tc.desc: The static function will return an object of TicketVerify; + * @tc.type: FUNC + */ +HWTEST_F (TicketVerifyTest, CheckTicketSource002, TestSize.Level1) +{ + ProvisionInfo profileInfo; + profileInfo.bundleInfo.bundleName = BUNDLE_NAME; + auto res = CheckTicketSource(profileInfo); + ASSERT_EQ(res, false); +} + +/** + * @tc.name: Test TicketVerify Constructor and overload function. + * @tc.desc: The static function will return an object of TicketVerify; + * @tc.type: FUNC + */ +HWTEST_F (TicketVerifyTest, CheckTicketSource003, TestSize.Level1) +{ + ProvisionInfo profileInfo; + profileInfo.bundleInfo.bundleName = VERIFY_TEST; + auto res = CheckTicketSource(profileInfo); + ASSERT_EQ(res, false); +} + +/** + * @tc.name: Test TicketVerify Constructor and overload function. + * @tc.desc: The static function will return an object of TicketVerify; + * @tc.type: FUNC + */ +HWTEST_F (TicketVerifyTest, CheckTicketSource004, TestSize.Level1) +{ + ProvisionInfo profileInfo; + profileInfo.bundleInfo.bundleName = VERIFY_ERR; + auto res = CheckTicketSource(profileInfo); + ASSERT_EQ(res, false); +} +} diff --git a/test/resource/appverify/ohos_test.xml b/test/resource/appverify/ohos_test.xml index 194ae14..2ae1f69 100644 --- a/test/resource/appverify/ohos_test.xml +++ b/test/resource/appverify/ohos_test.xml @@ -1,5 +1,5 @@ -