1 /*
2 * Copyright (C) 2022 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 "user_idm_callback_proxy_test.h"
17
18 #include "iam_ptr.h"
19 #include "mock_credential_info.h"
20 #include "mock_remote_object.h"
21 #include "mock_secure_user_info.h"
22 #include "user_idm_callback_proxy.h"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
27 using namespace testing;
28 using namespace testing::ext;
29
SetUpTestCase()30 void UserIdmCallbackProxyTest::SetUpTestCase()
31 {
32 }
33
TearDownTestCase()34 void UserIdmCallbackProxyTest::TearDownTestCase()
35 {
36 }
37
SetUp()38 void UserIdmCallbackProxyTest::SetUp()
39 {
40 }
41
TearDown()42 void UserIdmCallbackProxyTest::TearDown()
43 {
44 }
45
46 HWTEST_F(UserIdmCallbackProxyTest, TestOnResult_001, TestSize.Level0)
47 {
48 sptr<MockRemoteObject> obj = new MockRemoteObject();
49 EXPECT_NE(obj, nullptr);
50 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
51 .WillOnce(
__anoneebbe0320102(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 52 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
53 EXPECT_EQ(code, IdmCallbackInterface::IDM_CALLBACK_ON_RESULT);
54 return OHOS::NO_ERROR;
55 }
56 );
57
58 auto proxy = Common::MakeShared<IdmCallbackProxy>(obj);
59 EXPECT_NE(proxy, nullptr);
60
61 int32_t result = 0;
62 Attributes extraInfo;
63 proxy->OnResult(result, extraInfo);
64 }
65
66 HWTEST_F(UserIdmCallbackProxyTest, TestOnAcquireInfo_001, TestSize.Level0)
67 {
68 sptr<MockRemoteObject> obj = new MockRemoteObject();
69 EXPECT_NE(obj, nullptr);
70 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
71 .WillOnce(
__anoneebbe0320202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 72 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
73 EXPECT_EQ(code, IdmCallbackInterface::IDM_CALLBACK_ON_ACQUIRE_INFO);
74 return OHOS::NO_ERROR;
75 }
76 );
77
78 auto proxy = Common::MakeShared<IdmCallbackProxy>(obj);
79 EXPECT_NE(proxy, nullptr);
80
81 int32_t module = 10;
82 int32_t acquireInfo = 20;
83 Attributes extraInfo;
84 proxy->OnAcquireInfo(module, acquireInfo, extraInfo);
85 }
86
87 HWTEST_F(UserIdmCallbackProxyTest, TestOnCredentialInfos_001, TestSize.Level0)
88 {
89 sptr<MockRemoteObject> obj = new MockRemoteObject();
90 EXPECT_NE(obj, nullptr);
91 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
92 .WillOnce(
__anoneebbe0320302(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 93 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
94 EXPECT_EQ(code, IdmGetCredInfoCallbackInterface::ON_GET_INFO);
95 return OHOS::NO_ERROR;
96 }
97 );
98
99 auto proxy = Common::MakeShared<IdmGetCredentialInfoProxy>(obj);
100 EXPECT_NE(proxy, nullptr);
101
102 std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> infoList;
103 infoList.push_back(nullptr);
104 PinSubType subType = PIN_SIX;
105 proxy->OnCredentialInfos(infoList, subType);
106
107 infoList.clear();
108 auto credInfo = Common::MakeShared<MockCredentialInfo>();
109 EXPECT_NE(credInfo, nullptr);
110 infoList.push_back(credInfo);
111
112 EXPECT_CALL(*credInfo, GetCredentialId()).WillOnce(Return(20));
113 EXPECT_CALL(*credInfo, GetTemplateId()).WillOnce(Return(30));
114 EXPECT_CALL(*credInfo, GetAuthType()).WillOnce(Return(PIN));
115
116 proxy->OnCredentialInfos(infoList, subType);
117 }
118
119 HWTEST_F(UserIdmCallbackProxyTest, TestOnSecureUserInfo_001, TestSize.Level0)
120 {
121 sptr<MockRemoteObject> obj = new MockRemoteObject();
122 EXPECT_NE(obj, nullptr);
123 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
124 .WillOnce(
__anoneebbe0320402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 125 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
126 EXPECT_EQ(code, IdmGetSecureUserInfoCallbackInterface::ON_GET_SEC_INFO);
127 return OHOS::NO_ERROR;
128 }
129 );
130
131 auto proxy = Common::MakeShared<IdmGetSecureUserInfoProxy>(obj);
132 EXPECT_NE(proxy, nullptr);
133
134 std::shared_ptr<IdmGetSecureUserInfoCallbackInterface::SecureUserInfo> info = nullptr;
135 proxy->OnSecureUserInfo(info);
136
137 std::vector<std::shared_ptr<IdmGetSecureUserInfoCallbackInterface::EnrolledInfo>> enrolledInfos;
138 enrolledInfos.push_back(nullptr);
139 auto testUserInfo = Common::MakeShared<MockSecureUserInfo>();
140 EXPECT_NE(testUserInfo, nullptr);
141 EXPECT_CALL(*testUserInfo, GetSecUserId()).WillOnce(Return(10));
142 EXPECT_CALL(*testUserInfo, GetEnrolledInfo()).WillOnce(Return(enrolledInfos));
143
144 proxy->OnSecureUserInfo(testUserInfo);
145 }
146 } // namespace UserAuth
147 } // namespace UserIam
148 } // namespace OHOS
149