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 ActsPMSLoadTest : 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_0510 93f6603c60Sopenharmony_ci * @tc.name Can load application permission with long and short package names 94f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 95f6603c60Sopenharmony_ci */ 96f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0510, Function | MediumTest | Level2) 97f6603c60Sopenharmony_ci{ 98f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_SHORT, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 99f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_LONG, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 100f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_SHORT, TEST_TASKID); 101f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 102f6603c60Sopenharmony_ci ret = LoadPermissions(TEST_APP_LONG, SUBTEST_TASKID); 103f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 104f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 105f6603c60Sopenharmony_ci UnLoadPermissions(SUBTEST_TASKID); 106f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_SHORT); 107f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_LONG); 108f6603c60Sopenharmony_ci} 109f6603c60Sopenharmony_ci 110f6603c60Sopenharmony_ci/** 111f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0520 112f6603c60Sopenharmony_ci * @tc.name Load unauthorized permissions 113f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 114f6603c60Sopenharmony_ci */ 115f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0520, Function | MediumTest | Level1) 116f6603c60Sopenharmony_ci{ 117f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 118f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 119f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 120f6603c60Sopenharmony_ci for (int i = 0; i < SYS_PERM_NUM - 1; i++) { 121f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[i].name); 122f6603c60Sopenharmony_ci EXPECT_EQ(ret, NOT_GRANTED) << "checkperm ret = " << ret << ", index = " << i <<endl; 123f6603c60Sopenharmony_ci } 124f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 125f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 126f6603c60Sopenharmony_ci} 127f6603c60Sopenharmony_ci 128f6603c60Sopenharmony_ci/** 129f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0530 130f6603c60Sopenharmony_ci * @tc.name Load authorized permissions 131f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 132f6603c60Sopenharmony_ci */ 133f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0530, Function | MediumTest | Level1) 134f6603c60Sopenharmony_ci{ 135f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 136f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 137f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 138f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 139f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[0].name); 140f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl; 141f6603c60Sopenharmony_ci for (int i = 1; i < SYS_PERM_NUM - 1; i++) { 142f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[i].name); 143f6603c60Sopenharmony_ci EXPECT_EQ(ret, NOT_GRANTED) << "checkperm ret = " << ret << ", index = " << i <<endl; 144f6603c60Sopenharmony_ci } 145f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 146f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 147f6603c60Sopenharmony_ci} 148f6603c60Sopenharmony_ci 149f6603c60Sopenharmony_ci/** 150f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0540 151f6603c60Sopenharmony_ci * @tc.name Load system_grant permissions 152f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 153f6603c60Sopenharmony_ci */ 154f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0540, Function | MediumTest | Level1) 155f6603c60Sopenharmony_ci{ 156f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 157f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 158f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 159f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 160f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[SYS_PERM_NUM - 1].name); 161f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl; 162f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 163f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 164f6603c60Sopenharmony_ci} 165f6603c60Sopenharmony_ci 166f6603c60Sopenharmony_ci/** 167f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0550 168f6603c60Sopenharmony_ci * @tc.name Load user_grant permissions 169f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 170f6603c60Sopenharmony_ci */ 171f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0550, Function | MediumTest | Level0) 172f6603c60Sopenharmony_ci{ 173f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 174f6603c60Sopenharmony_ci int i = 0; 175f6603c60Sopenharmony_ci for (i = 0; i < SYS_PERM_NUM; i++) { 176f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[i].name); 177f6603c60Sopenharmony_ci } 178f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 179f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 180f6603c60Sopenharmony_ci for (int i = 0; i < SYS_PERM_NUM; i++) { 181f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[i].name); 182f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << ", index = " << i <<endl; 183f6603c60Sopenharmony_ci } 184f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 185f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 186f6603c60Sopenharmony_ci} 187f6603c60Sopenharmony_ci 188f6603c60Sopenharmony_ci/** 189f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0560 190f6603c60Sopenharmony_ci * @tc.name Load permissions to large and small PIDs 191f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 192f6603c60Sopenharmony_ci */ 193f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0560, Function | MediumTest | Level0) 194f6603c60Sopenharmony_ci{ 195f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 196f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, MAX_PID); 197f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 198f6603c60Sopenharmony_ci UnLoadPermissions(MAX_PID); 199f6603c60Sopenharmony_ci ret = LoadPermissions(TEST_APP_ID, MIN_PID); 200f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 201f6603c60Sopenharmony_ci UnLoadPermissions(MIN_PID); 202f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 203f6603c60Sopenharmony_ci} 204f6603c60Sopenharmony_ci 205f6603c60Sopenharmony_ci/** 206f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0570 207f6603c60Sopenharmony_ci * @tc.name Load nonexistent application permissions 208f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 209f6603c60Sopenharmony_ci */ 210f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0570, Function | MediumTest | Level2) 211f6603c60Sopenharmony_ci{ 212f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, MAX_PID); 213f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 214f6603c60Sopenharmony_ci} 215f6603c60Sopenharmony_ci 216f6603c60Sopenharmony_ci/** 217f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0580 218f6603c60Sopenharmony_ci * @tc.name Load loaded application permissions 219f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 220f6603c60Sopenharmony_ci */ 221f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0580, Function | MediumTest | Level2) 222f6603c60Sopenharmony_ci{ 223f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 224f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 225f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 226f6603c60Sopenharmony_ci ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 227f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 228f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 229f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 230f6603c60Sopenharmony_ci} 231f6603c60Sopenharmony_ci 232f6603c60Sopenharmony_ci/** 233f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0630 234f6603c60Sopenharmony_ci * @tc.name Duplicate load application permissions 235f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 236f6603c60Sopenharmony_ci */ 237f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0630, Function | MediumTest | Level2) 238f6603c60Sopenharmony_ci{ 239f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 240f6603c60Sopenharmony_ci LoadPermissions(TEST_APP_ID, TEST_TASKID); 241f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 242f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 243f6603c60Sopenharmony_ci ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 244f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 245f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 246f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 247f6603c60Sopenharmony_ci} 248f6603c60Sopenharmony_ci 249f6603c60Sopenharmony_ci/** 250f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0650 251f6603c60Sopenharmony_ci * @tc.name Load multiple application permissions 252f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 253f6603c60Sopenharmony_ci */ 254f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0650, Function | MediumTest | Level2) 255f6603c60Sopenharmony_ci{ 256f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 257f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID2, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 258f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 259f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 260f6603c60Sopenharmony_ci ret = LoadPermissions(TEST_APP_ID2, SUBTEST_TASKID); 261f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 262f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 263f6603c60Sopenharmony_ci UnLoadPermissions(SUBTEST_TASKID); 264f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 265f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID2); 266f6603c60Sopenharmony_ci} 267f6603c60Sopenharmony_ci 268f6603c60Sopenharmony_ci/** 269f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0670 270f6603c60Sopenharmony_ci * @tc.name Load immediately after saving permissions 271f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 272f6603c60Sopenharmony_ci */ 273f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0670, Function | MediumTest | Level2) 274f6603c60Sopenharmony_ci{ 275f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 276f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 277f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 278f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 279f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 280f6603c60Sopenharmony_ci} 281f6603c60Sopenharmony_ci 282f6603c60Sopenharmony_ci/** 283f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0680 284f6603c60Sopenharmony_ci * @tc.name Load immediately after updating permissions 285f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 286f6603c60Sopenharmony_ci */ 287f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0680, Function | MediumTest | Level2) 288f6603c60Sopenharmony_ci{ 289f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, 0, FIRST_INSTALL); 290f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, UPDATE); 291f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 292f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 293f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[SYS_PERM_NUM - 1].name); 294f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl; 295f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 296f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 297f6603c60Sopenharmony_ci} 298f6603c60Sopenharmony_ci 299f6603c60Sopenharmony_ci/** 300f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0690 301f6603c60Sopenharmony_ci * @tc.name Load immediately after deleting permissions 302f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 303f6603c60Sopenharmony_ci */ 304f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0690, Function | MediumTest | Level3) 305f6603c60Sopenharmony_ci{ 306f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 307f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 308f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 309f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 310f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 311f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[0].name); 312f6603c60Sopenharmony_ci EXPECT_EQ(ret, RET_NOK) << "checkperm ret = " << ret << endl; 313f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 314f6603c60Sopenharmony_ci} 315f6603c60Sopenharmony_ci 316f6603c60Sopenharmony_ci/** 317f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0700 318f6603c60Sopenharmony_ci * @tc.name Duplicate load after deleting permissions 319f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 320f6603c60Sopenharmony_ci */ 321f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0700, Function | MediumTest | Level3) 322f6603c60Sopenharmony_ci{ 323f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 324f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 325f6603c60Sopenharmony_ci LoadPermissions(TEST_APP_ID, TEST_TASKID); 326f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 327f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 328f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 329f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[0].name); 330f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl; 331f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 332f6603c60Sopenharmony_ci} 333f6603c60Sopenharmony_ci 334f6603c60Sopenharmony_ci/** 335f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0710 336f6603c60Sopenharmony_ci * @tc.name Load immediately after querying permissions 337f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 338f6603c60Sopenharmony_ci */ 339f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0710, Function | MediumTest | Level4) 340f6603c60Sopenharmony_ci{ 341f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 342f6603c60Sopenharmony_ci PermissionSaved* permissions = NULL; 343f6603c60Sopenharmony_ci int permNum = 0; 344f6603c60Sopenharmony_ci g_interface->QueryPermission(TEST_APP_ID, &permissions, &permNum); 345f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 346f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 347f6603c60Sopenharmony_ci ClrPers(permissions); 348f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 349f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 350f6603c60Sopenharmony_ci} 351f6603c60Sopenharmony_ci 352f6603c60Sopenharmony_ci/** 353f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0720 354f6603c60Sopenharmony_ci * @tc.name Load permission after grant runtime permissions 355f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 356f6603c60Sopenharmony_ci */ 357f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0720, Function | MediumTest | Level2) 358f6603c60Sopenharmony_ci{ 359f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 360f6603c60Sopenharmony_ci LoadPermissions(TEST_APP_ID, TEST_TASKID); 361f6603c60Sopenharmony_ci g_interface->GrantRuntimePermission(TEST_TASKID, g_systemPers[0].name); 362f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 363f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 364f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 365f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 366f6603c60Sopenharmony_ci} 367f6603c60Sopenharmony_ci 368f6603c60Sopenharmony_ci/** 369f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0730 370f6603c60Sopenharmony_ci * @tc.name Load immediately after granting permissions 371f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 372f6603c60Sopenharmony_ci */ 373f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0730, Function | MediumTest | Level2) 374f6603c60Sopenharmony_ci{ 375f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 376f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 377f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 378f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 379f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[0].name); 380f6603c60Sopenharmony_ci EXPECT_EQ(ret, GRANTED) << "checkperm ret = " << ret << endl; 381f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 382f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 383f6603c60Sopenharmony_ci} 384f6603c60Sopenharmony_ci 385f6603c60Sopenharmony_ci/** 386f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0740 387f6603c60Sopenharmony_ci * @tc.name Load immediately after revoking permissions 388f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 389f6603c60Sopenharmony_ci */ 390f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0740, Function | MediumTest | Level2) 391f6603c60Sopenharmony_ci{ 392f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 393f6603c60Sopenharmony_ci g_interface->GrantPermission(TEST_APP_ID, g_systemPers[0].name); 394f6603c60Sopenharmony_ci g_interface->RevokePermission(TEST_APP_ID, g_systemPers[0].name); 395f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 396f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 397f6603c60Sopenharmony_ci ret = g_interface->CheckPermission(TEST_TASKID, g_systemPers[0].name); 398f6603c60Sopenharmony_ci EXPECT_EQ(ret, NOT_GRANTED) << "checkperm ret = " << ret << endl; 399f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 400f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 401f6603c60Sopenharmony_ci} 402f6603c60Sopenharmony_ci 403f6603c60Sopenharmony_ci/** 404f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0830 405f6603c60Sopenharmony_ci * @tc.name Another application permission change does not affect load permission 406f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 407f6603c60Sopenharmony_ci */ 408f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0830, Function | MediumTest | Level3) 409f6603c60Sopenharmony_ci{ 410f6603c60Sopenharmony_ci int pid = fork(); 411f6603c60Sopenharmony_ci int status = 0; 412f6603c60Sopenharmony_ci if (pid != 0) { 413f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 414f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 415f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 416f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 417f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 418f6603c60Sopenharmony_ci waitpid(pid, &status, 0); 419f6603c60Sopenharmony_ci } else { 420f6603c60Sopenharmony_ci SubTestWithoutCheck(SUBTEST_APP_ID, SUBTEST_TASKID); 421f6603c60Sopenharmony_ci exit(0); 422f6603c60Sopenharmony_ci } 423f6603c60Sopenharmony_ci} 424f6603c60Sopenharmony_ci 425f6603c60Sopenharmony_ci/** 426f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0850 427f6603c60Sopenharmony_ci * @tc.name Permission to load exception package names 428f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 429f6603c60Sopenharmony_ci */ 430f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0850, Function | MediumTest | Level4) 431f6603c60Sopenharmony_ci{ 432f6603c60Sopenharmony_ci int ret = LoadPermissions(NULL, TEST_TASKID); 433f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_INVALID_PARAMS) << "load ret = " << ret << endl; 434f6603c60Sopenharmony_ci ret = LoadPermissions(SUBTEST_APP_ID, TEST_TASKID); 435f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 436f6603c60Sopenharmony_ci ret = LoadPermissions(PERMISSION_EMPTY, TEST_TASKID); 437f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_STAT_FAIL) << "load ret = " << ret << endl; 438f6603c60Sopenharmony_ci ret = LoadPermissions(PERMISSION_TOOLONG, TEST_TASKID); 439f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 440f6603c60Sopenharmony_ci ret = LoadPermissions(PERMISSION_UNSUPPORTED, TEST_TASKID); 441f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_SUCCESS) << "load ret = " << ret << endl; 442f6603c60Sopenharmony_ci} 443f6603c60Sopenharmony_ci 444f6603c60Sopenharmony_ci/** 445f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0860 446f6603c60Sopenharmony_ci * @tc.name Permission to load exception pid 447f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 448f6603c60Sopenharmony_ci */ 449f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0860, Function | MediumTest | Level3) 450f6603c60Sopenharmony_ci{ 451f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 452f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, ABNORMAL_TASKID); 453f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_INVALID_PARAMS) << "load ret = " << ret << endl; 454f6603c60Sopenharmony_ci UnLoadPermissions(ABNORMAL_TASKID); 455f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 456f6603c60Sopenharmony_ci} 457f6603c60Sopenharmony_ci 458f6603c60Sopenharmony_ci/** 459f6603c60Sopenharmony_ci * @tc.number SUB_SEC_AppSEC_PermissionMgmt_PMS_0880 460f6603c60Sopenharmony_ci * @tc.name Permission to load exception data 461f6603c60Sopenharmony_ci * @tc.desc [C- SECURITY -0900] 462f6603c60Sopenharmony_ci */ 463f6603c60Sopenharmony_ciHWTEST_F(ActsPMSLoadTest, testSecPMPMS_0880, Function | MediumTest | Level4) 464f6603c60Sopenharmony_ci{ 465f6603c60Sopenharmony_ci SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); 466f6603c60Sopenharmony_ci int fd = access(TEST_APP_PATH, F_OK); 467f6603c60Sopenharmony_ci if (fd == 0) { 468f6603c60Sopenharmony_ci unlink(TEST_APP_PATH); 469f6603c60Sopenharmony_ci } 470f6603c60Sopenharmony_ci fd = open(TEST_APP_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 471f6603c60Sopenharmony_ci if (fd >= 0) { 472f6603c60Sopenharmony_ci write(fd, PERMISSION_UNSUPPORTED, strlen(PERMISSION_UNSUPPORTED)); 473f6603c60Sopenharmony_ci close(fd); 474f6603c60Sopenharmony_ci } 475f6603c60Sopenharmony_ci int ret = LoadPermissions(TEST_APP_ID, TEST_TASKID); 476f6603c60Sopenharmony_ci EXPECT_EQ(ret, PERM_ERRORCODE_JSONPARSE_FAIL) << "load ret = " << ret << endl; 477f6603c60Sopenharmony_ci UnLoadPermissions(TEST_TASKID); 478f6603c60Sopenharmony_ci DeletePermissions(TEST_APP_ID); 479f6603c60Sopenharmony_ci} 480