1 /*
2 * Copyright (c) 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 "el5_filekey_manager_kit_unittest.h"
17
18 #include "accesstoken_kit.h"
19 #include "el5_filekey_callback_stub.h"
20 #include "el5_filekey_manager_error.h"
21 #include "el5_filekey_manager_kit.h"
22 #include "token_setproc.h"
23
24 using namespace testing::ext;
25 using namespace OHOS::Security::AccessToken;
26
SetUpTestCase()27 void El5FilekeyManagerKitTest::SetUpTestCase()
28 {
29 }
30
TearDownTestCase()31 void El5FilekeyManagerKitTest::TearDownTestCase()
32 {
33 }
34
SetUp()35 void El5FilekeyManagerKitTest::SetUp()
36 {
37 }
38
TearDown()39 void El5FilekeyManagerKitTest::TearDown()
40 {
41 }
42
43 class TestEl5FilekeyCallback : public El5FilekeyCallbackStub {
44 public:
OnRegenerateAppKey(std::vector<AppKeyInfo> & infos)45 void OnRegenerateAppKey(std::vector<AppKeyInfo> &infos)
46 {
47 GTEST_LOG_(INFO) << "OnRegenerateAppKey.";
48 }
49 };
50
51 /**
52 * @tc.name: AcquireAccess001
53 * @tc.desc: Acquire media type data access without permission.
54 * @tc.type: FUNC
55 * @tc.require: issueI9JGMV
56 */
57 HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess001, TestSize.Level1)
58 {
59 DataLockType type = MEDIA_DATA;
60 ASSERT_EQ(El5FilekeyManagerKit::AcquireAccess(static_cast<DataLockType>(type)), EFM_ERR_NO_PERMISSION);
61 }
62
63 /**
64 * @tc.name: AcquireAccess002
65 * @tc.desc: Acquire all type data access without permission.
66 * @tc.type: FUNC
67 * @tc.require: issueI9JGMV
68 */
69 HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess002, TestSize.Level1)
70 {
71 DataLockType type = ALL_DATA;
72 ASSERT_EQ(El5FilekeyManagerKit::AcquireAccess(static_cast<DataLockType>(type)), EFM_ERR_NO_PERMISSION);
73 }
74
75 /**
76 * @tc.name: ReleaseAccess001
77 * @tc.desc: Release media type data access without permission.
78 * @tc.type: FUNC
79 * @tc.require: issueI9JGMV
80 */
81 HWTEST_F(El5FilekeyManagerKitTest, ReleaseAccess001, TestSize.Level1)
82 {
83 DataLockType type = MEDIA_DATA;
84 ASSERT_EQ(El5FilekeyManagerKit::ReleaseAccess(static_cast<DataLockType>(type)), EFM_ERR_NO_PERMISSION);
85 }
86
87 /**
88 * @tc.name: ReleaseAccess002
89 * @tc.desc: Release all type data access without permission.
90 * @tc.type: FUNC
91 * @tc.require: issueI9JGMV
92 */
93 HWTEST_F(El5FilekeyManagerKitTest, ReleaseAccess002, TestSize.Level1)
94 {
95 DataLockType type = ALL_DATA;
96 ASSERT_EQ(El5FilekeyManagerKit::ReleaseAccess(static_cast<DataLockType>(type)), EFM_ERR_NO_PERMISSION);
97 }
98
99 /**
100 * @tc.name: GenerateAppKey001
101 * @tc.desc: Generate app key by uid and bundle name without permission.
102 * @tc.type: FUNC
103 * @tc.require: issueI9JGMV
104 */
105 HWTEST_F(El5FilekeyManagerKitTest, GenerateAppKey001, TestSize.Level1)
106 {
107 int32_t uid = 10010;
108 std::string bundleName = "com.ohos.systemui";
109 std::string keyId;
110 ASSERT_EQ(El5FilekeyManagerKit::GenerateAppKey(uid, bundleName, keyId), EFM_ERR_NO_PERMISSION);
111 }
112
113 /**
114 * @tc.name: DeleteAppKey001
115 * @tc.desc: Delete app key by bundle name and user id without permission.
116 * @tc.type: FUNC
117 * @tc.require: issueI9JGMV
118 */
119 HWTEST_F(El5FilekeyManagerKitTest, DeleteAppKey001, TestSize.Level1)
120 {
121 std::string bundleName = "";
122 int32_t userId = 100;
123 ASSERT_EQ(El5FilekeyManagerKit::DeleteAppKey(bundleName, userId), EFM_ERR_NO_PERMISSION);
124 }
125
126 /**
127 * @tc.name: GetUserAppKey001
128 * @tc.desc: Find key infos of the specified user id without permission.
129 * @tc.type: FUNC
130 * @tc.require: issueI9JGMV
131 */
132 HWTEST_F(El5FilekeyManagerKitTest, GetUserAppKey001, TestSize.Level1)
133 {
134 int32_t userId = 100;
135 std::vector<std::pair<int32_t, std::string>> keyInfos;
136 ASSERT_EQ(El5FilekeyManagerKit::GetUserAppKey(userId, keyInfos), EFM_ERR_NO_PERMISSION);
137 }
138
139 /**
140 * @tc.name: ChangeUserAppkeysLoadInfo001
141 * @tc.desc: Change key infos of the specified user id without permission.
142 * @tc.type: FUNC
143 * @tc.require: issueI9JGMV
144 */
145 HWTEST_F(El5FilekeyManagerKitTest, ChangeUserAppkeysLoadInfo001, TestSize.Level1)
146 {
147 int32_t userId = 100;
148 std::vector<std::pair<std::string, bool>> loadInfos;
149 loadInfos.emplace_back(std::make_pair("", true));
150 ASSERT_EQ(El5FilekeyManagerKit::ChangeUserAppkeysLoadInfo(userId, loadInfos), EFM_ERR_NO_PERMISSION);
151 }
152
153 /**
154 * @tc.name: SetFilePathPolicy001
155 * @tc.desc: Set path policy without permission.
156 * @tc.type: FUNC
157 * @tc.require: issueI9Q6K2
158 */
159 HWTEST_F(El5FilekeyManagerKitTest, SetFilePathPolicy001, TestSize.Level1)
160 {
161 ASSERT_EQ(El5FilekeyManagerKit::SetFilePathPolicy(), EFM_ERR_NO_PERMISSION);
162 }
163
164 /**
165 * @tc.name: RegisterCallback001
166 * @tc.desc: Register app key generation callback without permission.
167 * @tc.type: FUNC
168 * @tc.require: issueI9Q6K2
169 */
170 HWTEST_F(El5FilekeyManagerKitTest, RegisterCallback001, TestSize.Level1)
171 {
172 ASSERT_NE(El5FilekeyManagerKit::RegisterCallback((new TestEl5FilekeyCallback())), EFM_SUCCESS);
173 }
174
175 /**
176 * @tc.name: GetUserAllAppKey001
177 * @tc.desc: GetUserAllAppKey function test without permission.
178 * @tc.type: FUNC
179 * @tc.require: issueI9Q6K2
180 */
181 HWTEST_F(El5FilekeyManagerKitTest, GetUserAllAppKey001, TestSize.Level1)
182 {
183 int32_t userId = 100;
184 std::vector<std::pair<int32_t, std::string>> keyInfos;
185 keyInfos.emplace_back(std::make_pair(100, ""));
186 ASSERT_EQ(El5FilekeyManagerKit::GetUserAllAppKey(userId, keyInfos), EFM_ERR_NO_PERMISSION);
187 }