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_ut_constant.h" 18 #include "ipc_skeleton.h" 19 20 using namespace OHOS::Security::AccessToken; 21 namespace OHOS { 22 namespace Notification { 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 bool g_isSystemApp = false; 29 bool g_isAtomicService = false; 30 } 31 MockGetTokenTypeFlag(ATokenTypeEnum mockRet)32void MockGetTokenTypeFlag(ATokenTypeEnum mockRet) 33 { 34 g_mockGetTokenTypeFlagRet = mockRet; 35 } MockDlpType(DlpType mockRet)36void MockDlpType(DlpType mockRet) 37 { 38 g_mockDlpType = mockRet; 39 } MockApl(ATokenAplEnum mockRet)40void MockApl(ATokenAplEnum mockRet) 41 { 42 g_mockApl = mockRet; 43 } 44 MockIsVerfyPermisson(bool isVerify)45void MockIsVerfyPermisson(bool isVerify) 46 { 47 g_mockVerfyPermisson = isVerify; 48 } 49 MockIsSystemAppByFullTokenID(bool isSystemApp)50void MockIsSystemAppByFullTokenID(bool isSystemApp) 51 { 52 g_isSystemApp = isSystemApp; 53 } 54 MockIsAtomicServiceByFullTokenID(bool isAtomicService)55void MockIsAtomicServiceByFullTokenID(bool isAtomicService) 56 { 57 g_isAtomicService = isAtomicService; 58 } 59 } 60 } 61 namespace OHOS { 62 namespace Security { 63 namespace AccessToken { VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)64int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) 65 { 66 if (!Notification::g_mockVerfyPermisson) { 67 return PERMISSION_DENIED; 68 } 69 70 if (tokenID == Notification::NON_NATIVE_TOKEN) { 71 return PERMISSION_DENIED; 72 } 73 return PERMISSION_GRANTED; 74 } 75 GetTokenTypeFlag(AccessTokenID tokenID)76ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) 77 { 78 return Notification::g_mockGetTokenTypeFlagRet; 79 } 80 GetHapTokenInfo(AccessTokenID tokenID,HapTokenInfo & info)81int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& info) 82 { 83 info.dlpType = Notification::g_mockDlpType; 84 return 0; 85 } 86 IsSystemAppByFullTokenID(uint64_t tokenId)87bool AccessTokenKit::IsSystemAppByFullTokenID(uint64_t tokenId) 88 { 89 return Notification::g_isSystemApp; 90 } 91 IsAtomicServiceByFullTokenID(uint64_t tokenId)92bool AccessTokenKit::IsAtomicServiceByFullTokenID(uint64_t tokenId) 93 { 94 return Notification::g_isAtomicService; 95 } 96 } // namespace AccessToken 97 } // namespace Security 98 } // namespace OHOS 99