• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 "framework_client_pinauth_register_impl_test.h"
17 #include "inputer_get_data_service.h"
18 #include "pin_auth_hdi.h"
19 #include "pin_auth_proxy.h"
20 #include "pin_auth_proxy_test.h"
21 #include "pinauth_register_impl.h"
22 #include "mock_inputer.h"
23 #include "mock_inputer_get_data_service.h"
24 #include "mock_pin_auth_interface.h"
25 #include "mock_pin_auth_service.h"
26 #include "mock_remote_object.h"
27 #include "iam_common_defines.h"
28 #include "iam_logger.h"
29 #include "iam_ptr.h"
30 #include "iremote_object.h"
31 #include "file_ex.h"
32 #include "accesstoken_kit.h"
33 #include "nativetoken_kit.h"
34 #include "token_setproc.h"
35 
36 #include <openssl/sha.h>
37 
38 #define LOG_TAG "PIN_AUTH_SDK"
39 
40 namespace OHOS {
41 namespace UserIam {
42 namespace PinAuth {
43 using namespace testing;
44 using namespace testing::ext;
45 
SetUpTestCase()46 void FrameworkClientPinAuthRegisterImplTest::SetUpTestCase()
47 {
48     static const char *PERMS[] = {
49         "ohos.permission.ACCESS_PIN_AUTH"
50     };
51     NativeTokenInfoParams infoInstance = {
52         .dcapsNum = 0,
53         .permsNum = 1,
54         .aclsNum = 0,
55         .dcaps = nullptr,
56         .perms = PERMS,
57         .acls = nullptr,
58         .processName = "pin_auth_service_test",
59         .aplStr = "system_core",
60     };
61     uint64_t tokenId = GetAccessTokenId(&infoInstance);
62     SetSelfTokenID(tokenId);
63     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
64 }
65 
TearDownTestCase()66 void FrameworkClientPinAuthRegisterImplTest::TearDownTestCase()
67 {
68 }
69 
SetUp()70 void FrameworkClientPinAuthRegisterImplTest::SetUp()
71 {
72 }
73 
TearDown()74 void FrameworkClientPinAuthRegisterImplTest::TearDown()
75 {
76 }
77 
78 HWTEST_F(FrameworkClientPinAuthRegisterImplTest, ResetProxyTest001, TestSize.Level0)
79 {
80     sptr<MockPinAuthInterface> mock(new (std::nothrow) MockPinAuthInterface());
81     EXPECT_CALL(*mock, RemoveDeathRecipient(_))
82         .Times(Exactly(1))
__anona00b271d0102(const sptr<MockPinAuthInterface::DeathRecipient> &recipient) 83         .WillOnce([](const sptr<MockPinAuthInterface::DeathRecipient> &recipient) {
84             return true;
85         });
86     PinAuthRegisterImpl::Instance().proxy_ = iface_cast<PinAuthInterface>(mock);
87     EXPECT_NE(PinAuthRegisterImpl::Instance().proxy_->AsObject(), nullptr);
88     PinAuthRegisterImpl::Instance().ResetProxy(mock);
89 }
90 
91 HWTEST_F(FrameworkClientPinAuthRegisterImplTest, OnRemoteDied001, TestSize.Level0)
92 {
93     sptr<IRemoteObject::DeathRecipient> dr(new (std::nothrow) PinAuthRegisterImpl::PinAuthDeathRecipient());
94     EXPECT_NO_THROW(dr->OnRemoteDied(nullptr));
95 }
96 
97 HWTEST_F(FrameworkClientPinAuthRegisterImplTest, OnRemoteDied002, TestSize.Level0)
98 {
99     sptr<IRemoteObject::DeathRecipient> dr(new (std::nothrow) PinAuthRegisterImpl::PinAuthDeathRecipient());
100     sptr<MockPinAuthInterface> mock(new (std::nothrow) MockPinAuthInterface());
101     EXPECT_CALL(*mock, RemoveDeathRecipient(_))
102         .Times(Exactly(1))
__anona00b271d0202(const sptr<MockPinAuthInterface::DeathRecipient> &recipient) 103         .WillOnce([](const sptr<MockPinAuthInterface::DeathRecipient> &recipient) {
104             return true;
105         });
106     PinAuthRegisterImpl::Instance().proxy_ = iface_cast<PinAuthInterface>(mock);
107     EXPECT_NO_THROW(dr->OnRemoteDied(mock));
108 }
109 } // namespace PinAuth
110 } // namespace UserIam
111 } // namespace OHOS
112