• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License") = 0;
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 #ifndef OHOS_DM_ACCESS_TOKEN_KIT_MOCK_H
17 #define OHOS_DM_ACCESS_TOKEN_KIT_MOCK_H
18 
19 #include <gmock/gmock.h>
20 
21 #include "accesstoken_kit.h"
22 #include "tokenid_kit.h"
23 
24 using OHOS::Security::AccessToken::ATokenTypeEnum;
25 using OHOS::Security::AccessToken::AccessTokenID;
26 using OHOS::Security::AccessToken::HapTokenInfo;
27 using OHOS::Security::AccessToken::NativeTokenInfo;
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 class AccessTokenKitInterface {
32 public:
33     AccessTokenKitInterface() = default;
34     virtual ~AccessTokenKitInterface() = default;
35 
36     virtual ATokenTypeEnum GetTokenTypeFlag(AccessTokenID) = 0;
37     virtual int GetHapTokenInfo(AccessTokenID, HapTokenInfo &) = 0;
38     virtual int GetNativeTokenInfo(AccessTokenID, NativeTokenInfo &) = 0;
39     virtual AccessTokenID GetNativeTokenId(const std::string &) = 0;
40     virtual AccessTokenID GetHapTokenID(int32_t, const std::string &, int32_t) = 0;
41     virtual int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) = 0;
42 
43     static std::shared_ptr<AccessTokenKitInterface> GetOrCreateAccessTokenKit();
44     static void ReleaseAccessTokenKit();
45 private:
46     static std::shared_ptr<AccessTokenKitInterface> token_;
47 };
48 
49 class AccessTokenKitMock : public AccessTokenKitInterface {
50 public:
51     AccessTokenKitMock() = default;
52     ~AccessTokenKitMock() override = default;
53 
54     MOCK_METHOD(ATokenTypeEnum, GetTokenTypeFlag, (AccessTokenID));
55     MOCK_METHOD(int, GetHapTokenInfo, (AccessTokenID, HapTokenInfo &));
56     MOCK_METHOD(int, GetNativeTokenInfo, (AccessTokenID, NativeTokenInfo &));
57     MOCK_METHOD(AccessTokenID, GetNativeTokenId, (const std::string &));
58     MOCK_METHOD(AccessTokenID, GetHapTokenID, (int32_t, const std::string &, int32_t));
59     MOCK_METHOD(int, VerifyAccessToken, (AccessTokenID, const std::string&));
60 };
61 } // namespace DistributedHardware
62 } // namespace OHOS
63 #endif // OHOS_DM_ACCESS_TOKEN_KIT_MOCK_H
64