1 /*
2 * Copyright (c) 2022-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 "UTTest_permission_manager.h"
17 #include "accesstoken_kit.h"
18 #include "nativetoken_kit.h"
19 #include "token_setproc.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
SetUp()23 void PremissionManagerTest::SetUp()
24 {
25 const int32_t permsNum = 2;
26 const int32_t indexZero = 0;
27 const int32_t indexOne = 1;
28 uint64_t tokenId;
29 const char *perms[permsNum];
30 perms[indexZero] = "ohos.permission.ACCESS_SERVICE_DM";
31 perms[indexOne] = "ohos.permission.DISTRIBUTED_DATASYNC";
32 NativeTokenInfoParams infoInstance = {
33 .dcapsNum = 0,
34 .permsNum = permsNum,
35 .aclsNum = 0,
36 .dcaps = NULL,
37 .perms = perms,
38 .acls = NULL,
39 .processName = "dsoftbus_service",
40 .aplStr = "system_core",
41 };
42 tokenId = GetAccessTokenId(&infoInstance);
43 SetSelfTokenID(tokenId);
44 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
45 }
46
TearDown()47 void PremissionManagerTest::TearDown()
48 {
49 }
50
SetUpTestCase()51 void PremissionManagerTest::SetUpTestCase()
52 {
53 }
54
TearDownTestCase()55 void PremissionManagerTest::TearDownTestCase()
56 {
57 }
58
59 namespace {
60
61 /**
62 * @tc.name: PinAuthUi::CheckPermission_001
63 * @tc.desc: the return value is true
64 * @tc.type: FUNC
65 * @tc.require: AR000GHSJK
66 */
67 HWTEST_F(PremissionManagerTest, CheckPermission_001, testing::ext::TestSize.Level0)
68 {
69 bool ret = PermissionManager::GetInstance().CheckPermission();
70 ASSERT_EQ(ret, true);
71 }
72
73 /**
74 * @tc.name: PinAuthUi::GetCallerProcessName_001
75 * @tc.desc: the return value is not DM_OK
76 * @tc.type: FUNC
77 * @tc.require: AR000GHSJK
78 */
79 HWTEST_F(PremissionManagerTest, GetCallerProcessName_001, testing::ext::TestSize.Level0)
80 {
81 std::string processName;
82 int32_t ret = PermissionManager::GetInstance().GetCallerProcessName(processName);
83 ASSERT_EQ(ret, DM_OK);
84 }
85
86 /**
87 * @tc.name: PinAuthUi::CheckProcessNameValidOnAuthCode_001
88 * @tc.desc: the return value is false
89 * @tc.type: FUNC
90 * @tc.require: AR000GHSJK
91 */
92 HWTEST_F(PremissionManagerTest, CheckProcessNameValidOnAuthCode_001, testing::ext::TestSize.Level0)
93 {
94 std::string processName;
95 bool ret = PermissionManager::GetInstance().CheckProcessNameValidOnAuthCode(processName);
96 ASSERT_EQ(ret, false);
97 }
98
99 /**
100 * @tc.name: PinAuthUi::CheckProcessNameValidOnAuthCode_002
101 * @tc.desc: the return value is true
102 * @tc.type: FUNC
103 * @tc.require: AR000GHSJK
104 */
105 HWTEST_F(PremissionManagerTest, CheckProcessNameValidOnAuthCode_002, testing::ext::TestSize.Level0)
106 {
107 std::string processName = "processName";
108 bool ret = PermissionManager::GetInstance().CheckProcessNameValidOnAuthCode(processName);
109 ASSERT_EQ(ret, false);
110 }
111
112 /**
113 * @tc.name: PinAuthUi::CheckProcessNameValidOnPinHolder_001
114 * @tc.desc: the return value is false
115 * @tc.type: FUNC
116 * @tc.require: AR000GHSJK
117 */
118 HWTEST_F(PremissionManagerTest, CheckProcessNameValidOnPinHolder_001, testing::ext::TestSize.Level0)
119 {
120 std::string processName;
121 bool ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName);
122 ASSERT_EQ(ret, false);
123 }
124
125 /**
126 * @tc.name: PinAuthUi::CheckProcessNameValidOnPinHolder_002
127 * @tc.desc: the return value is true
128 * @tc.type: FUNC
129 * @tc.require: AR000GHSJK
130 */
131 HWTEST_F(PremissionManagerTest, CheckProcessNameValidOnPinHolder_002, testing::ext::TestSize.Level0)
132 {
133 std::string processName = "processName";
134 bool ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName);
135 ASSERT_EQ(ret, false);
136 }
137 }
138 } // namespace DistributedHardware
139 } // namespace OHOS