1 /*
2 * Copyright (C) 2025 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 "risk_event_manager_test.h"
17
18 #include "risk_event_manager.h"
19
20 #include "iam_logger.h"
21 #include "securec.h"
22
23 #define LOG_TAG "USER_AUTH_SA"
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace testing;
29 using namespace testing::ext;
30
SetUpTestCase()31 void RiskEventManagerTest::SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 void RiskEventManagerTest::TearDownTestCase()
36 {
37 }
38
SetUp()39 void RiskEventManagerTest::SetUp()
40 {
41 }
42
TearDown()43 void RiskEventManagerTest::TearDown()
44 {
45 }
46
47 HWTEST_F(RiskEventManagerTest, SetRiskEventPropertyForAuthTypeTest, TestSize.Level0)
48 {
49 int32_t mainUserId = 100;
50 int32_t inValidUserId = -1;
51 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetRiskEventPropertyForAuthType(mainUserId,
52 AuthType::FACE, RiskEventManager::EventType::SCREENLOCK_STRONG_AUTH));
53 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetRiskEventPropertyForAuthType(inValidUserId,
54 AuthType::FACE, RiskEventManager::EventType::SCREENLOCK_STRONG_AUTH));
55 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetRiskEventPropertyForAuthType(mainUserId,
56 AuthType::PIN, RiskEventManager::EventType::SCREENLOCK_STRONG_AUTH));
57 }
58
59 HWTEST_F(RiskEventManagerTest, GetAttributesTest, TestSize.Level0)
60 {
61 int32_t mainUserId = 100;
62 int32_t inValidUserId = -1;
63 Attributes attributes;
64 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetAttributes(mainUserId, AuthType::FACE,
65 RiskEventManager::EventType::SCREENLOCK_STRONG_AUTH, attributes));
66 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetAttributes(inValidUserId, AuthType::FACE,
67 RiskEventManager::EventType::SCREENLOCK_STRONG_AUTH, attributes));
68 EXPECT_NO_THROW(RiskEventManager::GetInstance().SetAttributes(mainUserId, AuthType::FACE,
69 RiskEventManager::EventType::UNKNOWN, attributes));
70 }
71
72 HWTEST_F(RiskEventManagerTest, GetTemplateIdListTest, TestSize.Level0)
73 {
74 int32_t mainUserId = 100;
75 int32_t inValidUserId = -1;
76 std::vector<uint64_t> templateIds;
77 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetTemplateIdList(mainUserId, AuthType::FACE,
78 templateIds));
79 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetTemplateIdList(inValidUserId, AuthType::FACE,
80 templateIds));
81 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetTemplateIdList(mainUserId, AuthType::PIN,
82 templateIds));
83 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetTemplateIdList(inValidUserId, AuthType::PIN,
84 templateIds));
85 }
86
87 HWTEST_F(RiskEventManagerTest, GetStrongAuthExtraInfoTest, TestSize.Level0)
88 {
89 std::vector<uint8_t> extraInfo;
90 int32_t mainUserId = 100;
91 int32_t inValidUserId = -1;
92 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetStrongAuthExtraInfo(mainUserId,
93 AuthType::FACE, extraInfo));
94 EXPECT_NO_THROW(RiskEventManager::GetInstance().GetStrongAuthExtraInfo(inValidUserId,
95 AuthType::FACE, extraInfo));
96 }
97
98 HWTEST_F(RiskEventManagerTest, HandleStrongAuthEventTest, TestSize.Level0)
99 {
100 int32_t mainUserId = 100;
101 int32_t inValidUserId = -1;
102 EXPECT_NO_THROW(RiskEventManager::GetInstance().HandleStrongAuthEvent(mainUserId));
103 EXPECT_NO_THROW(RiskEventManager::GetInstance().HandleStrongAuthEvent(inValidUserId));
104 }
105
106 HWTEST_F(RiskEventManagerTest, SyncRiskEventsTest, TestSize.Level0)
107 {
108 auto instance = RiskEventManager::GetInstance();
109 EXPECT_NO_THROW(instance.SyncRiskEvents());
110 EXPECT_NO_THROW(instance.OnScreenLock());
111 }
112 } // namespace UserAuth
113 } // namespace UserIam
114 } // namespace OHOS