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 #include <gtest/gtest.h>
16 #include "i_sec_comp_probe.h"
17 #include "location_button.h"
18 #define private public
19 #include "sec_comp_caller_authorization.h"
20 #undef private
21 #include "sec_comp_client.h"
22 #include "sec_comp_enhance_adapter.h"
23 #include "sec_comp_err.h"
24 #include "sec_comp_info.h"
25 #include "sec_comp_kit.h"
26 #include "sec_comp_log.h"
27 #include "sec_comp_tool.h"
28 #include "sec_comp_ui_register.h"
29 #include "test_common.h"
30 #include "token_setproc.h"
31
32 using namespace testing::ext;
33 using namespace OHOS::Security::SecurityComponent;
34 using namespace OHOS::Security::AccessToken;
35
36 namespace {
37 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
38 LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompRegisterCallbackTest"};
39 static AccessTokenID g_selfTokenId = 0;
40 static int32_t g_selfUid = 0;
41
42 class MockUiSecCompProbe : public ISecCompProbe {
43 public:
GetComponentInfo(int32_t nodeId,std::string & componentInfo)44 int32_t GetComponentInfo(int32_t nodeId, std::string& componentInfo) override
45 {
46 componentInfo = mockComponentInfo;
47 return mockRes;
48 }
49 std::string mockComponentInfo;
50 int32_t mockRes;
51 };
52
53 static MockUiSecCompProbe g_probe;
InitUiRegister()54 static void InitUiRegister()
55 {
56 std::vector<uintptr_t> callerList;
57 SecCompUiRegister registerCallback(callerList, &g_probe);
58 SecCompCallerAuthorization::GetInstance().kitCallerList_.clear();
59 SecCompCallerAuthorization::GetInstance().isInit_ = false;
60 }
61 } // namespace
62
63 class SecCompRegisterCallbackTest : public testing::Test {
64 public:
65 static void SetUpTestCase();
66
67 static void TearDownTestCase();
68
69 void SetUp() override;
70
71 void TearDown() override;
72 };
73
SetUpTestCase()74 void SecCompRegisterCallbackTest::SetUpTestCase()
75 {
76 InitUiRegister();
77 SC_LOG_INFO(LABEL, "SecCompRegisterCallbackTest.");
78 }
79
TearDownTestCase()80 void SecCompRegisterCallbackTest::TearDownTestCase()
81 {
82 SC_LOG_INFO(LABEL, "SecCompRegisterCallbackTest.");
83 }
84
SetUp()85 void SecCompRegisterCallbackTest::SetUp()
86 {
87 g_selfUid = getuid();
88 g_selfTokenId = GetSelfTokenID();
89 SC_LOG_INFO(LABEL, "SetUp ok.");
90 }
91
TearDown()92 void SecCompRegisterCallbackTest::TearDown()
93 {
94 setuid(g_selfUid);
95 EXPECT_EQ(0, SetSelfTokenID(g_selfTokenId));
96 SC_LOG_INFO(LABEL, "TearDown.");
97 }
98
99 /**
100 * @tc.name: RegisterWithoutPreprocess001
101 * @tc.desc: test register without preprocess
102 * @tc.type: FUNC
103 * @tc.require: AR000HO9JM
104 */
105 HWTEST_F(SecCompRegisterCallbackTest, RegisterWithoutPreprocess001, TestSize.Level1)
106 {
107 nlohmann::json jsonRes;
108 TestCommon::BuildLocationComponentInfo(jsonRes);
109 std::string locationInfo = jsonRes.dump();
110
111 SecCompEnhanceAdapter::InitEnhanceHandler(SEC_COMP_ENHANCE_CLIENT_INTERFACE);
112 int32_t scId;
113 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
114 ASSERT_EQ(SC_ENHANCE_ERROR_CHALLENGE_CHECK_FAIL,
115 SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
116 ASSERT_EQ(-1, scId);
117 #else
118 ASSERT_EQ(SC_OK,
119 SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
120 ASSERT_NE(-1, scId);
121 EXPECT_EQ(SC_OK, SecCompClient::GetInstance().UnregisterSecurityComponent(scId));
122 #endif
123 }
124
125 /**
126 * @tc.name: RegisterSecurityComponent001
127 * @tc.desc: test register security component success.
128 * @tc.type: FUNC
129 * @tc.require: AR000HO9JM
130 */
131 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent001, TestSize.Level1)
132 {
133 nlohmann::json jsonRes;
134 TestCommon::BuildLocationComponentInfo(jsonRes);
135 std::string locationInfo = jsonRes.dump();
136 g_probe.mockComponentInfo = locationInfo;
137 g_probe.mockRes = 0;
138
139 int32_t scId;
140 ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
141 ASSERT_NE(-1, scId);
142
143 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
144 }
145
146 /**
147 * @tc.name: RegisterSecurityComponent002
148 * @tc.desc: test register callback failed.
149 * @tc.type: FUNC
150 * @tc.require: AR000HO9JM
151 */
152 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent002, TestSize.Level1)
153 {
154 nlohmann::json jsonRes;
155 TestCommon::BuildLocationComponentInfo(jsonRes);
156 std::string locationInfo = jsonRes.dump();
157 g_probe.mockComponentInfo = locationInfo;
158 g_probe.mockRes = -1;
159
160 int32_t scId;
161 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
162 ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_OPER_FAIL,
163 SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
164 ASSERT_EQ(-1, scId);
165 #else
166 ASSERT_EQ(SC_OK,
167 SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
168 ASSERT_NE(-1, scId);
169 ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
170 #endif
171 }
172
173 /**
174 * @tc.name: RegisterSecurityComponent003
175 * @tc.desc: test register in MaliciousAppList.
176 * @tc.type: FUNC
177 * @tc.require: AR000HO9JM
178 */
179 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent003, TestSize.Level1)
180 {
181 nlohmann::json jsonRes;
182 TestCommon::BuildLocationComponentInfo(jsonRes);
183 std::string locationInfo = jsonRes.dump();
184 g_probe.mockComponentInfo = locationInfo;
185 g_probe.mockRes = 0;
186
187 int32_t scId;
188 ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
189 ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
190 }
191
192 /**
193 * @tc.name: RegisterSecurityComponent004
194 * @tc.desc: Test register security component check touch info failed
195 * @tc.type: FUNC
196 * @tc.require: AR000HO9J7
197 */
198 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Level1)
199 {
200 system("param set sec.comp.enhance 1");
201 nlohmann::json jsonRes;
202 TestCommon::BuildSaveComponentInfo(jsonRes);
203 std::string saveInfo = jsonRes.dump();
204 int32_t scId;
205
206 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
207 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
208 struct SecCompClickEvent touchInfo = {
209 .touchX = TestCommon::TEST_COORDINATE,
210 .touchY = TestCommon::TEST_COORDINATE,
211 .timestamp = static_cast<uint64_t>(
212 std::chrono::high_resolution_clock::now().time_since_epoch().count())
213 };
214 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
215 touchInfo.extraInfo.data = data;
216 EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID,
217 SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
218 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
219 system("param set sec.comp.enhance 0");
220 }
221
222 /**
223 * @tc.name: RegisterSecurityComponent005
224 * @tc.desc: Test register security component permission grant failed
225 * @tc.type: FUNC
226 * @tc.require: AR000HO9J7
227 */
228 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Level1)
229 {
230 system("param set sec.comp.enhance 1");
231 nlohmann::json jsonRes;
232 TestCommon::BuildSaveComponentInfo(jsonRes);
233 std::string saveInfo = jsonRes.dump();
234 int32_t scId;
235
236 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
237 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
238 struct SecCompClickEvent touchInfo = {
239 .touchX = TestCommon::TEST_COORDINATE,
240 .touchY = TestCommon::TEST_COORDINATE,
241 .timestamp = static_cast<uint64_t>(
242 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
243 };
244 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
245 touchInfo.extraInfo.data = data;
246 EXPECT_EQ(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
247 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
248 system("param set sec.comp.enhance 0");
249 }
250
251 /**
252 * @tc.name: RegisterSecurityComponent006
253 * @tc.desc: Test register security component permission grant failed caller error
254 * @tc.type: FUNC
255 * @tc.require: AR000HO9J7
256 */
257 HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent006, TestSize.Level1)
258 {
259 nlohmann::json jsonRes;
260 TestCommon::BuildSaveComponentInfo(jsonRes);
261 std::string saveInfo = jsonRes.dump();
262 int32_t scId;
263 setuid(100);
264 EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
265 }
266
267 /**
268 * @tc.name: ReportSecurityComponentClickEvent001
269 * @tc.desc: Test register security component success
270 * @tc.type: FUNC
271 * @tc.require: AR000HO9J7
272 */
273 HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, TestSize.Level1)
274 {
275 system("param set sec.comp.enhance 1");
276 nlohmann::json jsonRes;
277 TestCommon::BuildSaveComponentInfo(jsonRes);
278 std::string saveInfo = jsonRes.dump();
279 int32_t scId;
280
281 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
282 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
283 struct SecCompClickEvent touchInfo = {
284 .touchX = TestCommon::TEST_COORDINATE,
285 .touchY = TestCommon::TEST_COORDINATE,
286 .timestamp = static_cast<uint64_t>(
287 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
288 };
289 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
290 touchInfo.extraInfo.data = data;
291
292 ASSERT_EQ(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
293 uint32_t selfTokenId = GetSelfTokenID();
294 ASSERT_TRUE(SecCompKit::ReduceAfterVerifySavePermission(selfTokenId));
295 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
296 system("param set sec.comp.enhance 0");
297 }
298
299 /**
300 * @tc.name: ReportSecurityComponentClickEvent002
301 * @tc.desc: Test report security component caller error
302 * @tc.type: FUNC
303 * @tc.require: AR000HO9J7
304 */
305 HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, TestSize.Level1)
306 {
307 system("param set sec.comp.enhance 1");
308 nlohmann::json jsonRes;
309 TestCommon::BuildSaveComponentInfo(jsonRes);
310 std::string saveInfo = jsonRes.dump();
311 int32_t scId;
312 ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID));
313
314 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
315 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
316 struct SecCompClickEvent touchInfo = {
317 .touchX = TestCommon::TEST_COORDINATE,
318 .touchY = TestCommon::TEST_COORDINATE,
319 .timestamp = static_cast<uint64_t>(
320 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
321 };
322 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
323 touchInfo.extraInfo.data = data;
324
325 setuid(100);
326 ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID,
327 SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
328 setuid(g_selfUid);
329 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
330 system("param set sec.comp.enhance 0");
331 }
332
333 /**
334 * @tc.name: ReportSecurityComponentClickEvent003
335 * @tc.desc: Test report security component data is empty
336 * @tc.type: FUNC
337 * @tc.require: AR000HO9J7
338 */
339 HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, TestSize.Level1)
340 {
341 nlohmann::json jsonRes;
342 TestCommon::BuildSaveComponentInfo(jsonRes);
343 std::string saveInfo = jsonRes.dump();
344 int32_t scId;
345 ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID));
346
347 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
348
349 struct SecCompClickEvent touchInfo = {
350 .touchX = TestCommon::TEST_COORDINATE,
351 .touchY = TestCommon::TEST_COORDINATE,
352 .timestamp = static_cast<uint64_t>(
353 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
354 };
355 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
356 ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID,
357 SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
358 #else
359 ASSERT_EQ(SC_OK,
360 SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
361 #endif
362 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
363 }
364
365 /**
366 * @tc.name: ReportClickWithoutHmac001
367 * @tc.desc: Test report click event permission denied
368 * @tc.type: FUNC
369 * @tc.require: AR000HO9JM
370 */
371 HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1)
372 {
373 system("param set sec.comp.enhance 1");
374 nlohmann::json jsonRes;
375 TestCommon::BuildLocationComponentInfo(jsonRes);
376 std::string locationInfo = jsonRes.dump();
377 g_probe.mockComponentInfo = locationInfo;
378 g_probe.mockRes = 0;
379
380 int32_t scId;
381 ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId));
382 ASSERT_NE(-1, scId);
383 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
384 struct SecCompClickEvent touch = {
385 .touchX = TestCommon::TEST_COORDINATE,
386 .touchY = TestCommon::TEST_COORDINATE,
387 .timestamp = static_cast<uint64_t>(
388 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
389 };
390 touch.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
391 touch.extraInfo.data = data;
392 EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL,
393 SecCompKit::ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr));
394 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
395 system("param set sec.comp.enhance 0");
396 }
397
398 /**
399 * @tc.name: ReduceAfterVerifySavePermission001
400 * @tc.desc: Test register security component wrong hap
401 * @tc.type: FUNC
402 * @tc.require: AR000HO9J7
403 */
404 HWTEST_F(SecCompRegisterCallbackTest, ReduceAfterVerifySavePermission001, TestSize.Level1)
405 {
406 system("param set sec.comp.enhance 1");
407 nlohmann::json jsonRes;
408 TestCommon::BuildSaveComponentInfo(jsonRes);
409 std::string saveInfo = jsonRes.dump();
410 int32_t scId;
411 ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID));
412
413 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
414 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
415 struct SecCompClickEvent touchInfo = {
416 .touchX = TestCommon::TEST_COORDINATE,
417 .touchY = TestCommon::TEST_COORDINATE,
418 .timestamp = static_cast<uint64_t>(
419 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
420 };
421 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
422 touchInfo.extraInfo.data = data;
423
424 ASSERT_EQ(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
425 setuid(100);
426 ASSERT_FALSE(SecCompKit::ReduceAfterVerifySavePermission(TestCommon::HAP_TOKEN_ID));
427 // mediaLibraryTokenId_ != 0
428 ASSERT_FALSE(SecCompKit::ReduceAfterVerifySavePermission(TestCommon::HAP_TOKEN_ID));
429 setuid(g_selfUid);
430 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
431 system("param set sec.comp.enhance 0");
432 }
433
434 /**
435 * @tc.name: ReduceAfterVerifySavePermission002
436 * @tc.desc: Test register security component invalid tokenId
437 * @tc.type: FUNC
438 * @tc.require: AR000HO9J7
439 */
440 HWTEST_F(SecCompRegisterCallbackTest, ReduceAfterVerifySavePermission002, TestSize.Level1)
441 {
442 system("param set sec.comp.enhance 1");
443 nlohmann::json jsonRes;
444 TestCommon::BuildSaveComponentInfo(jsonRes);
445 std::string saveInfo = jsonRes.dump();
446 int32_t scId;
447
448 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
449 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
450 struct SecCompClickEvent touchInfo = {
451 .touchX = TestCommon::TEST_COORDINATE,
452 .touchY = TestCommon::TEST_COORDINATE,
453 .timestamp = static_cast<uint64_t>(
454 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
455 };
456 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
457 touchInfo.extraInfo.data = data;
458
459 ASSERT_EQ(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
460 ASSERT_FALSE(SecCompKit::ReduceAfterVerifySavePermission(0));
461 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
462 system("param set sec.comp.enhance 0");
463 }
464
465 /**
466 * @tc.name: UnregisterSecurityComponent001
467 * @tc.desc: Test unregister security component caller error
468 * @tc.type: FUNC
469 * @tc.require: AR000HO9J7
470 */
471 HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.Level1)
472 {
473 system("param set sec.comp.enhance 1");
474 nlohmann::json jsonRes;
475 TestCommon::BuildSaveComponentInfo(jsonRes);
476 std::string saveInfo = jsonRes.dump();
477 int32_t scId;
478
479 EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId));
480 uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 };
481 struct SecCompClickEvent touchInfo = {
482 .touchX = TestCommon::TEST_COORDINATE,
483 .touchY = TestCommon::TEST_COORDINATE,
484 .timestamp = static_cast<uint64_t>(
485 std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT
486 };
487 touchInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE;
488 touchInfo.extraInfo.data = data;
489 EXPECT_EQ(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, touchInfo, nullptr));
490 setuid(100);
491 EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, SecCompKit::UnregisterSecurityComponent(scId));
492 setuid(g_selfUid);
493 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
494 system("param set sec.comp.enhance 0");
495 }
496
497 /**
498 * @tc.name: UpdateSecurityComponent001
499 * @tc.desc: Test update security component success
500 * @tc.type: FUNC
501 * @tc.require: AR000HO9IN
502 */
503 HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent001, TestSize.Level1)
504 {
505 nlohmann::json jsonRes;
506 TestCommon::BuildSaveComponentInfo(jsonRes);
507 std::string saveInfo = jsonRes.dump();
508 int32_t scId;
509 ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, saveInfo, scId));
510 ASSERT_NE(-1, scId);
511 ASSERT_EQ(SC_OK, SecCompKit::UpdateSecurityComponent(scId, saveInfo));
512 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
513 }
514
515 /**
516 * @tc.name: UpdateSecurityComponent002
517 * @tc.desc: Test update security component caller error
518 * @tc.type: FUNC
519 * @tc.require: AR000HO9IN
520 */
521 HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent002, TestSize.Level1)
522 {
523 nlohmann::json jsonRes;
524 TestCommon::BuildSaveComponentInfo(jsonRes);
525 std::string saveInfo = jsonRes.dump();
526 int32_t scId;
527
528 ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID));
529 ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, saveInfo, scId));
530 ASSERT_NE(-1, scId);
531 setuid(100);
532 ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, SecCompKit::UpdateSecurityComponent(scId, saveInfo));
533 setuid(g_selfUid);
534 EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId));
535 }
536