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