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_unNormalPers[] = {
23f6603c60Sopenharmony_ci    {
24f6603c60Sopenharmony_ci        PERMISSION_TOOLONG,
25f6603c60Sopenharmony_ci        "abnormal permission",
26f6603c60Sopenharmony_ci        INUSE,
27f6603c60Sopenharmony_ci    },
28f6603c60Sopenharmony_ci    {
29f6603c60Sopenharmony_ci        PERMISSION_EMPTY,
30f6603c60Sopenharmony_ci        "abnormal permission",
31f6603c60Sopenharmony_ci        INUSE,
32f6603c60Sopenharmony_ci    },
33f6603c60Sopenharmony_ci    {
34f6603c60Sopenharmony_ci        PERMISSION_UNSUPPORTED,
35f6603c60Sopenharmony_ci        "abnormal permission",
36f6603c60Sopenharmony_ci        INUSE,
37f6603c60Sopenharmony_ci    },
38f6603c60Sopenharmony_ci};
39f6603c60Sopenharmony_cistatic PermissionTrans g_systemPers[] = {
40f6603c60Sopenharmony_ci    {
41f6603c60Sopenharmony_ci        "ohos.permission.CAMERA",
42f6603c60Sopenharmony_ci        "for CAMERA use",
43f6603c60Sopenharmony_ci        INUSE,
44f6603c60Sopenharmony_ci    },
45f6603c60Sopenharmony_ci    {
46f6603c60Sopenharmony_ci        "ohos.permission.RECORD_AUDIO",
47f6603c60Sopenharmony_ci        "for RECORD_AUDIO use",
48f6603c60Sopenharmony_ci        ALWAYS,
49f6603c60Sopenharmony_ci    },
50f6603c60Sopenharmony_ci    {
51f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_AUDIO",
52f6603c60Sopenharmony_ci        "for READ_MEDIA_AUDIO use",
53f6603c60Sopenharmony_ci        INUSE,
54f6603c60Sopenharmony_ci    },
55f6603c60Sopenharmony_ci    {
56f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_IMAGES",
57f6603c60Sopenharmony_ci        "for READ_MEDIA_IMAGES use",
58f6603c60Sopenharmony_ci        ALWAYS,
59f6603c60Sopenharmony_ci    },
60f6603c60Sopenharmony_ci    {
61f6603c60Sopenharmony_ci        "ohos.permission.READ_MEDIA_VIDEO",
62f6603c60Sopenharmony_ci        "for READ_MEDIA_VIDEO use",
63f6603c60Sopenharmony_ci        INUSE,
64f6603c60Sopenharmony_ci    },
65f6603c60Sopenharmony_ci    {
66f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_AUDIO",
67f6603c60Sopenharmony_ci        "for WRITE_MEDIA_AUDIO use",
68f6603c60Sopenharmony_ci        ALWAYS,
69f6603c60Sopenharmony_ci    },
70f6603c60Sopenharmony_ci    {
71f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_IMAGES",
72f6603c60Sopenharmony_ci        "for WRITE_MEDIA_IMAGES use",
73f6603c60Sopenharmony_ci        INUSE,
74f6603c60Sopenharmony_ci    },
75f6603c60Sopenharmony_ci    {
76f6603c60Sopenharmony_ci        "ohos.permission.WRITE_MEDIA_VIDEO",
77f6603c60Sopenharmony_ci        "for WRITE_MEDIA_VIDEO use",
78f6603c60Sopenharmony_ci        ALWAYS,
79f6603c60Sopenharmony_ci    },
80f6603c60Sopenharmony_ci    {
81f6603c60Sopenharmony_ci        "ohos.permission.MODIFY_AUDIO_SETTINGS",
82f6603c60Sopenharmony_ci        "for MODIFY_AUDIO_SETTINGS use",
83f6603c60Sopenharmony_ci        INUSE,
84f6603c60Sopenharmony_ci    },
85f6603c60Sopenharmony_ci};
86f6603c60Sopenharmony_cistatic PermissionTrans g_unDefPer = {
87f6603c60Sopenharmony_ci    PERMISSION_UNDEFINED,
88f6603c60Sopenharmony_ci    "for undefined use",
89f6603c60Sopenharmony_ci    INUSE,
90f6603c60Sopenharmony_ci};
91f6603c60Sopenharmony_ci
92f6603c60Sopenharmony_ciint IsUserGrant(const char* pname)
93f6603c60Sopenharmony_ci{
94f6603c60Sopenharmony_ci    if (strcmp(pname, "ohos.permission.MODIFY_AUDIO_SETTINGS") == 0) {
95f6603c60Sopenharmony_ci        return false;
96f6603c60Sopenharmony_ci    }
97f6603c60Sopenharmony_ci    return true;
98f6603c60Sopenharmony_ci}
99f6603c60Sopenharmony_ci
100f6603c60Sopenharmony_ciint CheckPermData(const PermissionTrans* pt, const PermissionSaved* ps,
101f6603c60Sopenharmony_ci    const PermissionSaved* pre, int len, int plen)
102f6603c60Sopenharmony_ci{
103f6603c60Sopenharmony_ci    if (len == 0) {
104f6603c60Sopenharmony_ci        printf("len == 0\n");
105f6603c60Sopenharmony_ci        return true;
106f6603c60Sopenharmony_ci    }
107f6603c60Sopenharmony_ci    if (ps == NULL) {
108f6603c60Sopenharmony_ci        printf("ps == NULL\n");
109f6603c60Sopenharmony_ci        return false;
110f6603c60Sopenharmony_ci    }
111f6603c60Sopenharmony_ci    bool ret = true;
112f6603c60Sopenharmony_ci    for (int i = 0; i < len; i++) {
113f6603c60Sopenharmony_ci        if (strcmp(pt[i].name, ps[i].name) != 0) {
114f6603c60Sopenharmony_ci            ret = false;
115f6603c60Sopenharmony_ci        }
116f6603c60Sopenharmony_ci        int grant = NOT_GRANTED;
117f6603c60Sopenharmony_ci        if (IsUserGrant(pt[i].name)) {
118f6603c60Sopenharmony_ci            if (pre != NULL) {
119f6603c60Sopenharmony_ci                for (int j = 0; j < plen; j++) {
120f6603c60Sopenharmony_ci                    if (strcmp(ps[i].name, pre[j].name) == 0 && pre[j].granted == GRANTED) {
121f6603c60Sopenharmony_ci                        grant = GRANTED;
122f6603c60Sopenharmony_ci                        break;
123f6603c60Sopenharmony_ci                    }
124f6603c60Sopenharmony_ci                }
125f6603c60Sopenharmony_ci            }
126f6603c60Sopenharmony_ci        } else {
127f6603c60Sopenharmony_ci            grant = GRANTED;
128f6603c60Sopenharmony_ci        }
129f6603c60Sopenharmony_ci        if (ps[i].granted != grant) {
130f6603c60Sopenharmony_ci            ret = false;
131f6603c60Sopenharmony_ci        }
132f6603c60Sopenharmony_ci        if (ret == false) {
133f6603c60Sopenharmony_ci            printf("ps[i].name = %s, ps[i].granted = %d, except = %d\n", pt[i].name, ps[i].granted, grant);
134f6603c60Sopenharmony_ci            break;
135f6603c60Sopenharmony_ci        }
136f6603c60Sopenharmony_ci    }
137f6603c60Sopenharmony_ci    return ret;
138f6603c60Sopenharmony_ci}
139f6603c60Sopenharmony_ci
140f6603c60Sopenharmony_civoid ClrPers(PermissionSaved* &permissions)
141f6603c60Sopenharmony_ci{
142f6603c60Sopenharmony_ci    if (permissions != NULL) {
143f6603c60Sopenharmony_ci        free(permissions);
144f6603c60Sopenharmony_ci        permissions = NULL;
145f6603c60Sopenharmony_ci    }
146f6603c60Sopenharmony_ci}
147f6603c60Sopenharmony_ci
148f6603c60Sopenharmony_ciclass ActsPMSSaveTest : public testing::Test {
149f6603c60Sopenharmony_cipublic:
150f6603c60Sopenharmony_ci    static void InitInterface()
151f6603c60Sopenharmony_ci    {
152f6603c60Sopenharmony_ci        if (g_interface != NULL) {
153f6603c60Sopenharmony_ci            return;
154f6603c60Sopenharmony_ci        }
155f6603c60Sopenharmony_ci
156f6603c60Sopenharmony_ci        SetUpTestCase();
157f6603c60Sopenharmony_ci    }
158f6603c60Sopenharmony_ciprotected:
159f6603c60Sopenharmony_ci    static void SetUpTestCase(void)
160f6603c60Sopenharmony_ci    {
161f6603c60Sopenharmony_ci        CreateAppDir();
162f6603c60Sopenharmony_ci        IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(PERMISSION_SERVICE, PERM_INNER);
163f6603c60Sopenharmony_ci        iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **) &g_interface);
164f6603c60Sopenharmony_ci        setuid(0);
165f6603c60Sopenharmony_ci    }
166f6603c60Sopenharmony_ci    static void TearDownTestCase(void) {}
167f6603c60Sopenharmony_ci    virtual void SetUp() {}
168f6603c60Sopenharmony_ci    virtual void TearDown()
169f6603c60Sopenharmony_ci    {
170f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID);
171f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID2);
172f6603c60Sopenharmony_ci        DeletePermissions(SUBTEST_APP_ID);
173f6603c60Sopenharmony_ci        UnLoadPermissions(TEST_TASKID);
174f6603c60Sopenharmony_ci        UnLoadPermissions(SUBTEST_TASKID);
175f6603c60Sopenharmony_ci    }
176f6603c60Sopenharmony_ci};
177f6603c60Sopenharmony_ci
178f6603c60Sopenharmony_civoid CheckAppPermission(const char *identifier, int expRet, int expNum, const PermissionTrans* installPers,
179f6603c60Sopenharmony_ci    const PermissionSaved* lastPers, int lastLen)
180f6603c60Sopenharmony_ci{
181f6603c60Sopenharmony_ci    if (g_interface == NULL) {
182f6603c60Sopenharmony_ci        ActsPMSSaveTest::InitInterface();
183f6603c60Sopenharmony_ci    }
184f6603c60Sopenharmony_ci    PermissionSaved* permissions = NULL;
185f6603c60Sopenharmony_ci    int permNum = 0;
186f6603c60Sopenharmony_ci    int ret = g_interface->QueryPermission(identifier, &permissions, &permNum);
187f6603c60Sopenharmony_ci    EXPECT_EQ(ret, expRet) << "query ret = " << ret << ", expect ret = " << expRet << std::endl;
188f6603c60Sopenharmony_ci    EXPECT_EQ(permNum, expNum) << "permNum = " << permNum << ", expect permNum = " << expNum << std::endl;
189f6603c60Sopenharmony_ci    ret = CheckPermData(installPers, permissions, lastPers, permNum, lastLen);
190f6603c60Sopenharmony_ci    EXPECT_EQ(ret, true);
191f6603c60Sopenharmony_ci    ClrPers(permissions);
192f6603c60Sopenharmony_ci}
193f6603c60Sopenharmony_ci
194f6603c60Sopenharmony_civoid SubTestWithoutCheck(const char *identifier, int taskID)
195f6603c60Sopenharmony_ci{
196f6603c60Sopenharmony_ci    if (g_interface == NULL) {
197f6603c60Sopenharmony_ci        ActsPMSSaveTest::InitInterface();
198f6603c60Sopenharmony_ci    }
199f6603c60Sopenharmony_ci
200f6603c60Sopenharmony_ci    SaveOrUpdatePermissions(identifier, g_systemPers, 0, FIRST_INSTALL);
201f6603c60Sopenharmony_ci    SaveOrUpdatePermissions(identifier, g_systemPers, SYS_PERM_NUM, UPDATE);
202f6603c60Sopenharmony_ci    int i;
203f6603c60Sopenharmony_ci    for (i = 0; i < SYS_PERM_NUM; i++) {
204f6603c60Sopenharmony_ci        g_interface->GrantPermission(identifier, g_systemPers[i].name);
205f6603c60Sopenharmony_ci    }
206f6603c60Sopenharmony_ci    for (i = 0; i < SYS_PERM_NUM; i++) {
207f6603c60Sopenharmony_ci        g_interface->RevokePermission(identifier, g_systemPers[i].name);
208f6603c60Sopenharmony_ci    }
209f6603c60Sopenharmony_ci    g_interface->GrantPermission(identifier, g_systemPers[0].name);
210f6603c60Sopenharmony_ci    LoadPermissions(identifier, taskID);
211f6603c60Sopenharmony_ci    g_interface->GrantRuntimePermission(taskID, g_systemPers[1].name);
212f6603c60Sopenharmony_ci    CheckPermission(TEST_TASKID, g_systemPers[0].name);
213f6603c60Sopenharmony_ci    UnLoadPermissions(taskID);
214f6603c60Sopenharmony_ci    CheckPermission(TEST_TASKID, g_systemPers[0].name);
215f6603c60Sopenharmony_ci    DeletePermissions(identifier);
216f6603c60Sopenharmony_ci}
217f6603c60Sopenharmony_ci
218f6603c60Sopenharmony_civoid CreateAppDir(void)
219f6603c60Sopenharmony_ci{
220f6603c60Sopenharmony_ci    mkdir("/storage", DIR_MODE);
221f6603c60Sopenharmony_ci    mkdir("/storage/app", DIR_MODE);
222f6603c60Sopenharmony_ci    int ret = mkdir(ETC_PREFIX, DIR_MODE);
223f6603c60Sopenharmony_ci    if (ret) {
224f6603c60Sopenharmony_ci        printf("create dir %s error\n", ETC_PREFIX);
225f6603c60Sopenharmony_ci    }
226f6603c60Sopenharmony_ci    ret = mkdir(PERMISSION_PREFIX, DIR_MODE);
227f6603c60Sopenharmony_ci    if (ret) {
228f6603c60Sopenharmony_ci        printf("create dir %s error\n", PERMISSION_PREFIX);
229f6603c60Sopenharmony_ci    }
230f6603c60Sopenharmony_ci}
231f6603c60Sopenharmony_ci
232f6603c60Sopenharmony_ci/**
233f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0010
234f6603c60Sopenharmony_ci * @tc.name       Calling PMS interface to install and save unauthorized application for the first time
235f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
236f6603c60Sopenharmony_ci */
237f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0010, Function | MediumTest | Level1)
238f6603c60Sopenharmony_ci{
239f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0]};
240f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 0, FIRST_INSTALL);
241f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
242f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, pt);
243f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
244f6603c60Sopenharmony_ci}
245f6603c60Sopenharmony_ci
246f6603c60Sopenharmony_ci/**
247f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0020
248f6603c60Sopenharmony_ci * @tc.name       Call PMS interface to install and save the application with full application rights for the first time
249f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0300]
250f6603c60Sopenharmony_ci */
251f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0020, Function | MediumTest | Level0)
252f6603c60Sopenharmony_ci{
253f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
254f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
255f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
256f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
257f6603c60Sopenharmony_ci}
258f6603c60Sopenharmony_ci
259f6603c60Sopenharmony_ci/**
260f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0030
261f6603c60Sopenharmony_ci * @tc.name       Call the PMS interface to install and save the application with a permission for the first time
262f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
263f6603c60Sopenharmony_ci */
264f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0030, Function | MediumTest | Level2)
265f6603c60Sopenharmony_ci{
266f6603c60Sopenharmony_ci    PermissionTrans pt[1];
267f6603c60Sopenharmony_ci    int ret = PERM_ERRORCODE_INVALID_PARAMS;
268f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
269f6603c60Sopenharmony_ci        pt[0] = g_systemPers[i];
270f6603c60Sopenharmony_ci        ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 1, FIRST_INSTALL);
271f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
272f6603c60Sopenharmony_ci        CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 1, pt);
273f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID);
274f6603c60Sopenharmony_ci    }
275f6603c60Sopenharmony_ci}
276f6603c60Sopenharmony_ci
277f6603c60Sopenharmony_ci/**
278f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0040
279f6603c60Sopenharmony_ci * @tc.name       Calling the PMS interface first installs a non system defined permission
280f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
281f6603c60Sopenharmony_ci */
282f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0040, Function | MediumTest | Level3)
283f6603c60Sopenharmony_ci{
284f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_unDefPer};
285f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 1, FIRST_INSTALL);
286f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
287f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 1, pt);
288f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
289f6603c60Sopenharmony_ci}
290f6603c60Sopenharmony_ci
291f6603c60Sopenharmony_ci/**
292f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0050
293f6603c60Sopenharmony_ci * @tc.name       Call the PMS interface to install the permission of exception permission name for the first time
294f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
295f6603c60Sopenharmony_ci */
296f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0050, Function | MediumTest | Level3)
297f6603c60Sopenharmony_ci{
298f6603c60Sopenharmony_ci    PermissionTrans pt[1];
299f6603c60Sopenharmony_ci    int ret = PERM_ERRORCODE_INVALID_PARAMS;
300f6603c60Sopenharmony_ci    for (int i = 0; i < ABNORMAL_PERM_NUM; i++) {
301f6603c60Sopenharmony_ci        pt[0] = g_unNormalPers[i];
302f6603c60Sopenharmony_ci        ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 1, FIRST_INSTALL);
303f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << ", index = " << i << endl;
304f6603c60Sopenharmony_ci        CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 1, pt);
305f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID);
306f6603c60Sopenharmony_ci    }
307f6603c60Sopenharmony_ci}
308f6603c60Sopenharmony_ci
309f6603c60Sopenharmony_ci/**
310f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0060
311f6603c60Sopenharmony_ci * @tc.name       The number of saved application permissions has reached the upper limit
312f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
313f6603c60Sopenharmony_ci */
314f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0060, Function | MediumTest | Level2)
315f6603c60Sopenharmony_ci{
316f6603c60Sopenharmony_ci    PermissionTrans pt[MAX_PERM_NUM];
317f6603c60Sopenharmony_ci    PermissionTrans exp[MAX_PERM_NUM];
318f6603c60Sopenharmony_ci    int i;
319f6603c60Sopenharmony_ci    for (i = 0; i < SYS_PERM_NUM; i++) {
320f6603c60Sopenharmony_ci        pt[i] = g_systemPers[i];
321f6603c60Sopenharmony_ci        exp[i] = g_systemPers[i];
322f6603c60Sopenharmony_ci    }
323f6603c60Sopenharmony_ci    exp[SYS_PERM_NUM] = g_unDefPer;
324f6603c60Sopenharmony_ci    for (i = SYS_PERM_NUM; i < MAX_PERM_NUM; i++) {
325f6603c60Sopenharmony_ci        pt[i] = g_unDefPer;
326f6603c60Sopenharmony_ci    }
327f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, MAX_PERM_NUM, FIRST_INSTALL);
328f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
329f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM + 1, exp);
330f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
331f6603c60Sopenharmony_ci}
332f6603c60Sopenharmony_ci
333f6603c60Sopenharmony_ci/**
334f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0070
335f6603c60Sopenharmony_ci * @tc.name       The number of saved application permissions exceeds the upper limit
336f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
337f6603c60Sopenharmony_ci */
338f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0070, Function | MediumTest | Level4)
339f6603c60Sopenharmony_ci{
340f6603c60Sopenharmony_ci    PermissionTrans pt[MAX_PERM_NUM + 1];
341f6603c60Sopenharmony_ci    int i;
342f6603c60Sopenharmony_ci    for (i = 0; i < MAX_PERM_NUM + 1; i++) {
343f6603c60Sopenharmony_ci        pt[i] = g_systemPers[0];
344f6603c60Sopenharmony_ci    }
345f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, MAX_PERM_NUM + 1, FIRST_INSTALL);
346f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_TOO_MUCH_PERM) << "save ret = " << ret << endl;
347f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, pt);
348f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
349f6603c60Sopenharmony_ci}
350f6603c60Sopenharmony_ci
351f6603c60Sopenharmony_ci/**
352f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0080
353f6603c60Sopenharmony_ci * @tc.name       Save duplicate application permission
354f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
355f6603c60Sopenharmony_ci */
356f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0080, Function | MediumTest | Level2)
357f6603c60Sopenharmony_ci{
358f6603c60Sopenharmony_ci    PermissionTrans pt[MAX_PERM_NUM];
359f6603c60Sopenharmony_ci    int i;
360f6603c60Sopenharmony_ci    for (i = 0; i < SYS_PERM_NUM; i++) {
361f6603c60Sopenharmony_ci        pt[i] = g_systemPers[i];
362f6603c60Sopenharmony_ci    }
363f6603c60Sopenharmony_ci    for (i = SYS_PERM_NUM; i < MAX_PERM_NUM; i++) {
364f6603c60Sopenharmony_ci        pt[i] = g_systemPers[0];
365f6603c60Sopenharmony_ci    }
366f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, MAX_PERM_NUM, FIRST_INSTALL);
367f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
368f6603c60Sopenharmony_ci    PermissionSaved* permissions = NULL;
369f6603c60Sopenharmony_ci    int permNum = 0;
370f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &permissions, &permNum);
371f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
372f6603c60Sopenharmony_ci    EXPECT_EQ(permNum, SYS_PERM_NUM) << "permNum = " << permNum << endl;
373f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
374f6603c60Sopenharmony_ci}
375f6603c60Sopenharmony_ci
376f6603c60Sopenharmony_ci/**
377f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0090
378f6603c60Sopenharmony_ci * @tc.name       Save MAX_PERM_NUM application permission
379f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
380f6603c60Sopenharmony_ci */
381f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0090, Function | MediumTest | Level4)
382f6603c60Sopenharmony_ci{
383f6603c60Sopenharmony_ci    PermissionTrans pt[MAX_PERM_NUM];
384f6603c60Sopenharmony_ci    int i;
385f6603c60Sopenharmony_ci    for (i = 0; i < MAX_PERM_NUM; i++) {
386f6603c60Sopenharmony_ci        pt[i] = g_systemPers[0];
387f6603c60Sopenharmony_ci    }
388f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, MAX_PERM_NUM, FIRST_INSTALL);
389f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
390f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 1, pt);
391f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
392f6603c60Sopenharmony_ci}
393f6603c60Sopenharmony_ci
394f6603c60Sopenharmony_ci/**
395f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0100
396f6603c60Sopenharmony_ci * @tc.name       Save multiple application permissions
397f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
398f6603c60Sopenharmony_ci */
399f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0100, Function | MediumTest | Level1)
400f6603c60Sopenharmony_ci{
401f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0]};
402f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 0, FIRST_INSTALL);
403f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
404f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID2, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
405f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
406f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, pt);
407f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID2, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
408f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
409f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID2);
410f6603c60Sopenharmony_ci}
411f6603c60Sopenharmony_ci
412f6603c60Sopenharmony_ci/**
413f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0110
414f6603c60Sopenharmony_ci * @tc.name       Update application, save more permissions
415f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
416f6603c60Sopenharmony_ci */
417f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0110, Function | MediumTest | Level2)
418f6603c60Sopenharmony_ci{
419f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0]};
420f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 0, FIRST_INSTALL);
421f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
422f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
423f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
424f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
425f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
426f6603c60Sopenharmony_ci}
427f6603c60Sopenharmony_ci
428f6603c60Sopenharmony_ci/**
429f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0120
430f6603c60Sopenharmony_ci * @tc.name       Update application, save less permissions
431f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
432f6603c60Sopenharmony_ci */
433f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0120, Function | MediumTest | Level2)
434f6603c60Sopenharmony_ci{
435f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0]};
436f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
437f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
438f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 0, UPDATE);
439f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
440f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, pt);
441f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
442f6603c60Sopenharmony_ci}
443f6603c60Sopenharmony_ci
444f6603c60Sopenharmony_ci/**
445f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0130
446f6603c60Sopenharmony_ci * @tc.name       Update application, save same permissions
447f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
448f6603c60Sopenharmony_ci */
449f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0130, Function | MediumTest | Level1)
450f6603c60Sopenharmony_ci{
451f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
452f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
453f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
454f6603c60Sopenharmony_ci        ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
455f6603c60Sopenharmony_ci    }
456f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
457f6603c60Sopenharmony_ci    int oldp = 0;
458f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
459f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
460f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, SYS_PERM_NUM) << "permNum = " << oldp;
461f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
462f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
463f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers, oldpers, oldp);
464f6603c60Sopenharmony_ci    ClrPers(oldpers);
465f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
466f6603c60Sopenharmony_ci}
467f6603c60Sopenharmony_ci
468f6603c60Sopenharmony_ci/**
469f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0140
470f6603c60Sopenharmony_ci * @tc.name       Update application, save different permissions
471f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
472f6603c60Sopenharmony_ci */
473f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0140, Function | MediumTest | Level1)
474f6603c60Sopenharmony_ci{
475f6603c60Sopenharmony_ci    PermissionTrans pt1[] = {g_systemPers[0], g_systemPers[1], g_systemPers[2],
476f6603c60Sopenharmony_ci                g_systemPers[3], g_systemPers[5], g_systemPers[6], g_systemPers[7]};
477f6603c60Sopenharmony_ci    PermissionTrans pt2[] = {g_systemPers[1], g_systemPers[2], g_systemPers[3], g_systemPers[4],
478f6603c60Sopenharmony_ci                g_systemPers[5], g_systemPers[6], g_systemPers[7], g_systemPers[8]};
479f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt1, 7, FIRST_INSTALL);
480f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
481f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
482f6603c60Sopenharmony_ci        ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
483f6603c60Sopenharmony_ci    }
484f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
485f6603c60Sopenharmony_ci    int oldp = 0;
486f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
487f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
488f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, 7) << "permNum = " << oldp;
489f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, pt2, 8, UPDATE);
490f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
491f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 8, pt2, oldpers, oldp);
492f6603c60Sopenharmony_ci    ClrPers(oldpers);
493f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
494f6603c60Sopenharmony_ci}
495f6603c60Sopenharmony_ci
496f6603c60Sopenharmony_ci/**
497f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0150
498f6603c60Sopenharmony_ci * @tc.name       Update application, delete system_grant permissions
499f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
500f6603c60Sopenharmony_ci */
501f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0150, Function | MediumTest | Level3)
502f6603c60Sopenharmony_ci{
503f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
504f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
505f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
506f6603c60Sopenharmony_ci    int oldp = 0;
507f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
508f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
509f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, SYS_PERM_NUM) << "permNum = " << oldp;
510f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM - 1, UPDATE);
511f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
512f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM - 1, g_systemPers, oldpers, oldp);
513f6603c60Sopenharmony_ci    ClrPers(oldpers);
514f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
515f6603c60Sopenharmony_ci}
516f6603c60Sopenharmony_ci
517f6603c60Sopenharmony_ci/**
518f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0160
519f6603c60Sopenharmony_ci * @tc.name       Update application, delete granted user_grant permissions
520f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
521f6603c60Sopenharmony_ci */
522f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0160, Function | MediumTest | Level2)
523f6603c60Sopenharmony_ci{
524f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0], g_systemPers[1], g_systemPers[2], g_systemPers[3],
525f6603c60Sopenharmony_ci                            g_systemPers[5], g_systemPers[6], g_systemPers[7]};
526f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
527f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
528f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
529f6603c60Sopenharmony_ci        ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
530f6603c60Sopenharmony_ci    }
531f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
532f6603c60Sopenharmony_ci    int oldp = 0;
533f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
534f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
535f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, SYS_PERM_NUM) << "permNum = " << oldp;
536f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 7, UPDATE);
537f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
538f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 7, pt, oldpers, oldp);
539f6603c60Sopenharmony_ci    ClrPers(oldpers);
540f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
541f6603c60Sopenharmony_ci}
542f6603c60Sopenharmony_ci
543f6603c60Sopenharmony_ci/**
544f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0170
545f6603c60Sopenharmony_ci * @tc.name       Update application, delete user_grant permissions
546f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
547f6603c60Sopenharmony_ci */
548f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0170, Function | MediumTest | Level2)
549f6603c60Sopenharmony_ci{
550f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[0], g_systemPers[1], g_systemPers[2], g_systemPers[3],
551f6603c60Sopenharmony_ci                            g_systemPers[5], g_systemPers[6], g_systemPers[7]};
552f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
553f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
554f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
555f6603c60Sopenharmony_ci        if (i % 2 == 0) {
556f6603c60Sopenharmony_ci            continue;
557f6603c60Sopenharmony_ci        }
558f6603c60Sopenharmony_ci        ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
559f6603c60Sopenharmony_ci    }
560f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
561f6603c60Sopenharmony_ci    int oldp = 0;
562f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
563f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
564f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, SYS_PERM_NUM) << "permNum = " << oldp;
565f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 7, UPDATE);
566f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
567f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, 7, pt, oldpers, oldp);
568f6603c60Sopenharmony_ci    ClrPers(oldpers);
569f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
570f6603c60Sopenharmony_ci}
571f6603c60Sopenharmony_ci
572f6603c60Sopenharmony_ci/**
573f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0180
574f6603c60Sopenharmony_ci * @tc.name       Update application, add system_grant permissions
575f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
576f6603c60Sopenharmony_ci */
577f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0180, Function | MediumTest | Level2)
578f6603c60Sopenharmony_ci{
579f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM - 1, FIRST_INSTALL);
580f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
581f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
582f6603c60Sopenharmony_ci    int oldp = 0;
583f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
584f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
585f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, SYS_PERM_NUM - 1) << "permNum = " << oldp;
586f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
587f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
588f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers, oldpers, oldp);
589f6603c60Sopenharmony_ci    ClrPers(oldpers);
590f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
591f6603c60Sopenharmony_ci}
592f6603c60Sopenharmony_ci
593f6603c60Sopenharmony_ci/**
594f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0190
595f6603c60Sopenharmony_ci * @tc.name       Update application, add user_grant permissions
596f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
597f6603c60Sopenharmony_ci */
598f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0190, Function | MediumTest | Level1)
599f6603c60Sopenharmony_ci{
600f6603c60Sopenharmony_ci    PermissionTrans pt[] = {g_systemPers[8]};
601f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, pt, 1, FIRST_INSTALL);
602f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
603f6603c60Sopenharmony_ci    PermissionSaved* oldpers = NULL;
604f6603c60Sopenharmony_ci    int oldp = 0;
605f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &oldpers, &oldp);
606f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
607f6603c60Sopenharmony_ci    EXPECT_EQ(oldp, 1) << "permNum = " << oldp;
608f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
609f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
610f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers, oldpers, oldp);
611f6603c60Sopenharmony_ci    ClrPers(oldpers);
612f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
613f6603c60Sopenharmony_ci}
614f6603c60Sopenharmony_ci
615f6603c60Sopenharmony_ci/**
616f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0220
617f6603c60Sopenharmony_ci * @tc.name       First time installation, initializing permissions
618f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
619f6603c60Sopenharmony_ci */
620f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0220, Function | MediumTest | Level3)
621f6603c60Sopenharmony_ci{
622f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
623f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
624f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
625f6603c60Sopenharmony_ci        g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
626f6603c60Sopenharmony_ci    }
627f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
628f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
629f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
630f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
631f6603c60Sopenharmony_ci}
632f6603c60Sopenharmony_ci
633f6603c60Sopenharmony_ci/**
634f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0240
635f6603c60Sopenharmony_ci * @tc.name       After the application is uninstalled, the permissions are initialized
636f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0600]
637f6603c60Sopenharmony_ci */
638f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0240, Function | MediumTest | Level2)
639f6603c60Sopenharmony_ci{
640f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
641f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
642f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
643f6603c60Sopenharmony_ci        g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
644f6603c60Sopenharmony_ci    }
645f6603c60Sopenharmony_ci    ret = DeletePermissions(TEST_APP_ID);
646f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "delete ret = " << ret << endl;
647f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
648f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
649f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
650f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
651f6603c60Sopenharmony_ci}
652f6603c60Sopenharmony_ci
653f6603c60Sopenharmony_ci/**
654f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0320
655f6603c60Sopenharmony_ci * @tc.name       After the permissions are loaded, the permissions can be updated
656f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
657f6603c60Sopenharmony_ci */
658f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0320, Function | MediumTest | Level2)
659f6603c60Sopenharmony_ci{
660f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
661f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
662f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
663f6603c60Sopenharmony_ci        g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
664f6603c60Sopenharmony_ci    }
665f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
666f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
667f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, 0, UPDATE);
668f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
669f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
670f6603c60Sopenharmony_ci    ret = UnLoadPermissions(TEST_TASKID);
671f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
672f6603c60Sopenharmony_ci}
673f6603c60Sopenharmony_ci
674f6603c60Sopenharmony_ci/**
675f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0330
676f6603c60Sopenharmony_ci * @tc.name       After the permissions are unloaded, the permissions can be updated
677f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
678f6603c60Sopenharmony_ci */
679f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0330, Function | MediumTest | Level2)
680f6603c60Sopenharmony_ci{
681f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
682f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
683f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
684f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
685f6603c60Sopenharmony_ci    ret = UnLoadPermissions(TEST_TASKID);
686f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "unload ret = " << ret << endl;
687f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, 0, UPDATE);
688f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
689f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
690f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
691f6603c60Sopenharmony_ci}
692f6603c60Sopenharmony_ci
693f6603c60Sopenharmony_ci/**
694f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0340
695f6603c60Sopenharmony_ci * @tc.name       After the permissions are checked, the permissions can be updated
696f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
697f6603c60Sopenharmony_ci */
698f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0340, Function | MediumTest | Level4)
699f6603c60Sopenharmony_ci{
700f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
701f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
702f6603c60Sopenharmony_ci    for (int i = 0; i < SYS_PERM_NUM; i++) {
703f6603c60Sopenharmony_ci        g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name);
704f6603c60Sopenharmony_ci    }
705f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
706f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
707f6603c60Sopenharmony_ci    ret = CheckPermission(TEST_TASKID, g_systemPers[0].name);
708f6603c60Sopenharmony_ci    EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl;
709f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, 0, UPDATE);
710f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
711f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
712f6603c60Sopenharmony_ci    UnLoadPermissions(TEST_TASKID);
713f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
714f6603c60Sopenharmony_ci}
715f6603c60Sopenharmony_ci
716f6603c60Sopenharmony_ci/**
717f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0350
718f6603c60Sopenharmony_ci * @tc.name       After the permissions are queryed, the permissions can be updated
719f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
720f6603c60Sopenharmony_ci */
721f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0350, Function | MediumTest | Level4)
722f6603c60Sopenharmony_ci{
723f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
724f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
725f6603c60Sopenharmony_ci    ret = LoadPermissions(TEST_APP_ID, TEST_TASKID);
726f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl;
727f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_SUCCESS, SYS_PERM_NUM, g_systemPers);
728f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, 0, UPDATE);
729f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
730f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_FILE_NOT_EXIST, 0, g_systemPers);
731f6603c60Sopenharmony_ci    UnLoadPermissions(TEST_TASKID);
732f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
733f6603c60Sopenharmony_ci}
734f6603c60Sopenharmony_ci
735f6603c60Sopenharmony_ci/**
736f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0360
737f6603c60Sopenharmony_ci * @tc.name       After the permissions are granted, the permissions can be updated
738f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
739f6603c60Sopenharmony_ci */
740f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0360, Function | MediumTest | Level2)
741f6603c60Sopenharmony_ci{
742f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
743f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
744f6603c60Sopenharmony_ci    ret = g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name);
745f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
746f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
747f6603c60Sopenharmony_ci    PermissionSaved* permissions = NULL;
748f6603c60Sopenharmony_ci    int permNum = 0;
749f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &permissions, &permNum);
750f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
751f6603c60Sopenharmony_ci    EXPECT_EQ(permNum, SYS_PERM_NUM) << "permNum = " << permNum << endl;
752f6603c60Sopenharmony_ci    EXPECT_EQ(permissions[0].granted, GRANTED);
753f6603c60Sopenharmony_ci    ClrPers(permissions);
754f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
755f6603c60Sopenharmony_ci}
756f6603c60Sopenharmony_ci
757f6603c60Sopenharmony_ci/**
758f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0370
759f6603c60Sopenharmony_ci * @tc.name       After the permissions are revoked, the permissions can be updated
760f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
761f6603c60Sopenharmony_ci */
762f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0370, Function | MediumTest | Level2)
763f6603c60Sopenharmony_ci{
764f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
765f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
766f6603c60Sopenharmony_ci    g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name);
767f6603c60Sopenharmony_ci    g_interface->RevokePermission(TEST_APP_ID, g_systemPers[0].name);
768f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
769f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
770f6603c60Sopenharmony_ci    PermissionSaved* permissions = NULL;
771f6603c60Sopenharmony_ci    int permNum = 0;
772f6603c60Sopenharmony_ci    ret = g_interface->QueryPermission(TEST_APP_ID, &permissions, &permNum);
773f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "query ret = " << ret << endl;
774f6603c60Sopenharmony_ci    EXPECT_EQ(permNum, SYS_PERM_NUM) << "permNum = " << permNum << endl;
775f6603c60Sopenharmony_ci    EXPECT_EQ(permissions[0].granted, NOT_GRANTED);
776f6603c60Sopenharmony_ci    ClrPers(permissions);
777f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
778f6603c60Sopenharmony_ci}
779f6603c60Sopenharmony_ci
780f6603c60Sopenharmony_ci/**
781f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0380
782f6603c60Sopenharmony_ci * @tc.name       Another application permission change does not affect save permission
783f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
784f6603c60Sopenharmony_ci */
785f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0380, Function | MediumTest | Level3)
786f6603c60Sopenharmony_ci{
787f6603c60Sopenharmony_ci    int pid = fork();
788f6603c60Sopenharmony_ci    int status = 0;
789f6603c60Sopenharmony_ci    if (pid != 0) {
790f6603c60Sopenharmony_ci        int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
791f6603c60Sopenharmony_ci        EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
792f6603c60Sopenharmony_ci        DeletePermissions(TEST_APP_ID);
793f6603c60Sopenharmony_ci        waitpid(pid, &status, 0);
794f6603c60Sopenharmony_ci    } else {
795f6603c60Sopenharmony_ci        SubTestWithoutCheck(SUBTEST_APP_ID, SUBTEST_TASKID);
796f6603c60Sopenharmony_ci        exit(0);
797f6603c60Sopenharmony_ci    }
798f6603c60Sopenharmony_ci}
799f6603c60Sopenharmony_ci
800f6603c60Sopenharmony_ci/**
801f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0390
802f6603c60Sopenharmony_ci * @tc.name       Permission not to save exception package names
803f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
804f6603c60Sopenharmony_ci */
805f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0390, Function | MediumTest | Level3)
806f6603c60Sopenharmony_ci{
807f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(NULL, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
808f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_INVALID_PARAMS) << "save ret = " << ret << endl;
809f6603c60Sopenharmony_ci}
810f6603c60Sopenharmony_ci
811f6603c60Sopenharmony_ci/**
812f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0410
813f6603c60Sopenharmony_ci * @tc.name       The permission file is abnormal and can be updated
814f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
815f6603c60Sopenharmony_ci */
816f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0410, Function | MediumTest | Level4)
817f6603c60Sopenharmony_ci{
818f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
819f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
820f6603c60Sopenharmony_ci    int fd = access(TEST_APP_PATH, F_OK);
821f6603c60Sopenharmony_ci    if (fd == 0) {
822f6603c60Sopenharmony_ci        unlink(TEST_APP_PATH);
823f6603c60Sopenharmony_ci    }
824f6603c60Sopenharmony_ci    fd = open(TEST_APP_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
825f6603c60Sopenharmony_ci    if (fd >= 0) {
826f6603c60Sopenharmony_ci        write(fd, PERMISSION_UNSUPPORTED, strlen(PERMISSION_UNSUPPORTED));
827f6603c60Sopenharmony_ci        close(fd);
828f6603c60Sopenharmony_ci    }
829f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE);
830f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_JSONPARSE_FAIL) << "save ret = " << ret << endl;
831f6603c60Sopenharmony_ci    CheckAppPermission(TEST_APP_ID, PERM_ERRORCODE_JSONPARSE_FAIL, 0, g_systemPers);
832f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_ID);
833f6603c60Sopenharmony_ci}
834f6603c60Sopenharmony_ci
835f6603c60Sopenharmony_ci/**
836f6603c60Sopenharmony_ci * @tc.number     SUB_SEC_AppSEC_PermissionMgmt_PMS_0490
837f6603c60Sopenharmony_ci * @tc.name       Can save application permission with long and short package names
838f6603c60Sopenharmony_ci * @tc.desc       [C- SECURITY -0700]
839f6603c60Sopenharmony_ci */
840f6603c60Sopenharmony_ciHWTEST_F(ActsPMSSaveTest, testSecPMPMS_0490, Function | MediumTest | Level2)
841f6603c60Sopenharmony_ci{
842f6603c60Sopenharmony_ci    int ret = SaveOrUpdatePermissions(TEST_APP_SHORT, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
843f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
844f6603c60Sopenharmony_ci    ret = SaveOrUpdatePermissions(TEST_APP_LONG, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
845f6603c60Sopenharmony_ci    EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "save ret = " << ret << endl;
846f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_SHORT);
847f6603c60Sopenharmony_ci    DeletePermissions(TEST_APP_LONG);
848f6603c60Sopenharmony_ci}