1 /*
2  * Copyright (c) 2023 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 "accesstoken_kit.h"
17 #include "ces_ut_constant.h"
18 
19 
20 using namespace OHOS::Security::AccessToken;
21 namespace OHOS {
22 namespace EventFwk {
23 namespace {
24 ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID;
25 DlpType g_mockDlpType = DlpType::DLP_COMMON;
26 ATokenAplEnum g_mockApl = ATokenAplEnum::APL_NORMAL;
27 bool g_mockVerfyPermisson = true;
28 }
29 
MockGetTokenTypeFlag(ATokenTypeEnum mockRet)30 void MockGetTokenTypeFlag(ATokenTypeEnum mockRet)
31 {
32     g_mockGetTokenTypeFlagRet = mockRet;
33 }
MockDlpType(DlpType mockRet)34 void MockDlpType(DlpType mockRet)
35 {
36     g_mockDlpType = mockRet;
37 }
MockApl(ATokenAplEnum mockRet)38 void MockApl(ATokenAplEnum mockRet)
39 {
40     g_mockApl = mockRet;
41 }
42 
MockIsVerfyPermisson(bool isVerify)43 void MockIsVerfyPermisson(bool isVerify)
44 {
45     g_mockVerfyPermisson = isVerify;
46 }
47 }
48 }
49 namespace OHOS {
50 namespace Security {
51 namespace AccessToken {
VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)52 int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName)
53 {
54     if (!EventFwk::g_mockVerfyPermisson) {
55         return PERMISSION_DENIED;
56     }
57 
58     if (tokenID == EventFwk::NON_NATIVE_TOKEN) {
59         return PERMISSION_DENIED;
60     }
61     return PERMISSION_GRANTED;
62 }
63 
GetTokenTypeFlag(AccessTokenID tokenID)64 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID)
65 {
66     return EventFwk::g_mockGetTokenTypeFlagRet;
67 }
68 
GetHapTokenInfo(AccessTokenID tokenID,HapTokenInfo & info)69 int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& info)
70 {
71     info.dlpType = EventFwk::g_mockDlpType;
72     info.apl = EventFwk::g_mockApl;
73     return 0;
74 }
75 } // namespace AccessToken
76 } // namespace Security
77 } // namespace OHOS
78