1f6603c60Sopenharmony_ci/**
2f6603c60Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *   http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "ActsPMSTest.h"
17f6603c60Sopenharmony_ci
18f6603c60Sopenharmony_ciusing namespace std;
19f6603c60Sopenharmony_ciusing namespace testing::ext;
20f6603c60Sopenharmony_ci
21f6603c60Sopenharmony_cistatic PmsInnerApi *g_interface;
22f6603c60Sopenharmony_cistatic PermissionTrans g_systemPers[] = {
23f6603c60Sopenharmony_ci    {
24f6603c60Sopenharmony_ci        "ohos.permission.CAMERA",
25f6603c60Sopenharmony_ci        "for CAMERA use",
26f6603c60Sopenharmony_ci        INUSE,
27f6603c60Sopenharmony_ci    },
28f6603c60Sopenharmony_ci    {
29f6603c60Sopenharmony_ci        "ohos.permission.RECORD_AUDIO",
30f6603c60Sopenharmony_ci        "for RECORD_AUDIO use",
31f6603c60Sopenharmony_ci        ALWAYS,
32f6603c60Sopenharmony_ci    },
33f6603c60Sopenharmony_ci    {
34f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_AUDIO",
35f6603c60Sopenharmony_ci        "for READ_MEDIA_AUDIO use",
36f6603c60Sopenharmony_ci        INUSE,
37f6603c60Sopenharmony_ci    },
38f6603c60Sopenharmony_ci    {
39f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_IMAGES",
40f6603c60Sopenharmony_ci        "for READ_MEDIA_IMAGES use",
41f6603c60Sopenharmony_ci        ALWAYS,
42f6603c60Sopenharmony_ci    },
43f6603c60Sopenharmony_ci    {
44f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_VIDEO",
45f6603c60Sopenharmony_ci        "for READ_MEDIA_VIDEO use",
46f6603c60Sopenharmony_ci        INUSE,
47f6603c60Sopenharmony_ci    },
48f6603c60Sopenharmony_ci    {
49f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_AUDIO",
50f6603c60Sopenharmony_ci        "for WRITE_MEDIA_AUDIO use",
51f6603c60Sopenharmony_ci        ALWAYS,
52f6603c60Sopenharmony_ci    },
53f6603c60Sopenharmony_ci    {
54f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_IMAGES",
55f6603c60Sopenharmony_ci        "for WRITE_MEDIA_IMAGES use",
56f6603c60Sopenharmony_ci        INUSE,
57f6603c60Sopenharmony_ci    },
58f6603c60Sopenharmony_ci    {
59f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_VIDEO",
60f6603c60Sopenharmony_ci        "for WRITE_MEDIA_VIDEO use",
61f6603c60Sopenharmony_ci        ALWAYS,
62f6603c60Sopenharmony_ci    },
63f6603c60Sopenharmony_ci    {
64f6603c60Sopenharmony_ci        "ohos.permission.MODIFY_AUDIO_SETTINGS",
65f6603c60Sopenharmony_ci        "for MODIFY_AUDIO_SETTINGS use",
66f6603c60Sopenharmony_ci        INUSE,
67f6603c60Sopenharmony_ci    },
68f6603c60Sopenharmony_ci};
69f6603c60Sopenharmony_ci
70f6603c60Sopenharmony_ciclass ActsPMSDeleteTest : public testing::Test {
71f6603c60Sopenharmony_ciprotected:
72f6603c60Sopenharmony_ci    static void SetUpTestCase(void)
73f6603c60Sopenharmony_ci    {
74f6603c60Sopenharmony_ci        CreateAppDir();
75f6603c60Sopenharmony_ci        IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(PERMISSION_SERVICE, PERM_INNER);
76f6603c60Sopenharmony_ci        iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **) &g_interface);
77f6603c60Sopenharmony_ci        setuid(0);
78f6603c60Sopenharmony_ci    }
79f6603c60Sopenharmony_ci    static void TearDownTestCase(void) {}
80f6603c60Sopenharmony_ci    virtual void SetUp() {}
81f6603c60Sopenharmony_ci    virtual void TearDown()
82f6603c60Sopenharmony_ci    {
83f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID);
84f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID2);
85f6603c60Sopenharmony_ci        DeletePermissions(SUBTEST_APP_ID);
86f6603c60Sopenharmony_ci        UnLoadPermissions(TEST_TASKID);
87f6603c60Sopenharmony_ci        UnLoadPermissions(SUBTEST_TASKID);
88f6603c60Sopenharmony_ci    }
89f6603c60Sopenharmony_ci};
90f6603c60Sopenharmony_ci
91f6603c60Sopenharmony_ci/**
92f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0200
93f6603c60Sopenharmony_ci * @tc.name       The application is unloaded and the permission data is deleted
94f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
95f6603c60Sopenharmony_ci */
96f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0200, Function | MediumTest | Level0)
97f6603c60Sopenharmony_ci{
98f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
99f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
100f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
101f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
102f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
103f6603c60Sopenharmony_ci}
104f6603c60Sopenharmony_ci
105f6603c60Sopenharmony_ci/**
106f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0210
107f6603c60Sopenharmony_ci * @tc.name       Unload unknown applications
108f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
109f6603c60Sopenharmony_ci */
110f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0210, Function | MediumTest | Level2)
111f6603c60Sopenharmony_ci{
112f6603c60Sopenharmony_ci    int ret = DeletePermissions(TEST_APP_ID);
113f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
114f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
115f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
116f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
117f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
118f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
119f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
120f6603c60Sopenharmony_ci}
121f6603c60Sopenharmony_ci
122f6603c60Sopenharmony_ci/**
123f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0230
124f6603c60Sopenharmony_ci * @tc.name       Delete multiple application permissions
125f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
126f6603c60Sopenharmony_ci */
127f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0230, Function | MediumTest | Level3)
128f6603c60Sopenharmony_ci{
129f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
130f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
131f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID2, g_systemPers, 0, FIRST_INSTALL);
132f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
133f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
134f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
135f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID2);
136f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
137f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
138f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID2, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
139f6603c60Sopenharmony_ci}
140f6603c60Sopenharmony_ci
141f6603c60Sopenharmony_ci/**
142f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0250
143f6603c60Sopenharmony_ci * @tc.name       After the application permissions are loaded, the permissions can be deleted
144f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
145f6603c60Sopenharmony_ci */
146f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0250, Function | MediumTest | Level3)
147f6603c60Sopenharmony_ci{
148f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
149f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
150f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
151f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
152f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
153f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
154f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
155f6603c60Sopenharmony_ci    ret = UnLoadPermissions(TEST_TASKID);
156f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "unload ret = " << ret << endl;
157f6603c60Sopenharmony_ci}
158f6603c60Sopenharmony_ci
159f6603c60Sopenharmony_ci/**
160f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0260
161f6603c60Sopenharmony_ci * @tc.name       After the application permissions are unloaded, the permissions can be deleted
162f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
163f6603c60Sopenharmony_ci */
164f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0260, Function | MediumTest | Level2)
165f6603c60Sopenharmony_ci{
166f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
167f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
168f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
169f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
170f6603c60Sopenharmony_ci    ret = UnLoadPermissions(TEST_TASKID);
171f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "unload ret = " << ret << endl;
172f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
173f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
174f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
175f6603c60Sopenharmony_ci}
176f6603c60Sopenharmony_ci
177f6603c60Sopenharmony_ci/**
178f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0270
179f6603c60Sopenharmony_ci * @tc.name       After the application permissions are checked, the permissions can be deleted
180f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
181f6603c60Sopenharmony_ci */
182f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0270, Function | MediumTest | Level2)
183f6603c60Sopenharmony_ci{
184f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
185f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
186f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
187f6603c60Sopenharmony_ci        g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
188f6603c60Sopenharmony_ci    }
189f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
190f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
191f6603c60Sopenharmony_ci    ret = CheckPermission(TEST_TASKID, g_systemPers[0].name);
192f6603c60Sopenharmony_ci    EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl;
193f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
194f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
195f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
196f6603c60Sopenharmony_ci    ret = UnLoadPermissions(TEST_TASKID);
197f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "unload ret = " << ret << endl;
198f6603c60Sopenharmony_ci}
199f6603c60Sopenharmony_ci
200f6603c60Sopenharmony_ci/**
201f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0280
202f6603c60Sopenharmony_ci * @tc.name       After the application permissions are queryed, the permissions can be deleted
203f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
204f6603c60Sopenharmony_ci */
205f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0280, Function | MediumTest | Level4)
206f6603c60Sopenharmony_ci{
207f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
208f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
209f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
210f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
211f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
212f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
213f6603c60Sopenharmony_ci}
214f6603c60Sopenharmony_ci
215f6603c60Sopenharmony_ci/**
216f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0290
217f6603c60Sopenharmony_ci * @tc.name       After the application permissions are granted, the permissions can be deleted
218f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
219f6603c60Sopenharmony_ci */
220f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0290, Function | MediumTest | Level2)
221f6603c60Sopenharmony_ci{
222f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
223f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
224f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
225f6603c60Sopenharmony_ci        ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
226f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "grant ret = " << ret << endl;
227f6603c60Sopenharmony_ci    }
228f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
229f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
230f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
231f6603c60Sopenharmony_ci}
232f6603c60Sopenharmony_ci
233f6603c60Sopenharmony_ci/**
234f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0300
235f6603c60Sopenharmony_ci * @tc.name       After the application permissions are revoked, the permissions can be deleted
236f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
237f6603c60Sopenharmony_ci */
238f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0300, Function | MediumTest | Level2)
239f6603c60Sopenharmony_ci{
240f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
241f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
242f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
243f6603c60Sopenharmony_ci        ret = g_interface->RevokePermission(TEST_APP_ID, g_systemPers[i].name);
244f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "revoke ret = " << ret << endl;
245f6603c60Sopenharmony_ci    }
246f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
247f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
248f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
249f6603c60Sopenharmony_ci}
250f6603c60Sopenharmony_ci
251f6603c60Sopenharmony_ci/**
252f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0310
253f6603c60Sopenharmony_ci * @tc.name       Another application permission change does not affect delete permission
254f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
255f6603c60Sopenharmony_ci */
256f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0310, Function | MediumTest | Level3)
257f6603c60Sopenharmony_ci{
258f6603c60Sopenharmony_ci    int pid = fork();
259f6603c60Sopenharmony_ci    int status = 0;
260f6603c60Sopenharmony_ci    if (pid != 0) {
261f6603c60Sopenharmony_ci        SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
262f6603c60Sopenharmony_ci        int ret = DeletePermissions(TEST_APP_ID);
263f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
264f6603c60Sopenharmony_ci        waitpid(pid, &status, 0);
265f6603c60Sopenharmony_ci    } else {
266f6603c60Sopenharmony_ci        SubTestWithoutCheck(SUBTEST_APP_ID, SUBTEST_TASKID);
267f6603c60Sopenharmony_ci        exit(0);
268f6603c60Sopenharmony_ci    }
269f6603c60Sopenharmony_ci}
270f6603c60Sopenharmony_ci
271f6603c60Sopenharmony_ci/**
272f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0420
273f6603c60Sopenharmony_ci * @tc.name       The permission file is abnormal and can be deleted
274f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
275f6603c60Sopenharmony_ci */
276f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0420, Function | MediumTest | Level4)
277f6603c60Sopenharmony_ci{
278f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
279f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
280f6603c60Sopenharmony_ci    int fd = access(TEST_APP_PATH, F_OK);
281f6603c60Sopenharmony_ci    if (fd == 0) {
282f6603c60Sopenharmony_ci        unlink(TEST_APP_PATH);
283f6603c60Sopenharmony_ci    }
284f6603c60Sopenharmony_ci    fd = open(TEST_APP_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
285f6603c60Sopenharmony_ci    if (fd >= 0) {
286f6603c60Sopenharmony_ci        write(fd, PERMISSION_UNSUPPORTED, strlen(PERMISSION_UNSUPPORTED));
287f6603c60Sopenharmony_ci        close(fd);
288f6603c60Sopenharmony_ci    }
289f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
290f6603c60Sopenharmony_ci    fd = open(TEST_APP_PATH, O_RDONLY);
291f6603c60Sopenharmony_ci    EXPECT_LT(fd, 0);
292f6603c60Sopenharmony_ci}
293f6603c60Sopenharmony_ci
294f6603c60Sopenharmony_ci/**
295f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0500
296f6603c60Sopenharmony_ci * @tc.name       Can delete application permission with long and short package names
297f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0800]
298f6603c60Sopenharmony_ci */
299f6603c60Sopenharmony_ciHWTEST_F(ActsPMSDeleteTest, testSecPMPMS_0500, Function | MediumTest | Level2)
300f6603c60Sopenharmony_ci{
301f6603c60Sopenharmony_ci    SaveOrUpdatePermissions(TEST_APP_SHORT, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
302f6603c60Sopenharmony_ci    SaveOrUpdatePermissions(TEST_APP_LONG, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
303f6603c60Sopenharmony_ci    int ret = DeletePermissions(TEST_APP_SHORT);
304f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
305f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_LONG);
306f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
307f6603c60Sopenharmony_ci}