1 /*
2 * Copyright (c) 2025 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 "dlp_file_operator_test.h"
17 #include <cstddef>
18 #include <cstdio>
19 #include <cstring>
20 #include <fcntl.h>
21 #include <openssl/rand.h>
22 #include "c_mock_common.h"
23 #include "nlohmann/json.hpp"
24 #define private public
25 #include "dlp_file_operator.h"
26 #undef private
27 #include "dlp_file_manager.h"
28 #include "dlp_permission.h"
29 #include "dlp_permission_log.h"
30
31 namespace OHOS {
32 namespace Security {
33 namespace DlpPermission {
34 using namespace testing::ext;
35 using namespace std;
36 using json = nlohmann::json;
37 namespace {
38 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpFileOperatorTest"};
39 static const std::string DLP_TEST_DIR = "/data/dlpOperatorTest/";
40
41 static const std::string ACCOUNT_INDEX = "account";
42 static const std::string ACCOUNT_TYPE = "accountType";
43 static const std::string EDIT_INDEX = "edit";
44 static const std::string ENC_ACCOUNT_TYPE = "accountType";
45 static const std::string EVERYONE_INDEX = "everyone";
46 static const std::string FC_INDEX = "fullCtrl";
47 static const std::string NEED_ONLINE = "needOnline";
48 static const std::string OWNER_ACCOUNT_NAME = "ownerAccountName";
49 static const std::string OWNER_ACCOUNT = "ownerAccount";
50 static const std::string OWNER_ACCOUNT_ID = "ownerAccountId";
51 static const std::string OWNER_ACCOUNT_TYPE = "ownerAccountType";
52 static const std::string AUTHUSER_LIST = "authUserList";
53 static const std::string CONTACT_ACCOUNT = "contactAccount";
54 static const std::string OFFLINE_ACCESS = "offlineAccess";
55 static const std::string EVERYONE_ACCESS_LIST = "everyoneAccessList";
56 static const std::string PERM_EXPIRY_TIME = "expireTime";
57 static const std::string ACTION_UPON_EXPIRY = "actionUponExpiry";
58 static const std::string POLICY_INDEX = "policy";
59 static const std::string READ_INDEX = "read";
60 static const std::string RIGHT_INDEX = "right";
61 static const std::string CUSTOM_PROPERTY = "customProperty";
62
63 static const std::string DEFAULT_CURRENT_ACCOUNT = "ohosAnonymousName";
64 static const std::string DEFAULT_CUSTOM_PROPERTY = "customProperty";
65 static const uint8_t ARRAY_CHAR_SIZE = 62;
66 static const char CHAR_ARRAY[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
67 static const int32_t RAND_STR_SIZE = 16;
68 static int g_plainFileFd = -1;
69 static int g_dlpFileFd = -1;
70 static int g_recoverFileFd = -1;
71 static const int INVALID_FD = -1;
72 constexpr uint64_t VALID_TIME_STAMP = 2147483647;
73
74 static const char TEST_FILE[] = "/data/dlpOperatorTest/file_test.txt";
75 static const char TEST_FILE_1[] = "/data/dlpOperatorTest/file_test_1.txt";
76 static const char DLP_FILE[] = "/data/dlpOperatorTest/file_test.txt.dlp";
77 }
78
SetUpTestCase()79 void DlpFileOperatorTest::SetUpTestCase()
80 {
81 struct stat fstat;
82 if (stat(DLP_TEST_DIR.c_str(), &fstat) != 0) {
83 if (errno == ENOENT) {
84 int32_t ret = mkdir(DLP_TEST_DIR.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
85 if (ret < 0) {
86 DLP_LOG_ERROR(LABEL, "mkdir mount point failed errno %{public}d", errno);
87 return;
88 }
89 } else {
90 DLP_LOG_ERROR(LABEL, "get mount point failed errno %{public}d", errno);
91 return;
92 }
93 }
94 }
95
TearDownTestCase()96 void DlpFileOperatorTest::TearDownTestCase()
97 {
98 rmdir(DLP_TEST_DIR.c_str());
99 }
100
SetUp()101 void DlpFileOperatorTest::SetUp() {}
102
TearDown()103 void DlpFileOperatorTest::TearDown() {}
104
105 namespace {
GetRandNum()106 static uint8_t GetRandNum()
107 {
108 uint8_t rand;
109 RAND_bytes(reinterpret_cast<unsigned char *>(&rand), sizeof(rand));
110 return rand;
111 }
112
GenerateRandStr(uint32_t len,std::string & res)113 static void GenerateRandStr(uint32_t len, std::string& res)
114 {
115 for (uint32_t i = 0; i < len; i++) {
116 uint32_t index = GetRandNum() % ARRAY_CHAR_SIZE;
117 DLP_LOG_INFO(LABEL, "%{public}u", index);
118 res.push_back(CHAR_ARRAY[index]);
119 }
120 DLP_LOG_INFO(LABEL, "%{public}s", res.c_str());
121 }
122
DeserializeEveryoneInfo(const json & policyJson,PermissionPolicy & policy)123 static bool DeserializeEveryoneInfo(const json& policyJson, PermissionPolicy& policy)
124 {
125 if (policyJson.find(EVERYONE_INDEX) == policyJson.end() || !policyJson.at(EVERYONE_INDEX).is_object()) {
126 return false;
127 }
128
129 policy.supportEveryone_ = true;
130 json everyoneInfoJson;
131 policyJson.at(EVERYONE_INDEX).get_to(everyoneInfoJson);
132
133 json rightInfoJson;
134 if (everyoneInfoJson.find(RIGHT_INDEX) == everyoneInfoJson.end() ||
135 !everyoneInfoJson.at(RIGHT_INDEX).is_object()) {
136 return false;
137 }
138 everyoneInfoJson.at(RIGHT_INDEX).get_to(rightInfoJson);
139
140 bool edit = false;
141 bool fullCtrl = false;
142
143 if (rightInfoJson.find(EDIT_INDEX) != rightInfoJson.end() && rightInfoJson.at(EDIT_INDEX).is_boolean()) {
144 rightInfoJson.at(EDIT_INDEX).get_to(edit);
145 }
146
147 if (rightInfoJson.find(FC_INDEX) != rightInfoJson.end() && rightInfoJson.at(FC_INDEX).is_boolean()) {
148 rightInfoJson.at(FC_INDEX).get_to(fullCtrl);
149 }
150
151 if (fullCtrl) {
152 policy.everyonePerm_ = DLPFileAccess::FULL_CONTROL;
153 } else if (edit) {
154 policy.everyonePerm_ = DLPFileAccess::CONTENT_EDIT;
155 } else {
156 policy.everyonePerm_ = DLPFileAccess::READ_ONLY;
157 }
158 return true;
159 }
160
DeserializeAuthUserInfo(const json & accountInfoJson,AuthUserInfo & userInfo)161 static int32_t DeserializeAuthUserInfo(const json& accountInfoJson, AuthUserInfo& userInfo)
162 {
163 json rightInfoJson;
164 if (accountInfoJson.find(RIGHT_INDEX) != accountInfoJson.end() && accountInfoJson.at(RIGHT_INDEX).is_object()) {
165 accountInfoJson.at(RIGHT_INDEX).get_to(rightInfoJson);
166 }
167
168 bool edit = false;
169 bool fullCtrl = false;
170
171 if (rightInfoJson.find(EDIT_INDEX) != rightInfoJson.end() && rightInfoJson.at(EDIT_INDEX).is_boolean()) {
172 rightInfoJson.at(EDIT_INDEX).get_to(edit);
173 }
174
175 if (rightInfoJson.find(FC_INDEX) != rightInfoJson.end() && rightInfoJson.at(FC_INDEX).is_boolean()) {
176 rightInfoJson.at(FC_INDEX).get_to(fullCtrl);
177 }
178
179 if (fullCtrl) {
180 userInfo.authPerm = DLPFileAccess::FULL_CONTROL;
181 } else if (edit) {
182 userInfo.authPerm = DLPFileAccess::CONTENT_EDIT;
183 } else {
184 userInfo.authPerm = DLPFileAccess::READ_ONLY;
185 }
186
187 userInfo.permExpiryTime = VALID_TIME_STAMP;
188 userInfo.authAccountType = CLOUD_ACCOUNT;
189
190 return DLP_OK;
191 }
192
DeserializeAuthUserList(const json & authUsersJson,std::vector<AuthUserInfo> & userList)193 static int32_t DeserializeAuthUserList(const json& authUsersJson, std::vector<AuthUserInfo>& userList)
194 {
195 for (auto iter = authUsersJson.begin(); iter != authUsersJson.end(); ++iter) {
196 AuthUserInfo authInfo;
197 std::string name = iter.key();
198 authInfo.authAccount = name;
199 json accountInfo = iter.value();
200 int32_t res = DeserializeAuthUserInfo(accountInfo, authInfo);
201 if (res == DLP_OK) {
202 userList.emplace_back(authInfo);
203 } else {
204 userList.clear();
205 return res;
206 }
207 }
208 return DLP_OK;
209 }
210
DeserializeDlpPermission(const std::string & queryResult,PermissionPolicy & policy)211 static uint32_t DeserializeDlpPermission(const std::string& queryResult, PermissionPolicy& policy)
212 {
213 if (!json::accept(queryResult)) {
214 return DLP_SERVICE_ERROR_JSON_OPERATE_FAIL;
215 }
216 json policyJson = json::parse(queryResult);
217 if (policyJson.find(OWNER_ACCOUNT_NAME) != policyJson.end() && policyJson.at(OWNER_ACCOUNT_NAME).is_string()) {
218 policyJson.at(OWNER_ACCOUNT_NAME).get_to(policy.ownerAccount_);
219 }
220 if (policyJson.find(OWNER_ACCOUNT_ID) != policyJson.end() && policyJson.at(OWNER_ACCOUNT_ID).is_string()) {
221 policyJson.at(OWNER_ACCOUNT_ID).get_to(policy.ownerAccountId_);
222 }
223 if (policyJson.find(PERM_EXPIRY_TIME) != policyJson.end() && policyJson.at(PERM_EXPIRY_TIME).is_number()) {
224 policyJson.at(PERM_EXPIRY_TIME).get_to(policy.expireTime_);
225 }
226 if (policyJson.find(ACTION_UPON_EXPIRY) != policyJson.end() && policyJson.at(ACTION_UPON_EXPIRY).is_number()) {
227 policyJson.at(ACTION_UPON_EXPIRY).get_to(policy.actionUponExpiry_);
228 }
229 if (policyJson.find(NEED_ONLINE) != policyJson.end() && policyJson.at(NEED_ONLINE).is_number()) {
230 policyJson.at(NEED_ONLINE).get_to(policy.needOnline_);
231 }
232 if (policyJson.find(CUSTOM_PROPERTY) != policyJson.end() && policyJson.at(CUSTOM_PROPERTY).is_string()) {
233 policyJson.at(CUSTOM_PROPERTY).get_to(policy.customProperty_);
234 }
235 json accountListJson;
236 if (policyJson.find(ACCOUNT_INDEX) != policyJson.end() && policyJson.at(ACCOUNT_INDEX).is_object()) {
237 policyJson.at(ACCOUNT_INDEX).get_to(accountListJson);
238 }
239 DeserializeEveryoneInfo(policyJson, policy);
240
241 std::vector<AuthUserInfo> userList;
242 if (DeserializeAuthUserList(accountListJson, userList) != DLP_OK) {
243 return DLP_SERVICE_ERROR_JSON_OPERATE_FAIL;
244 }
245 policy.authUsers_ = userList;
246 return DLP_OK;
247 }
248
IsSameAuthInfo(const std::vector<AuthUserInfo> & info1,const std::vector<AuthUserInfo> & info2)249 static bool IsSameAuthInfo(const std::vector<AuthUserInfo>& info1, const std::vector<AuthUserInfo>& info2)
250 {
251 if (info1.size() != info2.size()) {
252 return false;
253 }
254 for (auto auth1 : info1) {
255 for (auto auth2 : info2) {
256 if (auth1.authAccount != auth2.authAccount) {
257 continue;
258 }
259 if (auth1.authPerm != auth2.authPerm) {
260 return false;
261 }
262 break;
263 }
264 }
265 return true;
266 }
267
IsSameProperty(const PermissionPolicy & property,const PermissionPolicy & queryProperty)268 static bool IsSameProperty(const PermissionPolicy& property, const PermissionPolicy& queryProperty)
269 {
270 return property.ownerAccount_ == queryProperty.ownerAccount_ &&
271 property.ownerAccountId_ == queryProperty.ownerAccountId_ &&
272 property.expireTime_ == queryProperty.expireTime_ &&
273 property.needOnline_ == queryProperty.needOnline_ &&
274 property.actionUponExpiry_ == queryProperty.actionUponExpiry_ &&
275 IsSameAuthInfo(property.authUsers_, queryProperty.authUsers_);
276 }
277
278 }
279
280
281 /**
282 * @tc.name: EnterpriseSpaceEncryptDlpFile001
283 * @tc.desc: test dlp file generate in Enterprise space
284 * @tc.type: FUNC
285 * @tc.require:
286 */
287 HWTEST_F(DlpFileOperatorTest, EnterpriseSpaceEncryptDlpFile001, TestSize.Level0)
288 {
289 DLP_LOG_INFO(LABEL, "EnterpriseSpaceEncryptDlpFile001");
290
291 g_plainFileFd = open(TEST_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
292 g_dlpFileFd = open(DLP_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
293 ASSERT_GE(g_plainFileFd, 0);
294 ASSERT_GE(g_dlpFileFd, 0);
295
296 char buffer[] = "123456";
297 ASSERT_NE(write(g_plainFileFd, buffer, sizeof(buffer)), -1);
298 std::string accountName;
299 GenerateRandStr(RAND_STR_SIZE, accountName);
300
301 DlpProperty property = {
302 .ownerAccount = DEFAULT_CURRENT_ACCOUNT,
303 .ownerAccountId = DEFAULT_CURRENT_ACCOUNT,
304 .contactAccount = accountName,
305 .ownerAccountType = CLOUD_ACCOUNT,
306 .offlineAccess = false,
307 .supportEveryone = false,
308 .everyonePerm = DLPFileAccess::NO_PERMISSION,
309 .expireTime = 0,
310 .actionUponExpiry = ActionType::NOTOPEN
311 };
312 CustomProperty customProperty = {
313 .enterprise = DEFAULT_CUSTOM_PROPERTY
314 };
315
316 int32_t result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
317 customProperty, INVALID_FD, g_dlpFileFd);
318 EXPECT_EQ(DLP_PARSE_ERROR_FD_ERROR, result);
319 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
320 customProperty, g_plainFileFd, INVALID_FD);
321 EXPECT_EQ(DLP_PARSE_ERROR_FD_ERROR, result);
322 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
323 customProperty, g_plainFileFd, g_dlpFileFd);
324 EXPECT_EQ(DLP_OK, result);
325 customProperty.enterprise = "";
326 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
327 customProperty, g_plainFileFd, g_dlpFileFd);
328 EXPECT_EQ(DLP_OK, result);
329 close(g_plainFileFd);
330 close(g_dlpFileFd);
331 }
332
333 /**
334 * @tc.name: EnterpriseSpaceDecryptDlpFile001
335 * @tc.desc: test decrypt dlp file in Enterprise space
336 * @tc.type: FUNC
337 * @tc.require:
338 */
339 HWTEST_F(DlpFileOperatorTest, EnterpriseSpaceDecryptDlpFile001, TestSize.Level0)
340 {
341 DLP_LOG_INFO(LABEL, "EnterpriseSpaceDecryptDlpFile001");
342
343 g_plainFileFd = open(TEST_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
344 g_dlpFileFd = open(DLP_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
345 ASSERT_GE(g_plainFileFd, 0);
346 ASSERT_GE(g_dlpFileFd, 0);
347
348 char buffer[] = "123456";
349 ASSERT_NE(write(g_plainFileFd, buffer, sizeof(buffer)), -1);
350 std::string accountName;
351 GenerateRandStr(RAND_STR_SIZE, accountName);
352
353 DlpProperty property = {
354 .ownerAccount = DEFAULT_CURRENT_ACCOUNT,
355 .ownerAccountId = DEFAULT_CURRENT_ACCOUNT,
356 .contactAccount = accountName,
357 .ownerAccountType = CLOUD_ACCOUNT,
358 .offlineAccess = false,
359 .supportEveryone = false,
360 .everyonePerm = DLPFileAccess::NO_PERMISSION,
361 .expireTime = 0,
362 .actionUponExpiry = ActionType::NOTOPEN
363 };
364 CustomProperty customProperty = {
365 .enterprise = DEFAULT_CUSTOM_PROPERTY
366 };
367
368 int32_t result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
369 customProperty, g_plainFileFd, g_dlpFileFd);
370 EXPECT_EQ(DLP_OK, result);
371 close(g_plainFileFd);
372
373 g_plainFileFd = open(TEST_FILE_1, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
374 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->DecryptDlpFile(INVALID_FD, g_dlpFileFd);
375 EXPECT_EQ(DLP_PARSE_ERROR_FD_ERROR, result);
376 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->DecryptDlpFile(g_plainFileFd, INVALID_FD);
377 EXPECT_EQ(DLP_PARSE_ERROR_FD_ERROR, result);
378
379 std::shared_ptr<DlpFile> filePtr = nullptr;
380 std::string workDir;
381 result = EnterpriseSpaceDlpPermissionKit::GetInstance()
382 ->EnterpriseSpacePrepareWorkDir(g_dlpFileFd, filePtr, workDir);
383 EXPECT_EQ(DLP_OK, result);
384
385 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EnterpriseSpaceParseDlpFileFormat(filePtr, false);
386 EXPECT_EQ(DLP_OK, result);
387
388 filePtr->authPerm_ = DLPFileAccess::FULL_CONTROL;
389 result = DlpFileManager::GetInstance().RecoverDlpFile(filePtr, g_plainFileFd);
390 EXPECT_EQ(DLP_OK, result);
391 close(g_dlpFileFd);
392 close(g_plainFileFd);
393 }
394
395 /**
396 * @tc.name: EnterpriseSpaceQueryDlpProperty001
397 * @tc.desc: test dlp file generate in Enterprise space
398 * @tc.type: FUNC
399 * @tc.require:
400 */
401 HWTEST_F(DlpFileOperatorTest, EnterpriseSpaceQueryDlpProperty001, TestSize.Level0)
402 {
403 DLP_LOG_INFO(LABEL, "EnterpriseSpaceQueryDlpProperty001");
404
405 g_plainFileFd = open(TEST_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
406 g_dlpFileFd = open(DLP_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
407 ASSERT_GE(g_plainFileFd, 0);
408 ASSERT_GE(g_dlpFileFd, 0);
409
410 char buffer[] = "123456";
411 ASSERT_NE(write(g_plainFileFd, buffer, sizeof(buffer)), -1);
412 std::string accountName;
413 GenerateRandStr(RAND_STR_SIZE, accountName);
414
415 DlpProperty property = {
416 .ownerAccount = DEFAULT_CURRENT_ACCOUNT,
417 .ownerAccountId = DEFAULT_CURRENT_ACCOUNT,
418 .contactAccount = accountName,
419 .ownerAccountType = CLOUD_ACCOUNT,
420 .offlineAccess = false,
421 .supportEveryone = false,
422 .everyonePerm = DLPFileAccess::NO_PERMISSION,
423 .expireTime = 0,
424 .actionUponExpiry = ActionType::NOTOPEN
425 };
426 CustomProperty customProperty = {
427 .enterprise = DEFAULT_CUSTOM_PROPERTY
428 };
429
430 int32_t result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
431 customProperty, g_plainFileFd, g_dlpFileFd);
432 EXPECT_EQ(DLP_OK, result);
433 close(g_plainFileFd);
434 close(g_dlpFileFd);
435 g_dlpFileFd = open(DLP_FILE, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
436 ASSERT_GE(g_dlpFileFd, 0);
437
438 std::string queryResult;
439 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->QueryDlpFileProperty(INVALID_FD, queryResult);
440 EXPECT_EQ(DLP_PARSE_ERROR_FD_ERROR, result);
441 close(g_dlpFileFd);
442 }
443
444 /**
445 * @tc.name: EnterpriseSpaceQueryDlpProperty002
446 * @tc.desc: test dlp file generate in Enterprise space
447 * @tc.type: FUNC
448 * @tc.require:
449 */
450 HWTEST_F(DlpFileOperatorTest, EnterpriseSpaceQueryDlpProperty002, TestSize.Level0)
451 {
452 DLP_LOG_INFO(LABEL, "EnterpriseSpaceQueryDlpProperty002");
453
454 g_plainFileFd = open(TEST_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
455 g_dlpFileFd = open(DLP_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
456 ASSERT_GE(g_plainFileFd, 0);
457 ASSERT_GE(g_dlpFileFd, 0);
458
459 char buffer[] = "123456";
460 ASSERT_NE(write(g_plainFileFd, buffer, sizeof(buffer)), -1);
461 std::string accountName;
462 GenerateRandStr(RAND_STR_SIZE, accountName);
463
464 DlpProperty property = {
465 .ownerAccount = DEFAULT_CURRENT_ACCOUNT,
466 .ownerAccountId = DEFAULT_CURRENT_ACCOUNT,
467 .contactAccount = accountName,
468 .ownerAccountType = CLOUD_ACCOUNT,
469 .offlineAccess = false,
470 .supportEveryone = false,
471 .everyonePerm = DLPFileAccess::NO_PERMISSION,
472 .expireTime = 0,
473 .actionUponExpiry = ActionType::NOTOPEN
474 };
475 CustomProperty customProperty = {
476 .enterprise = DEFAULT_CUSTOM_PROPERTY
477 };
478
479 int32_t result = EnterpriseSpaceDlpPermissionKit::GetInstance()->EncryptDlpFile(property,
480 customProperty, g_plainFileFd, g_dlpFileFd);
481 EXPECT_EQ(DLP_OK, result);
482 close(g_plainFileFd);
483 close(g_dlpFileFd);
484 g_dlpFileFd = open(DLP_FILE, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
485 ASSERT_GE(g_dlpFileFd, 0);
486
487 std::string resultStr;
488 result = EnterpriseSpaceDlpPermissionKit::GetInstance()->QueryDlpFileProperty(g_dlpFileFd, resultStr);
489 EXPECT_EQ(DLP_OK, result);
490 PermissionPolicy resultPolicy;
491 result = DeserializeDlpPermission(resultStr, resultPolicy);
492 EXPECT_EQ(DLP_OK, result);
493 PermissionPolicy inputPolicy(property);
494 bool res = IsSameProperty(inputPolicy, resultPolicy);
495 EXPECT_EQ(res, true);
496 close(g_dlpFileFd);
497 }
498
499 } // namespace DlpPermission
500 } // namespace Security
501 } // namespace OHOS