• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 
17 #include "acts_pms_test.h"
18 
19 using namespace std;
20 using namespace testing::ext;
21 
22 static PmsInnerApi *g_interface;
23 static PermissionTrans g_systemPers[] = {
24     {
25         "ohos.permission.CAMERA",
26         "for test use",
27         INUSE,
28     },
29     {
30         "ohos.permission.RECORD_AUDIO",
31         "for test use",
32         INUSE,
33     },
34     {
35         "ohos.permission.READ_MEDIA_AUDIO",
36         "for test use",
37         INUSE,
38     },
39     {
40         "ohos.permission.READ_MEDIA_IMAGES",
41         "for test use",
42         INUSE,
43     },
44     {
45         "ohos.permission.READ_MEDIA_VIDEO",
46         "for test use",
47         INUSE,
48     },
49     {
50         "ohos.permission.WRITE_MEDIA_AUDIO",
51         "for test use",
52         INUSE,
53     },
54     {
55         "ohos.permission.WRITE_MEDIA_IMAGES",
56         "for test use",
57         INUSE,
58     },
59     {
60         "ohos.permission.WRITE_MEDIA_VIDEO",
61         "for test use",
62         INUSE,
63     },
64     {
65         "ohos.permission.MODIFY_AUDIO_SETTINGS",
66         "for test use",
67         INUSE,
68     },
69 };
70 
CreateAppDir(void)71 void CreateAppDir(void)
72 {
73     int ret = mkdir(APP_PREFIX, DIR_MODE);
74     if (ret) {
75         printf("create dir %s error\n", APP_PREFIX);
76     }
77     ret = mkdir(ETC_PREFIX, DIR_MODE);
78     if (ret) {
79         printf("create dir %s error\n", ETC_PREFIX);
80     }
81     ret = mkdir(PERMISSION_PREFIX, DIR_MODE);
82     if (ret) {
83         printf("create dir %s error\n", PERMISSION_PREFIX);
84     }
85 }
86 
87 class ActsPMSCheckTest : public testing::Test {
88 public:
InitInterface()89     static void InitInterface()
90     {
91         if (g_interface != NULL) {
92             return;
93         }
94         SetUpTestCase();
95     }
96 
97 protected:
SetUpTestCase(void)98     static void SetUpTestCase(void)
99     {
100         CreateAppDir();
101         IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(PERMISSION_SERVICE, PERM_INNER);
102         iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&g_interface);
103         setuid(0);
104     }
TearDownTestCase(void)105     static void TearDownTestCase(void) {}
SetUp()106     virtual void SetUp() {}
TearDown()107     virtual void TearDown()
108     {
109         DeletePermissions(TEST_APP_ID);
110         DeletePermissions(TEST_APP_ID2);
111         DeletePermissions(SUBTEST_APP_ID);
112         UnLoadPermissions(TEST_TASKID);
113         UnLoadPermissions(SUBTEST_TASKID);
114     }
115 };
116 
117 
118 /*
119  ** @tc.name: testSecPMPMS_001
120  ** @tc.desc: check permission tp large and small PIDS
121  ** @tc.type: FUNC
122  ** @tc.require: test
123  */
124 
125 HWTEST_F(ActsPMSCheckTest, testSecPMPMS_001, Function | MediumTest | Level0)
126 {
127     SaveOrUpdatePermissions(TEST_APP_ID, g_systemPers, SYS_PERM_NUM, FIRST_INSTALL);
128     LoadPermissions(TEST_APP_ID, MAX_PID);
129     g_interface->GrantRuntimePermission(MAX_PID, g_systemPers[0].name);
130     int ret = g_interface->CheckPermission(MAX_PID, g_systemPers[0].name);
131     EXPECT_EQ(ret, GRANTED) << "checkpermission ret= " << ret << endl;
132     UnLoadPermissions(MAX_PID);
133     LoadPermissions(TEST_APP_ID, MIN_PID);
134     g_interface->GrantRuntimePermission(MIN_PID, g_systemPers[0].name);
135     ret = g_interface->CheckPermission(MIN_PID, g_systemPers[0].name);
136     EXPECT_EQ(ret, GRANTED) << "checkpermission ret= " << ret << endl;
137     UnLoadPermissions(MIN_PID);
138     DeletePermissions(TEST_APP_ID);
139 }
140