1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <memory>
18 #include <string>
19 #include "mock_http_client/http_client_error.h"
20 #include "mock_http_client/http_client_request.h"
21 #include "mock_http_client/http_client_response.h"
22 #include "mock_http_client/http_client_task.h"
23 #include "app_domain_verify_mgr_client.h"
24 #include "mock_constant.h"
25 #include "mock_verify_agent.h"
26 #include "agent_interface_code.h"
27 #define private public
28 #define protected public
29 #include "app_domain_verify_agent_client.h"
30 #include "app_domain_verify_agent_service.h"
31 #include "app_domain_verify_mgr_service.h"
32 #undef private
33 #undef protected
34 #include "mock_access_token.h"
35
36 namespace OHOS::AppDomainVerify {
37 using ::testing::_;
38 using ::testing::Invoke;
39 using ::testing::Mock;
40 using namespace testing;
41 using namespace testing::ext;
42 class AppDomainVerifyAgentModuleTest : public testing::Test {
43 public:
44 static void SetUpTestCase(void);
45 static void TearDownTestCase(void);
46 void SetUp();
47 void TearDown();
48 };
49
SetUpTestCase(void)50 void AppDomainVerifyAgentModuleTest::SetUpTestCase(void)
51 {
52 printf("SetUpTestCase \n");
53 }
54
TearDownTestCase(void)55 void AppDomainVerifyAgentModuleTest::TearDownTestCase(void)
56 {
57 printf("TearDownTestCase \n");
58 }
59
SetUp(void)60 void AppDomainVerifyAgentModuleTest::SetUp(void)
61 {
62 printf("SetUp \n");
63 MockAccessToken::mockSA();
64 AppDomainVerifyMgrClient::GetInstance()->ClearDomainVerifyStatus(APP_IDENTIFIER, BUNDLE_NAME);
65 }
66
TearDown(void)67 void AppDomainVerifyAgentModuleTest::TearDown(void)
68 {
69 printf("TearDown \n");
70 }
71
Sleep(int milliseconds=10)72 static void Sleep(int milliseconds = 10)
73 {
74 std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
75 }
76
77 std::string jsonString =
78 R"({"applinking":{"apps":[{"appIdentifier":"appIdentifier","bundleName":"com.openHarmony.test","fingerprint":"fingerprint"}]}})";
79
80 /**
81 * @tc.name: AppDomainVerifyAgentModuleTest001
82 * @tc.desc: SingleVerify bundleName fingerprint ok test.
83 * @tc.type: FUNC
84 */
85 HWTEST_F(AppDomainVerifyAgentModuleTest, AppDomainVerifyAgentModuleTest001, TestSize.Level0)
86 {
87 std::shared_ptr<AppDomainVerifyAgentService> appDomainVerifyAgentService =
88 std::make_shared<AppDomainVerifyAgentService>();
89 AppVerifyBaseInfo appVerifyBaseInfo;
90 appVerifyBaseInfo.bundleName = BUNDLE_NAME;
91 appVerifyBaseInfo.fingerprint = FINGERPRINT;
92
93 VerifyResultInfo verifyResultInfo;
94 verifyResultInfo.appIdentifier = APP_IDENTIFIER;
95 verifyResultInfo.hostVerifyStatusMap.insert_or_assign(
96 "https://" + HOST, std::make_tuple(InnerVerifyStatus::UNKNOWN, std::string(), 0));
97 appDomainVerifyAgentService->SingleVerify(appVerifyBaseInfo, verifyResultInfo);
98 Sleep();
99 DomainVerifyStatus domainVerificationState;
100 auto queryRes = AppDomainVerifyMgrClient::GetInstance()->QueryDomainVerifyStatus(
101 BUNDLE_NAME, domainVerificationState);
102 ASSERT_TRUE(queryRes);
103 ASSERT_TRUE(domainVerificationState == DomainVerifyStatus::STATE_NONE);
104 }
105 }
106