• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "sec_comp_enhance_adapter_test.h"
17 #include <unistd.h>
18 #include "sec_comp_err.h"
19 #include "sec_comp_log.h"
20 #include "sec_comp_info.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::Security::SecurityComponent;
24 
25 namespace {
26 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
27     LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompEnhanceAdapterTest"};
28 static constexpr uint32_t SEC_COMP_ENHANCE_CFG_SIZE = 76;
29 static constexpr uint32_t MAX_HMAC_SIZE = 160;
30 }  // namespace
31 
SetUpTestCase()32 void SecCompEnhanceAdapterTest::SetUpTestCase()
33 {
34     SC_LOG_INFO(LABEL, "SetUpTestCase.");
35 }
36 
TearDownTestCase()37 void SecCompEnhanceAdapterTest::TearDownTestCase()
38 {
39     SC_LOG_INFO(LABEL, "TearDownTestCase.");
40 }
41 
SetUp()42 void SecCompEnhanceAdapterTest::SetUp()
43 {
44     SC_LOG_INFO(LABEL, "SetUp ok.");
45 }
46 
TearDown()47 void SecCompEnhanceAdapterTest::TearDown()
48 {
49     SC_LOG_INFO(LABEL, "TearDown.");
50 }
51 
52 /**
53  * @tc.name: EnhanceAdapter001
54  * @tc.desc: test enhance adapter fail
55  * @tc.type: FUNC
56  * @tc.require:
57  */
58 HWTEST_F(SecCompEnhanceAdapterTest, EnhanceAdapter001, TestSize.Level0)
59 {
60     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
61     EXPECT_EQ(SecCompEnhanceAdapter::EnableInputEnhance(), SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE);
62     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
63     EXPECT_EQ(SecCompEnhanceAdapter::DisableInputEnhance(), SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE);
64 
65     SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false;
66     uint8_t cfgData[SEC_COMP_ENHANCE_CFG_SIZE] = { 0 };
67     EXPECT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE,
68         SecCompEnhanceAdapter::SetEnhanceCfg(cfgData, SEC_COMP_ENHANCE_CFG_SIZE));
69 
70     SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false;
71     uint8_t originData[MAX_HMAC_SIZE] = { 0 };
72     uint32_t enHancedataLen = MAX_HMAC_SIZE;
73     EXPECT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE,
74         SecCompEnhanceAdapter::GetPointerEventEnhanceData(originData, MAX_HMAC_SIZE, nullptr, enHancedataLen));
75 
76     SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false;
77     SecCompClickEvent touchInfo = {};
78     ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, SecCompEnhanceAdapter::CheckExtraInfo(touchInfo));
79 
80     SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false;
81     std::string componentInfo;
82     SecCompEnhanceAdapter::EnhanceDataPreprocess(1, componentInfo);
83 
84     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
85     SecCompEnhanceAdapter::StartEnhanceService();
86     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
87     SecCompEnhanceAdapter::ExitEnhanceService();
88     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
89     SecCompEnhanceAdapter::NotifyProcessDied(0);
90     SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false;
91     SecCompEnhanceAdapter::RegisterScIdEnhance(0);
92     SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false;
93     SecCompEnhanceAdapter::UnregisterScIdEnhance(0);
94     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
95     SecCompEnhanceAdapter::AddSecurityComponentProcess(0);
96     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
97 
98     OHOS::MessageParcel input;
99     OHOS::MessageParcel output;
100     OHOS::MessageParcel reply;
101     SecCompRawdata inputData;
102     SecCompRawdata outputData;
103     SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false;
104     SecCompEnhanceAdapter::EnhanceClientSerialize(input, outputData);
105     SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false;
106     SecCompEnhanceAdapter::EnhanceClientDeserialize(inputData, output);
107     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
108     SecCompEnhanceAdapter::EnhanceSrvSerialize(input, outputData);
109     SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false;
110     SecCompEnhanceAdapter::EnhanceSrvDeserialize(inputData, output);
111     std::shared_ptr<SecCompBase> compInfo;
112     const nlohmann::json jsonComponent;
113     ASSERT_EQ(SC_OK, SecCompEnhanceAdapter::CheckComponentInfoEnhance(0, compInfo, jsonComponent));
114 }
115