Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
31f0314c
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
31f0314c
编写于
9月 08, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 08, 2021
浏览文件
操作
浏览文件
下载
差异文件
!535 hebin
Merge pull request !535 from Harry John/mybranch
上级
1a51305b
c66b859a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
350 addition
and
7 deletion
+350
-7
security_lite/permission_posix/pms/BUILD.gn
security_lite/permission_posix/pms/BUILD.gn
+1
-0
security_lite/permission_posix/pms/src/ActsPMSTest.h
security_lite/permission_posix/pms/src/ActsPMSTest.h
+12
-7
security_lite/permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp
.../permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp
+337
-0
未找到文件。
security_lite/permission_posix/pms/BUILD.gn
浏览文件 @
31f0314c
...
...
@@ -25,6 +25,7 @@ hcpptest_suite("ActsPMSTest") {
"src/ActsPMSSaveTest.cpp",
"src/ActsPMSTest.h",
"src/ActsPMSUnloadTest.cpp",
"src/ActsPMSUpdatePermissionTest.cpp",
]
include_dirs = [
...
...
security_lite/permission_posix/pms/src/ActsPMSTest.h
浏览文件 @
31f0314c
...
...
@@ -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,19 +67,22 @@ 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
;
const
int
MILLISECOND
=
1000
;
int
IsUserGrant
(
const
char
*
pname
);
int
IsUserGrant
(
const
char
*
pname
);
int
CheckPermData
(
const
PermissionTrans
*
pt
,
const
PermissionSaved
*
ps
,
const
PermissionSaved
*
pre
,
int
len
,
int
plen
);
int
CheckPermData
(
const
PermissionTrans
*
pt
,
const
PermissionSaved
*
ps
,
const
PermissionSaved
*
pre
,
int
len
,
int
plen
);
void
ClrPers
(
PermissionSaved
*
&
permissions
);
void
ClrPers
(
PermissionSaved
*
&
permissions
);
void
CheckAppPermission
(
const
char
*
identifier
,
int
expRet
,
int
expNum
,
const
PermissionTrans
*
installPers
,
const
PermissionSaved
*
lastPers
=
nullptr
,
int
lastLen
=
0
);
void
CheckAppPermission
(
const
char
*
identifier
,
int
expRet
,
int
expNum
,
const
PermissionTrans
*
installPers
,
const
PermissionSaved
*
lastPers
=
nullptr
,
int
lastLen
=
0
);
void
SubTestWithoutCheck
(
const
char
*
identifier
,
int
taskID
);
void
CreateAppDir
(
void
);
#endif // XTS_HITS_TOKEN_API_EXPECT_H
\ No newline at end of file
#endif // XTS_HITS_TOKEN_API_EXPECT_H
\ No newline at end of file
security_lite/permission_posix/pms/src/ActsPMSUpdatePermissionTest.cpp
0 → 100644
浏览文件 @
31f0314c
/**
* 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 <sys/time.h>
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
(
&
current
,
NULL
);
return
current
.
tv_sec
*
MILLISECOND
+
current
.
tv_usec
/
MILLISECOND
;
}
/**
* @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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_DEFAULT
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ret
=
g_interface
->
QueryPermission
(
TEST_APP_ID
,
&
permissions
,
&
permNum
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"query ret="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_002
* @tc.name Update permission flags (No reminds after rejection)
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_002
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ret
=
g_interface
->
QueryPermission
(
TEST_APP_ID
,
&
permissions
,
&
permNum
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"query ret="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_003
* @tc.name Update permission flags (Name does not exist)
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_003
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
// pkg name not exist
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_NOT_EXIST
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_FILE_NOT_EXIST
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
// pkg perm not exist
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
PERMISSION_UNDEFINED
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
// pkg flag not exist
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
FLAG_NOT_EXIST
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_INVALID_PARAMS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_004
* @tc.name Update permission flags (Name empty)
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_004
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
// pkg name empty
ret
=
g_interface
->
UpdatePermissionFlags
(
NULL
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_INVALID_PARAMS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
// pkg perm empty
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
NULL
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_INVALID_PARAMS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
// pkg flag empty
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
NULL
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_005
* @tc.name Update permission flags (Name invalid)
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_005
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
// pkg name invalid
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_INVALID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_FILE_NOT_EXIST
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
// pkg perm invalid
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
PERMISSION_UNSUPPORTED
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_006
* @tc.name Updatepermissionflags interface stability test
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_006
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
for
(
int
i
=
0
;
i
<
PERFORMANCE_RUN_TIMES
/
2
;
i
++
)
{
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_DEFAULT
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
EXPECT_EQ
(
ret
,
PERM_ERRORCODE_SUCCESS
)
<<
"update perms flag ret ="
<<
ret
<<
endl
;
}
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
/**
* @tc.number Security_AppSecurity_PermissionManager_L1_UpdatePermissionFlags_007
* @tc.name Updatepermissionflags interface performace test
* @tc.desc [C- SECURITY -1000]
*/
HWTEST_F
(
ActsPMSUpdatePermissionTest
,
testSecPMUpdatePMFlags_007
,
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="
<<
ret
<<
endl
;
EXPECT_EQ
(
permNum
,
SYS_PERM_NUM
)
<<
"permNum ="
<<
permNum
<<
endl
;
if
(
permissions
!=
NULL
)
{
EXPECT_EQ
(
permissions
[
0
].
flags
,
PMS_FLAG_DEFAULT
)
<<
"flags ="
<<
permissions
[
0
].
flags
<<
endl
;
}
ClrPers
(
permissions
);
long
startTime
=
GetCurrentTimeMillis
();
for
(
int
i
=
0
;
i
<
PERFORMANCE_RUN_TIMES
/
2
;
i
++
)
{
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_DEFAULT
);
ret
=
g_interface
->
UpdatePermissionFlags
(
TEST_APP_ID
,
g_systemPers
[
0
].
name
,
PMS_FLAG_USER_FIXED
);
}
long
timeCost
=
GetCurrentTimeMillis
()
-
startTime
;
long
timeAvg
=
timeCost
/
10000
;
EXPECT_LT
(
timeAvg
,
11
)
<<
"avg times ="
<<
timeAvg
<<
endl
;
ClrPers
(
permissions
);
UnLoadPermissions
(
TEST_TASKID
);
DeletePermissions
(
TEST_APP_ID
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录