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 "UTTest_pin_auth_ui.h"
17
18 #include <unistd.h>
19 #include <memory>
20
21 #include "accesstoken_kit.h"
22 #include "dm_ability_manager.h"
23 #include "dm_constants.h"
24 #include "dm_log.h"
25 #include "nlohmann/json.hpp"
26 #include "device_manager_service_listener.h"
27 #include "nativetoken_kit.h"
28 #include "token_setproc.h"
29
30 using namespace OHOS::Security::AccessToken;
31 namespace OHOS {
32 namespace DistributedHardware {
SetUp()33 void PinAuthUiTest::SetUp()
34 {
35 const int32_t PERMS_NUM = 3;
36 const int32_t PEAMS_INDEX_TWO = 2;
37 uint64_t tokenId;
38 const char *perms[PERMS_NUM];
39 perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
40 perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
41 perms[PEAMS_INDEX_TWO] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED";
42 NativeTokenInfoParams infoInstance = {
43 .dcapsNum = 0,
44 .permsNum = PERMS_NUM,
45 .aclsNum = 0,
46 .dcaps = NULL,
47 .perms = perms,
48 .acls = NULL,
49 .processName = "device_manager",
50 .aplStr = "system_basic",
51 };
52 tokenId = GetAccessTokenId(&infoInstance);
53 SetSelfTokenID(tokenId);
54 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
55 }
56
TearDown()57 void PinAuthUiTest::TearDown()
58 {
59 }
60
SetUpTestCase()61 void PinAuthUiTest::SetUpTestCase()
62 {
63 }
64
TearDownTestCase()65 void PinAuthUiTest::TearDownTestCase()
66 {
67 }
68
69 namespace {
70 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
71 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
72 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
73 std::shared_ptr<DmAuthManager> authManager =
74 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
75 /**
76 * @tc.name: PinAuthUi::ShowPinDialog_001
77 * @tc.desc: Call ShowPinDialog to check whether the return value is ERR_DM_FAILED
78 * @tc.type: FUNC
79 * @tc.require: AR000GHSJK
80 */
81 HWTEST_F(PinAuthUiTest, ShowPinDialog_001, testing::ext::TestSize.Level0)
82 {
83 std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
84 int32_t code = 123456;
85 int32_t ret = pinAuthUi->ShowPinDialog(code, nullptr);
86 ASSERT_EQ(ret, ERR_DM_FAILED);
87 }
88
89 /**
90 * @tc.name: PinAuthUi::ShowPinDialog_002
91 * @tc.desc: Call ShowPinDialog to check whether the return value is DM_OK
92 * @tc.type: FUNC
93 * @tc.require: AR000GHSJK
94 */
95 HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0)
96 {
97 std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
98 int32_t code = 123456;
99 int32_t ret = pinAuthUi->ShowPinDialog(code, authManager);
100 ASSERT_EQ(ret, DM_OK);
101 }
102
103 /**
104 * @tc.name: PinAuthUi::ShowPinDialog_001
105 * @tc.desc: Call InputPinDialog to check whether the return value is ERR_DM_FAILED
106 * @tc.type: FUNC
107 * @tc.require: AR000GHSJK
108 */
109 HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
110 {
111 std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
112 int32_t ret = pinAuthUi->InputPinDialog(nullptr);
113 ASSERT_EQ(ret, ERR_DM_FAILED);
114 }
115
116 /**
117 * @tc.name: PinAuthUi::ShowPinDialog_001
118 * @tc.desc: Call InputPinDialog to check whether the return value is DM_OK
119 * @tc.type: FUNC
120 * @tc.require: AR000GHSJK
121 */
122 HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0)
123 {
124 std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
125 int32_t ret = pinAuthUi->InputPinDialog(authManager);
126 ASSERT_EQ(ret, DM_OK);
127 }
128 }
129 } // namespace DistributedHardware
130 } // namespace OHOS
131