1fb299fa2Sopenharmony_ci/*
2fb299fa2Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at
6fb299fa2Sopenharmony_ci *
7fb299fa2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb299fa2Sopenharmony_ci *
9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and
13fb299fa2Sopenharmony_ci * limitations under the License.
14fb299fa2Sopenharmony_ci */
15fb299fa2Sopenharmony_ci
16fb299fa2Sopenharmony_ci#include <cstring>
17fb299fa2Sopenharmony_ci#include <fcntl.h>
18fb299fa2Sopenharmony_ci#include <gtest/gtest.h>
19fb299fa2Sopenharmony_ci#include <iostream>
20fb299fa2Sopenharmony_ci#include <unistd.h>
21fb299fa2Sopenharmony_ci#include "log.h"
22fb299fa2Sopenharmony_ci#include "pkg_algorithm.h"
23fb299fa2Sopenharmony_ci#include "pkg_manager.h"
24fb299fa2Sopenharmony_ci#include "pkg_manager_impl.h"
25fb299fa2Sopenharmony_ci#include "pkg_test.h"
26fb299fa2Sopenharmony_ci#include "pkg_utils.h"
27fb299fa2Sopenharmony_ci
28fb299fa2Sopenharmony_ci#include "package.h"
29fb299fa2Sopenharmony_ci#include "cert_verify.h"
30fb299fa2Sopenharmony_ci#include "hash_data_verifier.h"
31fb299fa2Sopenharmony_ci#include "openssl_util.h"
32fb299fa2Sopenharmony_ci#include "pkg_verify_util.h"
33fb299fa2Sopenharmony_ci#include "zip_pkg_parse.h"
34fb299fa2Sopenharmony_ci#include "pkcs7_signed_data.h"
35fb299fa2Sopenharmony_ci
36fb299fa2Sopenharmony_ciusing namespace std;
37fb299fa2Sopenharmony_ciusing namespace Hpackage;
38fb299fa2Sopenharmony_ciusing namespace Updater;
39fb299fa2Sopenharmony_ciusing namespace testing::ext;
40fb299fa2Sopenharmony_ci
41fb299fa2Sopenharmony_cinamespace UpdaterUt {
42fb299fa2Sopenharmony_ciclass PackageVerifyTest : public PkgTest {
43fb299fa2Sopenharmony_cipublic:
44fb299fa2Sopenharmony_ci    PackageVerifyTest() {}
45fb299fa2Sopenharmony_ci    ~PackageVerifyTest() override {}
46fb299fa2Sopenharmony_cipublic:
47fb299fa2Sopenharmony_ci    int TestGetFileSize(const std::string &testfileName)
48fb299fa2Sopenharmony_ci    {
49fb299fa2Sopenharmony_ci        int32_t ret = GetFileSize(testfileName);
50fb299fa2Sopenharmony_ci        return ret;
51fb299fa2Sopenharmony_ci    }
52fb299fa2Sopenharmony_ci
53fb299fa2Sopenharmony_ci    int TestExtraPackageFile()
54fb299fa2Sopenharmony_ci    {
55fb299fa2Sopenharmony_ci        int32_t ret = ExtraPackageFile(nullptr, nullptr, nullptr, nullptr);
56fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_PARAM);
57fb299fa2Sopenharmony_ci
58fb299fa2Sopenharmony_ci        std::string packagePath = "invalid_path";
59fb299fa2Sopenharmony_ci        std::string keyPath = "invalid_key";
60fb299fa2Sopenharmony_ci        std::string file = "invalid_file";
61fb299fa2Sopenharmony_ci        std::string outPath = "invalid_path";
62fb299fa2Sopenharmony_ci        ret = ExtraPackageFile(packagePath.c_str(), keyPath.c_str(), file.c_str(), outPath.c_str());
63fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_FILE);
64fb299fa2Sopenharmony_ci
65fb299fa2Sopenharmony_ci        packagePath = testPackagePath + "test_package.zip";
66fb299fa2Sopenharmony_ci        keyPath = "/data/updater/src/signing_cert.crt";
67fb299fa2Sopenharmony_ci        file = "updater.bin";
68fb299fa2Sopenharmony_ci        ret = ExtraPackageFile(packagePath.c_str(), keyPath.c_str(), file.c_str(), testPackagePath.c_str());
69fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_SUCCESS);
70fb299fa2Sopenharmony_ci        return 0;
71fb299fa2Sopenharmony_ci    }
72fb299fa2Sopenharmony_ci
73fb299fa2Sopenharmony_ci    int TestExtraPackageDir()
74fb299fa2Sopenharmony_ci    {
75fb299fa2Sopenharmony_ci        int32_t ret = ExtraPackageDir(nullptr, nullptr, nullptr, nullptr);
76fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_PARAM);
77fb299fa2Sopenharmony_ci
78fb299fa2Sopenharmony_ci        std::string packagePath = "invalid_path";
79fb299fa2Sopenharmony_ci        std::string keyPath = "invalid_key";
80fb299fa2Sopenharmony_ci        std::string outPath = "invalid_path";
81fb299fa2Sopenharmony_ci        ret = ExtraPackageDir(packagePath.c_str(), keyPath.c_str(), nullptr, outPath.c_str());
82fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_FILE);
83fb299fa2Sopenharmony_ci
84fb299fa2Sopenharmony_ci        packagePath = testPackagePath + "test_package.zip";
85fb299fa2Sopenharmony_ci        keyPath = "/data/updater/src/signing_cert.crt";
86fb299fa2Sopenharmony_ci        ret = ExtraPackageDir(packagePath.c_str(), keyPath.c_str(), nullptr, testPackagePath.c_str());
87fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_SUCCESS);
88fb299fa2Sopenharmony_ci        return 0;
89fb299fa2Sopenharmony_ci    }
90fb299fa2Sopenharmony_ci
91fb299fa2Sopenharmony_ci    int TestCertVerifyFailed()
92fb299fa2Sopenharmony_ci    {
93fb299fa2Sopenharmony_ci        BIO *certbio = BIO_new_file(GetTestPrivateKeyName(0).c_str(), "r");
94fb299fa2Sopenharmony_ci        X509 *rcert = PEM_read_bio_X509(certbio, nullptr, nullptr, nullptr);
95fb299fa2Sopenharmony_ci        if (certbio != nullptr) {
96fb299fa2Sopenharmony_ci            BIO_free(certbio);
97fb299fa2Sopenharmony_ci        }
98fb299fa2Sopenharmony_ci        SingleCertHelper singleCert;
99fb299fa2Sopenharmony_ci        int32_t ret = singleCert.CertChainCheck(nullptr, nullptr);
100fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
101fb299fa2Sopenharmony_ci        ret = singleCert.CertChainCheck(nullptr, rcert);
102fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
103fb299fa2Sopenharmony_ci
104fb299fa2Sopenharmony_ci        ret = CertVerify::GetInstance().CheckCertChain(nullptr, nullptr);
105fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
106fb299fa2Sopenharmony_ci
107fb299fa2Sopenharmony_ci        bool result = VerifyX509CertByIssuerCert(nullptr, nullptr);
108fb299fa2Sopenharmony_ci        EXPECT_EQ(result, false);
109fb299fa2Sopenharmony_ci        result = VerifyX509CertByIssuerCert(rcert, rcert);
110fb299fa2Sopenharmony_ci        EXPECT_EQ(result, false);
111fb299fa2Sopenharmony_ci        return 0;
112fb299fa2Sopenharmony_ci    }
113fb299fa2Sopenharmony_ci
114fb299fa2Sopenharmony_ci    int TestOpensslUtilFailed()
115fb299fa2Sopenharmony_ci    {
116fb299fa2Sopenharmony_ci        std::vector<uint8_t> asn1Data;
117fb299fa2Sopenharmony_ci        int32_t ret = GetASN1OctetStringData(nullptr, asn1Data);
118fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
119fb299fa2Sopenharmony_ci
120fb299fa2Sopenharmony_ci        int32_t algoNid {};
121fb299fa2Sopenharmony_ci        ret = GetX509AlgorithmNid(nullptr, algoNid);
122fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
123fb299fa2Sopenharmony_ci
124fb299fa2Sopenharmony_ci        X509 *result = GetX509CertFromPemString(" ");
125fb299fa2Sopenharmony_ci        EXPECT_EQ(result, nullptr);
126fb299fa2Sopenharmony_ci        result = GetX509CertFromPemFile("invalid_file");
127fb299fa2Sopenharmony_ci        EXPECT_EQ(result, nullptr);
128fb299fa2Sopenharmony_ci
129fb299fa2Sopenharmony_ci        BIO *certbio = BIO_new_file(GetTestPrivateKeyName(0).c_str(), "r");
130fb299fa2Sopenharmony_ci        X509 *cert = PEM_read_bio_X509(certbio, nullptr, nullptr, nullptr);
131fb299fa2Sopenharmony_ci        if (certbio != nullptr) {
132fb299fa2Sopenharmony_ci            BIO_free(certbio);
133fb299fa2Sopenharmony_ci        }
134fb299fa2Sopenharmony_ci        bool boolResult = VerifyX509CertByIssuerCert(nullptr, nullptr);
135fb299fa2Sopenharmony_ci        EXPECT_EQ(boolResult, false);
136fb299fa2Sopenharmony_ci        boolResult = VerifyX509CertByIssuerCert(cert, cert);
137fb299fa2Sopenharmony_ci        EXPECT_EQ(boolResult, false);
138fb299fa2Sopenharmony_ci
139fb299fa2Sopenharmony_ci        ret = VerifyDigestByPubKey(nullptr, 0, asn1Data, asn1Data);
140fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
141fb299fa2Sopenharmony_ci        ret = CalcSha256Digest(nullptr, 0, asn1Data);
142fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
143fb299fa2Sopenharmony_ci
144fb299fa2Sopenharmony_ci        std::string stringResult = GetStringFromX509Name(nullptr);
145fb299fa2Sopenharmony_ci        EXPECT_EQ(stringResult, "");
146fb299fa2Sopenharmony_ci        stringResult = GetX509CertSubjectName(nullptr);
147fb299fa2Sopenharmony_ci        EXPECT_EQ(stringResult, "");
148fb299fa2Sopenharmony_ci        stringResult = GetX509CertSubjectName(cert);
149fb299fa2Sopenharmony_ci        EXPECT_EQ(stringResult, "");
150fb299fa2Sopenharmony_ci        stringResult = GetX509CertIssuerName(nullptr);
151fb299fa2Sopenharmony_ci        EXPECT_EQ(stringResult, "");
152fb299fa2Sopenharmony_ci        stringResult = GetX509CertIssuerName(cert);
153fb299fa2Sopenharmony_ci        EXPECT_EQ(stringResult, "");
154fb299fa2Sopenharmony_ci        return 0;
155fb299fa2Sopenharmony_ci    }
156fb299fa2Sopenharmony_ci
157fb299fa2Sopenharmony_ci    int TestPkcs7SignedDataFailed()
158fb299fa2Sopenharmony_ci    {
159fb299fa2Sopenharmony_ci        Pkcs7SignedData signedData;
160fb299fa2Sopenharmony_ci        uint8_t srcData[] = "A";
161fb299fa2Sopenharmony_ci        std::vector<uint8_t> hash;
162fb299fa2Sopenharmony_ci        std::vector<std::vector<uint8_t>> sigs;
163fb299fa2Sopenharmony_ci
164fb299fa2Sopenharmony_ci        int32_t ret = signedData.Verify();
165fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
166fb299fa2Sopenharmony_ci        ret = signedData.GetHashFromSignBlock(nullptr, 0, hash);
167fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
168fb299fa2Sopenharmony_ci        ret = signedData.GetHashFromSignBlock(srcData, 0, hash);
169fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
170fb299fa2Sopenharmony_ci        ret = signedData.GetHashFromSignBlock(srcData, 1, hash);
171fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, -1);
172fb299fa2Sopenharmony_ci        ret = signedData.ReadSig(nullptr, 0, sigs);
173fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKCS7_INVALID_PARAM_ERR);
174fb299fa2Sopenharmony_ci        ret = signedData.ReadSig(srcData, 0, sigs);
175fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKCS7_INVALID_PARAM_ERR);
176fb299fa2Sopenharmony_ci        ret = signedData.ReadSig(srcData, 1, sigs);
177fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKCS7_INIT_ERR);
178fb299fa2Sopenharmony_ci        return 0;
179fb299fa2Sopenharmony_ci    }
180fb299fa2Sopenharmony_ci
181fb299fa2Sopenharmony_ci    int TestPkgVerifyFailed()
182fb299fa2Sopenharmony_ci    {
183fb299fa2Sopenharmony_ci        PkgVerifyUtil pkgVerify;
184fb299fa2Sopenharmony_ci        std::vector<uint8_t> data;
185fb299fa2Sopenharmony_ci        size_t testData = 0;
186fb299fa2Sopenharmony_ci        uint16_t commentTotalLenAll = 0;
187fb299fa2Sopenharmony_ci        int32_t ret = pkgVerify.VerifyPackageSign(nullptr);
188fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_PARAM);
189fb299fa2Sopenharmony_ci        ret = pkgVerify.GetSignature(nullptr, testData, data, commentTotalLenAll);
190fb299fa2Sopenharmony_ci        EXPECT_NE(ret, PKG_SUCCESS);
191fb299fa2Sopenharmony_ci        ret = pkgVerify.HashCheck(nullptr, testData, data);
192fb299fa2Sopenharmony_ci        EXPECT_EQ(ret, PKG_INVALID_PARAM);
193fb299fa2Sopenharmony_ci        ret = pkgVerify.ParsePackage(nullptr, testData, testData, commentTotalLenAll);
194fb299fa2Sopenharmony_ci        EXPECT_NE(ret, PKG_SUCCESS);
195fb299fa2Sopenharmony_ci        ret = pkgVerify.Pkcs7verify(data, data);
196fb299fa2Sopenharmony_ci        EXPECT_NE(ret, PKG_SUCCESS);
197fb299fa2Sopenharmony_ci        return 0;
198fb299fa2Sopenharmony_ci    }
199fb299fa2Sopenharmony_ci
200fb299fa2Sopenharmony_ci    int TestHashDataVerifierFailed01()
201fb299fa2Sopenharmony_ci    {
202fb299fa2Sopenharmony_ci        // verifier with null pkg manager
203fb299fa2Sopenharmony_ci        HashDataVerifier verifier {nullptr};
204fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.LoadHashDataAndPkcs7(""));
205fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.VerifyHashData("build_tools/", "updater_binary", nullptr));
206fb299fa2Sopenharmony_ci        FileStream filestream(nullptr, "", nullptr, PkgStream::PkgStreamType_Read);
207fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.VerifyHashData("build_tools/", "updater_binary", &filestream));
208fb299fa2Sopenharmony_ci        return 0;
209fb299fa2Sopenharmony_ci    }
210fb299fa2Sopenharmony_ci
211fb299fa2Sopenharmony_ci    int TestHashDataVerifierFailed02()
212fb299fa2Sopenharmony_ci    {
213fb299fa2Sopenharmony_ci        // no hash signed data in pkg
214fb299fa2Sopenharmony_ci        std::string invalidPkgPath = "updater_full_without_hsd.zip";
215fb299fa2Sopenharmony_ci        HashDataVerifier verifier {pkgManager_};
216fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.LoadHashDataAndPkcs7(testPackagePath + invalidPkgPath));
217fb299fa2Sopenharmony_ci
218fb299fa2Sopenharmony_ci        // invalid package path
219fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.LoadHashDataAndPkcs7("invalid package path"));
220fb299fa2Sopenharmony_ci        return 0;
221fb299fa2Sopenharmony_ci    }
222fb299fa2Sopenharmony_ci
223fb299fa2Sopenharmony_ci    int TestHashDataVerifierFailed03()
224fb299fa2Sopenharmony_ci    {
225fb299fa2Sopenharmony_ci        // invalid hash signed data format
226fb299fa2Sopenharmony_ci        std::string invalidPkgPath = "updater_full_with_invalid_hsd.zip";
227fb299fa2Sopenharmony_ci        std::vector<std::string> fileIds {};
228fb299fa2Sopenharmony_ci        EXPECT_EQ(PKG_SUCCESS, pkgManager_->LoadPackage(testPackagePath + invalidPkgPath,
229fb299fa2Sopenharmony_ci            Utils::GetCertName(), fileIds));
230fb299fa2Sopenharmony_ci        HashDataVerifier verifier {pkgManager_};
231fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.LoadHashDataAndPkcs7(testPackagePath + invalidPkgPath));
232fb299fa2Sopenharmony_ci        return 0;
233fb299fa2Sopenharmony_ci    }
234fb299fa2Sopenharmony_ci
235fb299fa2Sopenharmony_ci    int TestHashDataVerifierFailed04()
236fb299fa2Sopenharmony_ci    {
237fb299fa2Sopenharmony_ci        // invalid pkg footer
238fb299fa2Sopenharmony_ci        std::string invalidPkgPath = "updater_full_with_invalid_footer.zip";
239fb299fa2Sopenharmony_ci        HashDataVerifier verifier {pkgManager_};
240fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.LoadHashDataAndPkcs7(testPackagePath + invalidPkgPath));
241fb299fa2Sopenharmony_ci        return 0;
242fb299fa2Sopenharmony_ci    }
243fb299fa2Sopenharmony_ci
244fb299fa2Sopenharmony_ci    int VerifyFileByVerifier(const HashDataVerifier &verifier, const std::string &fileName)
245fb299fa2Sopenharmony_ci    {
246fb299fa2Sopenharmony_ci        const FileInfo *info = pkgManager_->GetFileInfo(fileName);
247fb299fa2Sopenharmony_ci        EXPECT_NE(info, nullptr) << "info is null " << fileName;
248fb299fa2Sopenharmony_ci        if (info == nullptr) {
249fb299fa2Sopenharmony_ci            return -1;
250fb299fa2Sopenharmony_ci        }
251fb299fa2Sopenharmony_ci        PkgManager::StreamPtr outStream = nullptr;
252fb299fa2Sopenharmony_ci        PkgBuffer buffer{info->unpackedSize};
253fb299fa2Sopenharmony_ci        EXPECT_EQ(PKG_SUCCESS, pkgManager_->CreatePkgStream(outStream, fileName, buffer)) << fileName;
254fb299fa2Sopenharmony_ci        EXPECT_EQ(PKG_SUCCESS, pkgManager_->ExtractFile(fileName, outStream)) << fileName;
255fb299fa2Sopenharmony_ci        EXPECT_TRUE(verifier.VerifyHashData("build_tools/", fileName, outStream));
256fb299fa2Sopenharmony_ci        EXPECT_FALSE(verifier.VerifyHashData("build_tools/", "invalid", outStream));
257fb299fa2Sopenharmony_ci        pkgManager_->ClosePkgStream(outStream);
258fb299fa2Sopenharmony_ci        return 0;
259fb299fa2Sopenharmony_ci    }
260fb299fa2Sopenharmony_ci
261fb299fa2Sopenharmony_ci    int TestHashDataVerifierSuccess()
262fb299fa2Sopenharmony_ci    {
263fb299fa2Sopenharmony_ci        std::vector<std::string> fileIds {};
264fb299fa2Sopenharmony_ci        EXPECT_EQ(PKG_SUCCESS, pkgManager_->LoadPackage(testPackagePath + "updater_full_with_hsd.zip",
265fb299fa2Sopenharmony_ci            Utils::GetCertName(), fileIds));
266fb299fa2Sopenharmony_ci        HashDataVerifier verifier {pkgManager_};
267fb299fa2Sopenharmony_ci        EXPECT_TRUE(verifier.LoadHashDataAndPkcs7(testPackagePath + testZipPackageName));
268fb299fa2Sopenharmony_ci
269fb299fa2Sopenharmony_ci        // secondary load directly return true
270fb299fa2Sopenharmony_ci        EXPECT_TRUE(verifier.LoadHashDataAndPkcs7(testPackagePath + testZipPackageName));
271fb299fa2Sopenharmony_ci        std::vector<std::string> fileList { "updater_binary", "loadScript.us", "Verse-script.us" };
272fb299fa2Sopenharmony_ci        for (const auto &fileName : fileList) {
273fb299fa2Sopenharmony_ci            EXPECT_EQ(VerifyFileByVerifier(verifier, fileName), 0);
274fb299fa2Sopenharmony_ci        }
275fb299fa2Sopenharmony_ci        return 0;
276fb299fa2Sopenharmony_ci    }
277fb299fa2Sopenharmony_ci};
278fb299fa2Sopenharmony_ci
279fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestPkgVerifyFailed, TestSize.Level1)
280fb299fa2Sopenharmony_ci{
281fb299fa2Sopenharmony_ci    PackageVerifyTest test;
282fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestPkgVerifyFailed());
283fb299fa2Sopenharmony_ci}
284fb299fa2Sopenharmony_ci
285fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestPkcs7SignedDataFailed, TestSize.Level1)
286fb299fa2Sopenharmony_ci{
287fb299fa2Sopenharmony_ci    PackageVerifyTest test;
288fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestPkcs7SignedDataFailed());
289fb299fa2Sopenharmony_ci}
290fb299fa2Sopenharmony_ci
291fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestOpensslUtilFailed, TestSize.Level1)
292fb299fa2Sopenharmony_ci{
293fb299fa2Sopenharmony_ci    PackageVerifyTest test;
294fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestOpensslUtilFailed());
295fb299fa2Sopenharmony_ci}
296fb299fa2Sopenharmony_ci
297fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestCertVerifyFailed, TestSize.Level1)
298fb299fa2Sopenharmony_ci{
299fb299fa2Sopenharmony_ci    PackageVerifyTest test;
300fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestCertVerifyFailed());
301fb299fa2Sopenharmony_ci}
302fb299fa2Sopenharmony_ci
303fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestExtraPackageDir, TestSize.Level1)
304fb299fa2Sopenharmony_ci{
305fb299fa2Sopenharmony_ci    PackageVerifyTest test;
306fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestExtraPackageDir());
307fb299fa2Sopenharmony_ci}
308fb299fa2Sopenharmony_ci
309fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestExtraPackageFile, TestSize.Level1)
310fb299fa2Sopenharmony_ci{
311fb299fa2Sopenharmony_ci    PackageVerifyTest test;
312fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestExtraPackageFile());
313fb299fa2Sopenharmony_ci}
314fb299fa2Sopenharmony_ci
315fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestGetFileSize, TestSize.Level1)
316fb299fa2Sopenharmony_ci{
317fb299fa2Sopenharmony_ci    PackageVerifyTest test;
318fb299fa2Sopenharmony_ci    std::string testFileName = "invalid_path";
319fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestGetFileSize(testFileName));
320fb299fa2Sopenharmony_ci    testFileName = testPackagePath + "test_package.zip";
321fb299fa2Sopenharmony_ci    EXPECT_EQ(1368949, test.TestGetFileSize(testFileName));
322fb299fa2Sopenharmony_ci}
323fb299fa2Sopenharmony_ci
324fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestHashDataVerifierFailed01, TestSize.Level1)
325fb299fa2Sopenharmony_ci{
326fb299fa2Sopenharmony_ci    PackageVerifyTest test;
327fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestHashDataVerifierFailed01());
328fb299fa2Sopenharmony_ci}
329fb299fa2Sopenharmony_ci
330fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestHashDataVerifierFailed02, TestSize.Level1)
331fb299fa2Sopenharmony_ci{
332fb299fa2Sopenharmony_ci    PackageVerifyTest test;
333fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestHashDataVerifierFailed02());
334fb299fa2Sopenharmony_ci}
335fb299fa2Sopenharmony_ci
336fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestHashDataVerifierFailed03, TestSize.Level1)
337fb299fa2Sopenharmony_ci{
338fb299fa2Sopenharmony_ci    PackageVerifyTest test;
339fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestHashDataVerifierFailed03());
340fb299fa2Sopenharmony_ci}
341fb299fa2Sopenharmony_ci
342fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestHashDataVerifierFailed04, TestSize.Level1)
343fb299fa2Sopenharmony_ci{
344fb299fa2Sopenharmony_ci    PackageVerifyTest test;
345fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestHashDataVerifierFailed04());
346fb299fa2Sopenharmony_ci}
347fb299fa2Sopenharmony_ci
348fb299fa2Sopenharmony_ciHWTEST_F(PackageVerifyTest, TestHashDataVerifierSuccess, TestSize.Level1)
349fb299fa2Sopenharmony_ci{
350fb299fa2Sopenharmony_ci    PackageVerifyTest test;
351fb299fa2Sopenharmony_ci    EXPECT_EQ(0, test.TestHashDataVerifierSuccess());
352fb299fa2Sopenharmony_ci}
353fb299fa2Sopenharmony_ci}
354