1 /*
2 * Copyright (c) 2024 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 #include <gtest/gtest.h>
17 #include "avsession_log.h"
18 #include "avsession_errors.h"
19 #include "ipc_skeleton.h"
20 #include "timer.h"
21 #define private public
22 #define protected public
23 #include "permission_checker.h"
24 #undef protected
25 #undef private
26
27 using namespace OHOS;
28 using namespace OHOS::AVSession;
29 using namespace Security::AccessToken;
30
31 class PermissionCheckerTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void PermissionCheckerTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void PermissionCheckerTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void PermissionCheckerTest::SetUp()
48 {
49 }
50
TearDown()51 void PermissionCheckerTest::TearDown()
52 {
53 }
54
55 /**
56 * @tc.name: CheckSystemPermission001
57 * @tc.desc: Test CheckSystemPermission
58 * @tc.type: FUNC
59 */
60 static HWTEST_F(PermissionCheckerTest, CheckSystemPermission001, testing::ext::TestSize.Level1)
61 {
62 SLOGI("CheckSystemPermission001 begin!");
63 auto permissionChecker = PermissionChecker::GetInstance();
64 AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID();
65 bool ret = permissionChecker.CheckSystemPermission(tokenId);
66 EXPECT_EQ(ret, true);
67 SLOGI("CheckSystemPermission001 end!");
68 }
69
70 /**
71 * @tc.name: CheckPermission001
72 * @tc.desc: Test CheckSystemPermission
73 * @tc.type: FUNC
74 */
75 static HWTEST_F(PermissionCheckerTest, CheckPermission001, testing::ext::TestSize.Level1)
76 {
77 SLOGI("CheckPermission001 begin!");
78 auto permissionChecker = PermissionChecker::GetInstance();
79 bool ret = permissionChecker.CheckPermission(-1);
80 EXPECT_EQ(ret, false);
81 SLOGI("CheckPermission001 end!");
82 }
83
84 /**
85 * @tc.name: CheckSystemPermissionByUid001
86 * @tc.desc: Test CheckSystemPermissionByUid
87 * @tc.type: FUNC
88 */
89 static HWTEST_F(PermissionCheckerTest, CheckSystemPermissionByUid001, testing::ext::TestSize.Level1)
90 {
91 SLOGI("CheckSystemPermissionByUid001 begin!");
92 auto permissionChecker = PermissionChecker::GetInstance();
93 bool ret = permissionChecker.CheckSystemPermissionByUid(-1);
94 EXPECT_EQ(ret, true);
95 SLOGI("CheckSystemPermissionByUid001 end!");
96 }
97