diff --git a/interfaces/innerkits/appverify/test/BUILD.gn b/interfaces/innerkits/appverify/test/BUILD.gn index e37962d8ce264cdf12a31d966c276bde29ce7921..5c714eee0e44ba919acb7b2e05bb47731f131afb 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 0000000000000000000000000000000000000000..23580ccc2e48f91b15d70535860c12ddd25ba2a0 --- /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 0000000000000000000000000000000000000000..1c314d1cf69fc1ea7a062348216a1240f89b0965 --- /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 194ae14cef36daefb1de8033afc816460c67690a..2ae1f6915128244e26b4e16ccce0e752144d2440 100644 --- a/test/resource/appverify/ohos_test.xml +++ b/test/resource/appverify/ohos_test.xml @@ -1,5 +1,5 @@ -