• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 <memory>
18 #include <string>
19 #include <fcntl.h>
20 
21 #include "access_token_error.h"
22 #include "constant_common.h"
23 #define private public
24 #include "permission_map.h"
25 #undef private
26 
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Security {
31 namespace AccessToken {
32 namespace {
33 const static uint32_t MAX_PERM_SIZE = 2048;
34 }
35 class CommonTest : public testing::Test  {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39 
40     void SetUp();
41     void TearDown();
42 };
43 
SetUpTestCase()44 void CommonTest::SetUpTestCase() {}
TearDownTestCase()45 void CommonTest::TearDownTestCase() {}
SetUp()46 void CommonTest::SetUp() {}
TearDown()47 void CommonTest::TearDown() {}
48 
49 /**
50  * @tc.name: EncryptDevId001
51  * @tc.desc: Test EncryptDevId001 function.
52  * @tc.type: FUNC
53  * @tc.require: issueI5RUCC
54  */
55 HWTEST_F(CommonTest, EncryptDevId001, TestSize.Level1)
56 {
57     std::string res;
58     res = ConstantCommon::EncryptDevId("");
59     EXPECT_EQ(res, "");
60 
61     res = ConstantCommon::EncryptDevId("12345");
62     EXPECT_EQ(res, "1*******");
63 
64     res = ConstantCommon::EncryptDevId("123454321");
65     EXPECT_EQ(res, "1234****4321");
66 }
67 
68 /*
69  * @tc.name: TransferOpcodeToPermission001
70  * @tc.desc: TransferOpcodeToPermission function test
71  * @tc.type: FUNC
72  * @tc.require: issueI6024A
73  */
74 HWTEST_F(CommonTest, TransferOpcodeToPermission001, TestSize.Level1)
75 {
76     std::string permissionName;
77     uint32_t opCode;
78     EXPECT_TRUE(TransferPermissionToOpcode("ohos.permission.ANSWER_CALL", opCode));
79     EXPECT_TRUE(TransferOpcodeToPermission(opCode, permissionName));
80     EXPECT_EQ(permissionName, "ohos.permission.ANSWER_CALL");
81 }
82 
83 /*
84  * @tc.name: TransferOpcodeToPermission002
85  * @tc.desc: TransferOpcodeToPermission code oversize
86  * @tc.type: FUNC
87  * @tc.require: issueI6024A
88  */
89 HWTEST_F(CommonTest, TransferOpcodeToPermission002, TestSize.Level1)
90 {
91     std::string permissionName;
92     EXPECT_FALSE(TransferOpcodeToPermission(MAX_PERM_SIZE, permissionName));
93     EXPECT_FALSE(TransferOpcodeToPermission(MAX_PERM_SIZE - 1, permissionName));
94 }
95 
96 /*
97  * @tc.name: PermissionDefineMapTest
98  * @tc.desc: Test find permission difinition
99  * @tc.type: FUNC
100  * @tc.require:IBRDIV
101  */
102 HWTEST_F(CommonTest, PermissionDefineMapTest, TestSize.Level1)
103 {
104     EXPECT_TRUE(IsDefinedPermission("ohos.permission.ANSWER_CALL"));
105     PermissionBriefDef permDef;
106     EXPECT_TRUE(GetPermissionBriefDef("ohos.permission.ANSWER_CALL", permDef));
107     EXPECT_TRUE(strcmp("ohos.permission.ANSWER_CALL", permDef.permissionName) == 0);
108 }
109 } // namespace AccessToken
110 } // namespace Security
111 } // namespace OHOS
112