diff --git a/security_lite/permission_posix/pms/BUILD.gn b/security_lite/permission_posix/pms/BUILD.gn index 5ca27f8d0617a74300e43e2c872c4d3dea2b4281..5155c16a7d537d5cb0b0c4d36bdb35d5d9f72064 100644 --- a/security_lite/permission_posix/pms/BUILD.gn +++ b/security_lite/permission_posix/pms/BUILD.gn @@ -25,6 +25,7 @@ hcpptest_suite("ActsPMSTest") { "src/ActsPMSSaveTest.cpp", "src/ActsPMSTest.h", "src/ActsPMSUnloadTest.cpp", + "src/ActsPMSUpdatePermissionTest.cpp" ] include_dirs = [ diff --git a/security_lite/permission_posix/pms/src/ActsPMSTest.h b/security_lite/permission_posix/pms/src/ActsPMSTest.h index 795d95499bbbeb71ab1ce49fe827a612b5411df1..aee83f3577132e9bdf5b43d4aacf587e8f4c343e 100755 --- a/security_lite/permission_posix/pms/src/ActsPMSTest.h +++ b/security_lite/permission_posix/pms/src/ActsPMSTest.h @@ -44,6 +44,8 @@ #define TEST_APP_SHORT "a" #define TEST_APP_LONG "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" #define TEST_APP_PATH "/storage/app/etc/permissions/com.permission.test" +#define TEST_APP_INVALID "com.permission.!@#$%^&*()_+" +#define TEST_APP_NOT_EXIST "com.permission.onetwothree" #define PERMISSION_UNDEFINED "ohos.permission.TEST" #define PERMISSION_TOOLONG "ohos.permission.balabalabalabalabalabalabalabalabalabala" #define PERMISSION_EMPTY "" @@ -65,6 +67,8 @@ const int MAX_PID = 0x7fffffff; const int MIN_PID = 0; const int ABNORMAL_PKG_NUM = 5; const int DIR_MODE = 777; +const int FLAG_NOT_EXIST=123; +const int PERFORMANCE_RUN_TIMES=10000; int IsUserGrant(const char* pname); diff --git a/security_lite/permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp b/security_lite/permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1edcbce9ca7a90662c19e07a20118e0426408da5 --- /dev/null +++ b/security_lite/permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp @@ -0,0 +1,336 @@ +/** + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ActsPMSTest.h" +#include + +using namespace std; +using namespace testing::ext; + +static PmsInnerApi *g_interface; +static PermissionTrans g_systemPers[] = { + { + "ohos.permission.CAMERA", + "for CAMERA use", + INUSE, + }, + { + "ohos.permission.RECORD_AUDIO", + "for RECORD_AUDIO use", + ALWAYS, + }, + { + "ohos.permission.READ_MEDIA_AUDIO", + "for READ_MEDIA_AUDIO use", + INUSE, + }, + { + "ohos.permission.READ_MEDIA_IMAGES", + "for READ_MEDIA_IMAGES use", + ALWAYS, + }, + { + "ohos.permission.READ_MEDIA_VIDEO", + "for READ_MEDIA_VIDEO use", + INUSE, + }, + { + "ohos.permission.WRITE_MEDIA_AUDIO", + "for WRITE_MEDIA_AUDIO use", + ALWAYS, + }, + { + "ohos.permission.WRITE_MEDIA_IMAGES", + "for WRITE_MEDIA_IMAGES use", + INUSE, + }, + { + "ohos.permission.WRITE_MEDIA_VIDEO", + "for WRITE_MEDIA_VIDEO use", + ALWAYS, + }, + { + "ohos.permission.MODIFY_AUDIO_SETTINGS", + "for MODIFY_AUDIO_SETTINGS use", + INUSE, + }, +}; + +class ActsPMSUpdatePermissionTest:public testing::Test{ +protected: + static void SetUpTestCase(void) + { + CreateAppDir(); + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(PERMISSION_SERVICE, PERM_INNER); + iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **) &g_interface); + setuid(0); + } + static void TearDownTestCase(void) {} + virtual void SetUp() {} + virtual void TearDown() + { + DeletePermissions(TEST_APP_ID); + DeletePermissions(TEST_APP_ID2); + DeletePermissions(SUBTEST_APP_ID); + UnLoadPermissions(TEST_TASKID); + UnLoadPermissions(SUBTEST_TASKID); + } +}; + +long GetCurrentTimeMillis() +{ + struct timeval current; + gettimeofday(¤t,NULL); + return current.tv_sec*1000+current.tv_usec/1000; +} + +/** + * @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_001 + * @tc.name Update permission flags + * @tc.desc [C- SECURITY -1000] + */ +HWTEST_F(ActsPMSUpdatePermissionTest,testSecPMUpdatePMFlags_001, + Function | MediumTest | Level2) +{ + SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL); + + PermissionSaved *permissions=NULL; + int permNum=0; + int ret=g_interface->QueryPermission(TEST_APP_ID,&permissions,&permNum); + EXPECT_EQ(ret,PERM_ERRORCODE_SUCCESS)<<"query ret="<