• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <algorithm>
17 #include <fstream>
18 #include <functional>
19 #include <iostream>
20 #include <map>
21 #include <memory>
22 #include <thread>
23 
24 #define private public
25 #include "remote_command_executor.h"
26 #include "token_sync_manager_service.h"
27 #undef private
28 
29 #include "gtest/gtest.h"
30 #include "accesstoken_kit.h"
31 #include "accesstoken_common_log.h"
32 #include "access_token_error.h"
33 #include "base_remote_command.h"
34 #include "constant_common.h"
35 #include "delete_remote_token_command.h"
36 #include "device_info_manager.h"
37 #include "device_info_repository.h"
38 #include "device_info.h"
39 #include "device_manager.h"
40 #include "device_manager_callback.h"
41 #include "dm_device_info.h"
42 #include "i_token_sync_manager.h"
43 #define private public
44 #include "remote_command_manager.h"
45 #undef private
46 #include "socket.h"
47 #include "soft_bus_device_connection_listener.h"
48 #include "soft_bus_socket_listener.h"
49 #include "token_setproc.h"
50 #include "token_sync_manager_stub.h"
51 
52 using namespace std;
53 using namespace testing::ext;
54 
55 namespace OHOS {
56 namespace Security {
57 namespace AccessToken {
58 static std::vector<std::thread> threads_;
59 static std::shared_ptr<SoftBusDeviceConnectionListener> g_ptrDeviceStateCallback =
60     std::make_shared<SoftBusDeviceConnectionListener>();
61 static std::string g_udid = "deviceid-1:udid-001";
62 static int32_t g_selfUid;
63 static AccessTokenID g_selfTokenId = 0;
64 static const int32_t OUT_OF_MAP_SOCKET = 2;
65 
66 class TokenSyncServiceTest : public testing::Test {
67 public:
68     TokenSyncServiceTest();
69     ~TokenSyncServiceTest();
70     static void SetUpTestCase();
71     static void TearDownTestCase();
72     void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &info);
73     void SetUp();
74     void TearDown();
75     std::shared_ptr<TokenSyncManagerService> tokenSyncManagerService_;
76 };
77 
78 static DistributedHardware::DmDeviceInfo g_devInfo = {
79     // udid = deviceid-1:udid-001  uuid = deviceid-1:uuid-001
80     .deviceId = "deviceid-1",
81     .deviceName = "remote_mock",
82     .deviceTypeId = 1,
83     .networkId = "deviceid-1"
84 };
85 
86 namespace {
87 static constexpr int MAX_RETRY_TIMES = 10;
88 static constexpr int32_t DEVICEID_MAX_LEN = 256;
89 }
90 
TokenSyncServiceTest()91 TokenSyncServiceTest::TokenSyncServiceTest()
92 {
93     DelayedSingleton<TokenSyncManagerService>::GetInstance()->Initialize();
94 }
~TokenSyncServiceTest()95 TokenSyncServiceTest::~TokenSyncServiceTest()
96 {}
97 
NativeTokenGet()98 void NativeTokenGet()
99 {
100     uint64_t tokenId = 0;
101     tokenId = AccessTokenKit::GetNativeTokenId("token_sync_service");
102     ASSERT_NE(tokenId, static_cast<AccessTokenID>(0));
103     EXPECT_EQ(0, SetSelfTokenID(tokenId));
104 }
105 
SetUpTestCase()106 void TokenSyncServiceTest::SetUpTestCase()
107 {
108     g_selfUid = getuid();
109     g_selfTokenId = GetSelfTokenID();
110     NativeTokenGet();
111 }
TearDownTestCase()112 void TokenSyncServiceTest::TearDownTestCase()
113 {}
SetUp()114 void TokenSyncServiceTest::SetUp()
115 {
116     tokenSyncManagerService_ = DelayedSingleton<TokenSyncManagerService>::GetInstance();
117     EXPECT_NE(nullptr, tokenSyncManagerService_);
118 }
TearDown()119 void TokenSyncServiceTest::TearDown()
120 {
121     LOGI(ATM_DOMAIN, ATM_TAG, "TearDown start.");
122     tokenSyncManagerService_ = nullptr;
123     for (auto it = threads_.begin(); it != threads_.end(); it++) {
124         it->join();
125     }
126     threads_.clear();
127 
128     if (g_ptrDeviceStateCallback != nullptr) {
129         OnDeviceOffline(g_devInfo);
130         sleep(1);
131     }
132 }
133 
OnDeviceOffline(const DistributedHardware::DmDeviceInfo & info)134 void TokenSyncServiceTest::OnDeviceOffline(const DistributedHardware::DmDeviceInfo &info)
135 {
136     std::string networkId = info.networkId;
137     std::string uuid = DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(networkId);
138     std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(networkId);
139 
140     LOGI(ATM_DOMAIN, ATM_TAG,
141         "networkId: %{public}s,  uuid: %{public}s, udid: %{public}s",
142         networkId.c_str(),
143         uuid.c_str(),
144         ConstantCommon::EncryptDevId(udid).c_str());
145 
146     if (uuid != "" && udid != "") {
147         RemoteCommandManager::GetInstance().NotifyDeviceOffline(uuid);
148         RemoteCommandManager::GetInstance().NotifyDeviceOffline(udid);
149         DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(networkId, DeviceIdType::NETWORK_ID);
150     } else {
151         LOGE(ATM_DOMAIN, ATM_TAG, "uuid or udid is empty, offline failed.");
152     }
153 }
154 
155 namespace {
156     std::string g_jsonBefore;
157     std::string g_jsonAfter;
158 }
159 
SendTaskThread()160 void SendTaskThread()
161 {
162     int count = 0;
163     while (!GetSendMessFlagMock() && count < MAX_RETRY_TIMES) {
164         sleep(1);
165         count++;
166     }
167 
168     ResetSendMessFlagMock();
169 
170     std::string uuidMessage = GetUuidMock();
171     std::string sendJson = g_jsonBefore + uuidMessage + g_jsonAfter;
172 
173     unsigned char *sendBuffer = (unsigned char *)malloc(0x1000);
174     if (sendBuffer == nullptr) {
175         return;
176     }
177     int sendLen = 0x1000;
178     CompressMock(sendJson, sendBuffer, sendLen);
179 
180     SoftBusSocketListener::OnClientBytes(1, sendBuffer, sendLen);
181     free(sendBuffer);
182 }
183 
184 static PermissionDef g_infoManagerTestPermDef1 = {
185     .permissionName = "ohos.permission.test1",
186     .bundleName = "accesstoken_test",
187     .grantMode = 1,
188     .availableLevel = APL_NORMAL,
189     .label = "label",
190     .labelId = 1,
191     .description = "open the door",
192     .descriptionId = 1
193 };
194 
195 static PermissionDef g_infoManagerTestPermDef2 = {
196     .permissionName = "ohos.permission.test2",
197     .bundleName = "accesstoken_test",
198     .grantMode = 1,
199     .availableLevel = APL_NORMAL,
200     .label = "label",
201     .labelId = 1,
202     .description = "break the door",
203     .descriptionId = 1
204 };
205 
206 static PermissionStateFull g_infoManagerTestState1 = {
207     .permissionName = "ohos.permission.test1",
208     .isGeneral = true,
209     .resDeviceID = {"local"},
210     .grantStatus = {PermissionState::PERMISSION_GRANTED},
211     .grantFlags = {1}
212 };
213 
214 static PermissionStateFull g_infoManagerTestState2 = {
215     .permissionName = "ohos.permission.test2",
216     .isGeneral = false,
217     .resDeviceID = {"device 1", "device 2"},
218     .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED},
219     .grantFlags = {1, 2}
220 };
221 
222 static HapInfoParams g_infoManagerTestInfoParms = {
223     .userID = 1,
224     .bundleName = "accesstoken_test",
225     .instIndex = 0,
226     .appIDDesc = "testtesttesttest"
227 };
228 
229 static HapPolicyParams g_infoManagerTestPolicyPrams = {
230     .apl = APL_NORMAL,
231     .domain = "test.domain",
232     .permList = {g_infoManagerTestPermDef1, g_infoManagerTestPermDef2},
233     .permStateList = {g_infoManagerTestState1, g_infoManagerTestState2}
234 };
235 
236 class TestBaseRemoteCommand : public BaseRemoteCommand {
237 public:
Prepare()238     void Prepare() override {}
239 
Execute()240     void Execute() override {}
241 
Finish()242     void Finish() override {}
243 
ToJsonPayload()244     std::string ToJsonPayload() override
245     {
246         return std::string();
247     }
248 
TestBaseRemoteCommand()249     TestBaseRemoteCommand() {}
250     virtual ~TestBaseRemoteCommand() = default;
251 };
252 
DeleteAndAllocToken(AccessTokenID & tokenId)253 static void DeleteAndAllocToken(AccessTokenID& tokenId)
254 {
255     // create local token
256     AccessTokenID tokenID = AccessTokenKit::GetHapTokenID(g_infoManagerTestInfoParms.userID,
257         g_infoManagerTestInfoParms.bundleName, g_infoManagerTestInfoParms.instIndex);
258     AccessTokenKit::DeleteToken(tokenID);
259 
260     AccessTokenIDEx tokenIdEx = {0};
261     tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams);
262     ASSERT_NE(static_cast<AccessTokenID>(0), tokenIdEx.tokenIdExStruct.tokenID);
263 
264     tokenId = tokenIdEx.tokenIdExStruct.tokenID;
265 }
266 
267 /**
268  * @tc.name: ProcessOneCommand001
269  * @tc.desc: RemoteCommandExecutor::ProcessOneCommand function test with nullptr
270  * @tc.type: FUNC
271  * @tc.require:
272  */
273 HWTEST_F(TokenSyncServiceTest, ProcessOneCommand001, TestSize.Level1)
274 {
275     std::string nodeId = "test_nodeId";
276     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
277     EXPECT_EQ(Constant::SUCCESS, executor->ProcessOneCommand(nullptr));
278 }
279 
280 /**
281  * @tc.name: ProcessOneCommand002
282  * @tc.desc: RemoteCommandExecutor::ProcessOneCommand function test
283  * @tc.type: FUNC
284  * @tc.require:
285  */
286 HWTEST_F(TokenSyncServiceTest, ProcessOneCommand002, TestSize.Level1)
287 {
288     std::string nodeId = "test_nodeId";
289     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
290     auto cmd = std::make_shared<TestBaseRemoteCommand>();
291     cmd->remoteProtocol_.statusCode = Constant::FAILURE;
292     EXPECT_EQ(Constant::FAILURE, executor->ProcessOneCommand(cmd));
293 }
294 
295 /**
296  * @tc.name: ProcessOneCommand003
297  * @tc.desc: RemoteCommandExecutor::ProcessOneCommand function test with status code 0
298  * @tc.type: FUNC
299  * @tc.require:
300  */
301 HWTEST_F(TokenSyncServiceTest, ProcessOneCommand003, TestSize.Level1)
302 {
303     std::string nodeId = ConstantCommon::GetLocalDeviceId();
304     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
305     auto cmd = std::make_shared<TestBaseRemoteCommand>();
306     cmd->remoteProtocol_.statusCode = Constant::SUCCESS;
307     EXPECT_EQ(Constant::FAILURE, executor->ProcessOneCommand(cmd));
308 }
309 
310 /**
311  * @tc.name: AddCommand001
312  * @tc.desc: RemoteCommandExecutor::AddCommand function test with nullptr
313  * @tc.type: FUNC
314  * @tc.require:
315  */
316 HWTEST_F(TokenSyncServiceTest, AddCommand001, TestSize.Level1)
317 {
318     std::string nodeId = "test_nodeId";
319     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
320     EXPECT_EQ(Constant::INVALID_COMMAND, executor->AddCommand(nullptr));
321 }
322 
323 /**
324  * @tc.name: AddCommand002
325  * @tc.desc: RemoteCommandExecutor::AddCommand function test
326  * @tc.type: FUNC
327  * @tc.require:
328  */
329 HWTEST_F(TokenSyncServiceTest, AddCommand002, TestSize.Level1)
330 {
331     std::string nodeId = "test_nodeId";
332     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
333     auto cmd = std::make_shared<TestBaseRemoteCommand>();
334     EXPECT_EQ(Constant::SUCCESS, executor->AddCommand(cmd));
335 }
336 
337 /**
338  * @tc.name: ProcessBufferedCommands001
339  * @tc.desc: RemoteCommandExecutor::ProcessBufferedCommands function test
340  * @tc.type: FUNC
341  * @tc.require:
342  */
343 HWTEST_F(TokenSyncServiceTest, ProcessBufferedCommands001, TestSize.Level1)
344 {
345     std::string nodeId = "test_nodeId";
346     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
347     executor->commands_.clear();
348     EXPECT_EQ(Constant::SUCCESS, executor->ProcessBufferedCommands());
349 }
350 
351 /**
352  * @tc.name: ProcessBufferedCommands002
353  * @tc.desc: RemoteCommandExecutor::ProcessBufferedCommands function test
354  * @tc.type: FUNC
355  * @tc.require:
356  */
357 HWTEST_F(TokenSyncServiceTest, ProcessBufferedCommands002, TestSize.Level1)
358 {
359     std::string nodeId = "test_nodeId";
360     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
361     auto cmd = std::make_shared<TestBaseRemoteCommand>();
362     executor->commands_.emplace_back(cmd);
363     EXPECT_EQ(Constant::SUCCESS, executor->ProcessBufferedCommands());
364 }
365 
366 /**
367  * @tc.name: ProcessBufferedCommands003
368  * @tc.desc: RemoteCommandExecutor::ProcessBufferedCommands function test
369  * @tc.type: FUNC
370  * @tc.require:
371  */
372 HWTEST_F(TokenSyncServiceTest, ProcessBufferedCommands003, TestSize.Level1)
373 {
374     std::string nodeId = "test_nodeId";
375     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
376     auto cmd = std::make_shared<TestBaseRemoteCommand>();
377     cmd->remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY;
378     executor->commands_.emplace_back(cmd);
379     EXPECT_EQ(Constant::FAILURE, executor->ProcessBufferedCommands());
380 }
381 
382 /**
383  * @tc.name: ProcessBufferedCommands004
384  * @tc.desc: RemoteCommandExecutor::ProcessBufferedCommands function test
385  * @tc.type: FUNC
386  * @tc.require:
387  */
388 HWTEST_F(TokenSyncServiceTest, ProcessBufferedCommands004, TestSize.Level1)
389 {
390     std::string nodeId = "test_nodeId";
391     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
392     auto cmd = std::make_shared<TestBaseRemoteCommand>();
393     cmd->remoteProtocol_.statusCode = -3; // other error code
394     executor->commands_.emplace_back(cmd);
395     EXPECT_EQ(Constant::SUCCESS, executor->ProcessBufferedCommands());
396 }
397 
398 /**
399  * @tc.name: ClientProcessResult001
400  * @tc.desc: RemoteCommandExecutor::ClientProcessResult function test
401  * @tc.type: FUNC
402  * @tc.require:
403  */
404 HWTEST_F(TokenSyncServiceTest, ClientProcessResult001, TestSize.Level1)
405 {
406     std::string nodeId = "test_nodeId";
407     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
408     auto cmd = std::make_shared<TestBaseRemoteCommand>();
409     cmd->remoteProtocol_.statusCode = Constant::STATUS_CODE_BEFORE_RPC;
410     EXPECT_EQ(Constant::FAILURE, executor->ClientProcessResult(cmd));
411 }
412 
413 /**
414  * @tc.name: ClientProcessResult002
415  * @tc.desc: RemoteCommandExecutor::ClientProcessResult function test
416  * @tc.type: FUNC
417  * @tc.require:
418  */
419 HWTEST_F(TokenSyncServiceTest, ClientProcessResult002, TestSize.Level1)
420 {
421     std::string nodeId = ConstantCommon::GetLocalDeviceId();
422     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
423     auto cmd = std::make_shared<TestBaseRemoteCommand>();
424     cmd->remoteProtocol_.statusCode = Constant::SUCCESS;
425     EXPECT_EQ(Constant::SUCCESS, executor->ClientProcessResult(cmd));
426     cmd->remoteProtocol_.statusCode = Constant::FAILURE;
427     EXPECT_EQ(Constant::FAILURE, executor->ClientProcessResult(cmd));
428 }
429 
430 /**
431  * @tc.name: ToNativeTokenInfoJson001
432  * @tc.desc: ToNativeTokenInfoJson function test
433  * @tc.type: FUNC
434  * @tc.require:
435  */
436 HWTEST_F(TokenSyncServiceTest, ToNativeTokenInfoJson001, TestSize.Level1)
437 {
438     NativeTokenInfoBase native1 = {
439         .ver = 1,
440         .processName = "token_sync_test",
441         .dcap = {"AT_CAP"},
442         .tokenID = 1,
443         .tokenAttr = 0,
444         .nativeAcls = {},
445     };
446     auto cmd = std::make_shared<TestBaseRemoteCommand>();
447     EXPECT_NE(nullptr, cmd->ToNativeTokenInfoJson(native1));
448 }
449 
450 /**
451  * @tc.name: FromPermStateListJson001
452  * @tc.desc: FromPermStateListJson function test
453  * @tc.type: FUNC
454  * @tc.require:
455  */
456 HWTEST_F(TokenSyncServiceTest, FromPermStateListJson001, TestSize.Level1)
457 {
458     HapTokenInfo baseInfo = {
459         .ver = 1,
460         .userID = 1,
461         .bundleName = "com.ohos.access_token",
462         .instIndex = 1,
463         .tokenID = 0x20100000,
464         .tokenAttr = 0
465     };
466 
467     PermissionStatus infoManagerTestState = {
468         .permissionName = "ohos.permission.test1",
469         .grantStatus = PermissionState::PERMISSION_GRANTED,
470         .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
471     std::vector<PermissionStatus> permStateList;
472     permStateList.emplace_back(infoManagerTestState);
473 
474     HapTokenInfoForSync remoteTokenInfo = {
475         .baseInfo = baseInfo,
476         .permStateList = permStateList
477     };
478     CJsonUnique hapTokenJson;
479     auto cmd = std::make_shared<TestBaseRemoteCommand>();
480     hapTokenJson = cmd->ToHapTokenInfosJson(remoteTokenInfo);
481 
482     HapTokenInfoForSync hap;
483     cmd->FromHapTokenBasicInfoJson(hapTokenJson.get(), hap.baseInfo);
484     cmd->FromPermStateListJson(hapTokenJson.get(), hap.permStateList);
485 
486     PermissionStatus state1 = {
487         .permissionName = "ohos.permission.test1",
488         .grantStatus = PermissionState::PERMISSION_GRANTED,
489         .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
490     CJsonUnique permStateJson = CreateJson();
491     cmd->ToPermStateJson(permStateJson.get(), state1);
492 
493     PermissionStatus state2 = {
494         .permissionName = "ohos.permission.test1",
495         .grantStatus = PermissionState::PERMISSION_GRANTED,
496         .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
497     cmd->ToPermStateJson(permStateJson.get(), state2);
498 
499     EXPECT_EQ(hap.baseInfo.tokenID, remoteTokenInfo.baseInfo.tokenID);
500 }
501 
502 /**
503  * @tc.name: FromNativeTokenInfoJson001
504  * @tc.desc: FromNativeTokenInfoJson function test
505  * @tc.type: FUNC
506  * @tc.require:
507  */
508 HWTEST_F(TokenSyncServiceTest, FromNativeTokenInfoJson001, TestSize.Level1)
509 {
510     auto cmd = std::make_shared<TestBaseRemoteCommand>();
511 
512     CJsonUnique nativeTokenListJsonNull = CreateJson();
513     NativeTokenInfoBase tokenNull;
514     cmd->FromNativeTokenInfoJson(nativeTokenListJsonNull.get(), tokenNull);
515 
516     CJsonUnique hapTokenJsonNull = CreateJson();
517     HapTokenInfo hapTokenBasicInfoNull;
518     cmd->FromHapTokenBasicInfoJson(hapTokenJsonNull.get(), hapTokenBasicInfoNull);
519 
520     NativeTokenInfoBase native1 = {
521         .apl = APL_NORMAL,
522         .ver = 2,
523         .processName = "token_sync_test",
524         .dcap = {"AT_CAP"},
525         .tokenID = 1,
526         .tokenAttr = 0,
527         .nativeAcls = {},
528     };
529 
530     CJsonUnique nativeTokenListJson = cmd->ToNativeTokenInfoJson(native1);
531     NativeTokenInfoBase token;
532     cmd->FromNativeTokenInfoJson(nativeTokenListJson.get(), token);
533     EXPECT_EQ(token.processName, "token_sync_test");
534     EXPECT_EQ(token.apl, ATokenAplEnum::APL_NORMAL);
535 }
536 
537 /**
538  * @tc.name: FromPermStateListJson002
539  * @tc.desc: FromPermStateListJson function test
540  * @tc.type: FUNC
541  * @tc.require:
542  */
543 HWTEST_F(TokenSyncServiceTest, FromPermStateListJson002, TestSize.Level1)
544 {
545     auto cmd = std::make_shared<TestBaseRemoteCommand>();
546 
547     CJsonUnique hapTokenJsonNull = CreateJsonFromString("{\\\"bundleName\\\":\\\"\\\","
548         "\\\"instIndex\\\":0,\\\"permState\\\":[{\\\"permissionName\\\":\\\"TEST\\\", "
549         "\\\"grantStatus\\\":0, \\\"grantFlag\\\":0}],\\\"tokenAttr\\\":0,"
550         "\\\"tokenID\\\":111,\\\"userID\\\":0,\\\"version\\\":1}");
551 
552     std::vector<PermissionStatus> permStateListNull;
553     cmd->FromPermStateListJson(hapTokenJsonNull.get(), permStateListNull);
554     EXPECT_EQ(permStateListNull.size(), 0);
555 
556     hapTokenJsonNull = CreateJsonFromString("{\\\"bundleName\\\":\\\"\\\","
557         "\\\"instIndex\\\":0,\\\"permState\\\":[{\\\"permissionName\\\":\\\"TEST\\\"}],"
558         "\\\"tokenAttr\\\":0,\\\"tokenID\\\":111,\\\"userID\\\":0,\\\"version\\\":1}");
559     cmd->FromPermStateListJson(hapTokenJsonNull.get(), permStateListNull);
560     EXPECT_EQ(permStateListNull.size(), 0);
561 
562     hapTokenJsonNull = CreateJsonFromString("{\\\"bundleName\\\":\\\"\\\","
563         "\\\"instIndex\\\":0,\\\"permState\\\":[{\\\"permissionName\\\":\\\"TEST\\\"}],"
564         "\\\"tokenAttr\\\":0,\\\"tokenID\\\":111,\\\"userID\\\":0,\\\"version\\\":1}");
565     cmd->FromPermStateListJson(hapTokenJsonNull.get(), permStateListNull);
566     EXPECT_EQ(permStateListNull.size(), 0);
567 
568     hapTokenJsonNull = CreateJsonFromString("{\\\"bundleName\\\":\\\"\\\","
569         "\\\"instIndex\\\":0,\\\"permState\\\":[{\\\"permissionName\\\":\\\"TEST\\\", "
570         "\\\"grantStatus\\\":0, \\\"grantFlag\\\":0}],\\\"tokenAttr\\\":0,"
571         "\\\"tokenID\\\":111,\\\"userID\\\":0,\\\"version\\\":1}");
572     cmd->FromPermStateListJson(hapTokenJsonNull.get(), permStateListNull);
573     EXPECT_EQ(permStateListNull.size(), 0);
574 }
575 
576 /**
577  * @tc.name: GetRemoteHapTokenInfo002
578  * @tc.desc: test remote hap recv func
579  * @tc.type: FUNC
580  * @tc.require:AR000GK6T5 AR000GK6T9
581  */
582 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo002, TestSize.Level1)
583 {
584     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo002 start.");
585 
586     ResetUuidMock();
587 
588     AccessTokenID tokenId = 0;
589     DeleteAndAllocToken(tokenId);
590 
591     std::string jsonBefore =
592         "{\"commandName\":\"SyncRemoteHapTokenCommand\",\"id\":\"0065e65f-\",\"jsonPayload\":"
593         "\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"\\\","
594         "\\\"instIndex\\\":0,\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
595         "\\\"tokenID\\\":0,\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
596         "\\\"dstDeviceId\\\":\\\"local:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
597         "\\\"requestTokenId\\\":";
598     std::string jsonAfter = ",\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\",\\\"responseVersion\\\":2,"
599         "\\\"srcDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001,"
600         "\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}";
601     std::string recvJson = jsonBefore + std::to_string(tokenId) + jsonAfter;
602 
603     unsigned char *recvBuffer = (unsigned char *)malloc(0x1000);
604     int recvLen = 0x1000;
605     CompressMock(recvJson, recvBuffer, recvLen);
606 
607     ResetSendMessFlagMock();
608 
609     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); // create channel
610 
611     char networkId[DEVICEID_MAX_LEN + 1];
612     strcpy_s(networkId, DEVICEID_MAX_LEN, "deviceid-1:udid-001");
613 
614     PeerSocketInfo info = {
615         .networkId = networkId,
616     };
617     SoftBusSocketListener::OnBind(1, info);
618     SoftBusSocketListener::OnClientBytes(1, recvBuffer, recvLen);
619     int count = 0;
620     while (!GetSendMessFlagMock() && count < MAX_RETRY_TIMES) {
621         sleep(1);
622         count++;
623     }
624     free(recvBuffer);
625 
626     ResetSendMessFlagMock();
627     std::string uuidMessage = GetUuidMock();
628     ASSERT_EQ(uuidMessage, "0065e65f-");
629 }
630 
631 /**
632  * @tc.name: GetRemoteHapTokenInfo003
633  * @tc.desc: test remote hap send func, but get tokenInfo is wrong
634  * @tc.type: FUNC
635  * @tc.require:AR000GK6T5 AR000GK6T9
636  */
637 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1)
638 {
639     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo003 start.");
640     g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\"";
641     // apl is error
642     g_jsonAfter =
643         "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"mock_token_sync\\\","
644         "\\\"instIndex\\\":0,\\\"permState\\\":null,\\\"tokenAttr\\\":0,\\\"tokenID\\\":537919488,"
645         "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
646         "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\","
647         "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
648         "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\""
649         ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\","
650         "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}";
651 
652     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
653     sleep(3);
654     threads_.emplace_back(std::thread(SendTaskThread));
655 
656     OHOS::DelayedSingleton<TokenSyncManagerService>::GetInstance()->GetRemoteHapTokenInfo(
657         g_udid, 0x20100000);
658 
659     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0x20100000);
660     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
661 }
662 
663 /**
664  * @tc.name: GetRemoteHapTokenInfo004
665  * @tc.desc: test remote hap send func, but json payload lost parameter
666  * @tc.type: FUNC
667  * @tc.require:AR000GK6T5 AR000GK6T9
668  */
669 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1)
670 {
671     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo004 start.");
672     g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\"";
673     // lost tokenID
674     g_jsonAfter =
675         "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"mock_token_sync\\\","
676         "\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
677         "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
678         "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\","
679         "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
680         "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\""
681         ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\","
682         "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}";
683 
684     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
685     sleep(3);
686     threads_.emplace_back(std::thread(SendTaskThread));
687 
688     OHOS::DelayedSingleton<TokenSyncManagerService>::GetInstance()->GetRemoteHapTokenInfo(
689         g_udid, 0x20100000);
690 
691     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0x20100000);
692     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
693 }
694 
695 /**
696  * @tc.name: GetRemoteHapTokenInfo005
697  * @tc.desc: test remote hap send func, but json payload parameter type is wrong
698  * @tc.type: FUNC
699  * @tc.require:AR000GK6T5 AR000GK6T9
700  */
701 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1)
702 {
703     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo005 start.");
704     g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\"";
705     // instIndex is not number
706     g_jsonAfter =
707         "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"mock_token_sync\\\","
708         "\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
709         "\\\"tokenID\\\":\\\"aaa\\\","
710         "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
711         "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\","
712         "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
713         "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\""
714         ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\","
715         "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}";
716 
717     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
718     sleep(3);
719 
720     threads_.emplace_back(std::thread(SendTaskThread));
721     OHOS::DelayedSingleton<TokenSyncManagerService>::GetInstance()->GetRemoteHapTokenInfo(
722         g_udid, 0x20100000);
723 
724     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0x20100000);
725     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
726 }
727 
728 /**
729  * @tc.name: GetRemoteHapTokenInfo006
730  * @tc.desc: test remote hap send func, but json payload parameter format is wrong
731  * @tc.type: FUNC
732  * @tc.require:AR000GK6T5 AR000GK6T9
733  */
734 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1)
735 {
736     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo006 start.");
737     g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\"";
738     // mock_token_sync lost \\\"
739     g_jsonAfter =
740         "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"mock_token_sync,"
741         "\\\"111111\\\",\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
742         "\\\"tokenID\\\":537919488,"
743         "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
744         "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\","
745         "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
746         "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\""
747         ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\","
748         "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}";
749 
750     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
751     sleep(3);
752 
753     threads_.emplace_back(std::thread(SendTaskThread));
754 
755     OHOS::DelayedSingleton<TokenSyncManagerService>::GetInstance()->GetRemoteHapTokenInfo(
756         g_udid, 0x20100000);
757 
758     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0x20100000);
759     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
760 }
761 
762 /**
763  * @tc.name: GetRemoteHapTokenInfo007
764  * @tc.desc: test remote hap send func, statusCode is wrong
765  * @tc.type: FUNC
766  * @tc.require:AR000GK6T5 AR000GK6T9
767  */
768 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo007, TestSize.Level1)
769 {
770     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo007 start.");
771     g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\"";
772     // statusCode error
773     g_jsonAfter =
774         "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"mock_token_sync\\\","
775         "\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
776         "\\\"tokenID\\\":537919488,"
777         "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
778         "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
779         "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\""
780         ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\","
781         "\\\"statusCode\\\":-2,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\","
782         "\"type\":\"response\"}";
783 
784     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
785     sleep(3);
786     threads_.emplace_back(std::thread(SendTaskThread));
787 
788     OHOS::DelayedSingleton<TokenSyncManagerService>::GetInstance()->GetRemoteHapTokenInfo(
789         g_udid, 0x20100000);
790 
791     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0x20100000);
792     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
793 }
794 
795 /**
796  * @tc.name: GetRemoteHapTokenInfo008
797  * @tc.desc: test remote hap recv func, tokenID is not exist
798  * @tc.type: FUNC
799  * @tc.require:AR000GK6T5 AR000GK6T9
800  */
801 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo008, TestSize.Level1)
802 {
803     LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo008 start.");
804     // create local token
805     AccessTokenID tokenID = AccessTokenKit::GetHapTokenID(g_infoManagerTestInfoParms.userID,
806                                                           g_infoManagerTestInfoParms.bundleName,
807                                                           g_infoManagerTestInfoParms.instIndex);
808     AccessTokenKit::DeleteToken(tokenID);
809 
810     // tokenID is not exist
811     std::string jsonBefore =
812         "{\"commandName\":\"SyncRemoteHapTokenCommand\",\"id\":\"0065e65f-\",\"jsonPayload\":"
813         "\"{\\\"HapTokenInfo\\\":{\\\"bundleName\\\":\\\"\\\","
814         "\\\"instIndex\\\":0,\\\"permState\\\":null,\\\"tokenAttr\\\":0,"
815         "\\\"tokenID\\\":0,\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\","
816         "\\\"dstDeviceId\\\":\\\"local:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\","
817         "\\\"requestTokenId\\\":";
818     std::string tokenJsonStr = std::to_string(tokenID);
819     std::string jsonAfter = ",\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\",\\\"responseVersion\\\":2,"
820         "\\\"srcDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001,"
821         "\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}";
822 
823     // create recv message
824     std::string recvJson = jsonBefore + tokenJsonStr + jsonAfter;
825     unsigned char *recvBuffer = (unsigned char *)malloc(0x1000);
826     int recvLen = 0x1000;
827     CompressMock(recvJson, recvBuffer, recvLen);
828 
829     g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo);
830 
831     ResetSendMessFlagMock();
832     SoftBusSocketListener::OnClientBytes(1, recvBuffer, recvLen);
833 
834     int count = 0;
835     while (!GetSendMessFlagMock() && count < MAX_RETRY_TIMES) {
836         sleep(1);
837         count++;
838     }
839     free(recvBuffer);
840     AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_udid, 0);
841     ASSERT_EQ(mapID, static_cast<AccessTokenID>(0));
842 }
843 
844 /**
845  * @tc.name: DeleteRemoteTokenCommand001
846  * @tc.desc: test delete remote token command
847  * @tc.type: FUNC
848  * @tc.require: Issue Number
849  */
850 HWTEST_F(TokenSyncServiceTest, DeleteRemoteTokenCommand001, TestSize.Level1)
851 {
852     std::string srcDeviceId = "001";
853     std::string dstDeviceId = "002";
854     AccessTokenID tokenID = 1;
855     std::shared_ptr<DeleteRemoteTokenCommand> deleteRemoteTokenCommand =
856         RemoteCommandFactory::GetInstance().NewDeleteRemoteTokenCommand(srcDeviceId, dstDeviceId, tokenID);
857     ASSERT_EQ(deleteRemoteTokenCommand->remoteProtocol_.commandName, "DeleteRemoteTokenCommand");
858     ASSERT_EQ(deleteRemoteTokenCommand->remoteProtocol_.uniqueId, "DeleteRemoteTokenCommand");
859     ASSERT_EQ(deleteRemoteTokenCommand->remoteProtocol_.srcDeviceId, srcDeviceId);
860     ASSERT_EQ(deleteRemoteTokenCommand->remoteProtocol_.dstDeviceId, dstDeviceId);
861     ASSERT_EQ(
862         // 2 is DISTRIBUTED_ACCESS_TOKEN_SERVICE_VERSION
863         deleteRemoteTokenCommand->remoteProtocol_.responseVersion, 2);
864     ASSERT_EQ(
865         // 2 is DISTRIBUTED_ACCESS_TOKEN_SERVICE_VERSION
866         deleteRemoteTokenCommand->remoteProtocol_.requestVersion, 2);
867 
868     deleteRemoteTokenCommand->Execute();
869     deleteRemoteTokenCommand->Finish();
870     ASSERT_EQ(deleteRemoteTokenCommand->remoteProtocol_.statusCode, Constant::SUCCESS);
871 }
872 
873 /**
874  * @tc.name: NewUpdateRemoteHapTokenCommand001
875  * @tc.desc: test delete remote token command
876  * @tc.type: FUNC
877  * @tc.require: Issue Number
878  */
879 HWTEST_F(TokenSyncServiceTest, NewUpdateRemoteHapTokenCommand001, TestSize.Level1)
880 {
881     std::string srcDeviceId = "001";
882     std::string dstDeviceId = "002";
883     HapTokenInfoForSync tokenInfo;
884     std::shared_ptr<UpdateRemoteHapTokenCommand> command =
885         RemoteCommandFactory::GetInstance().NewUpdateRemoteHapTokenCommand(srcDeviceId, dstDeviceId, tokenInfo);
886     ASSERT_EQ(command->remoteProtocol_.commandName, "UpdateRemoteHapTokenCommand");
887     ASSERT_EQ(command->remoteProtocol_.uniqueId, "UpdateRemoteHapTokenCommand");
888     command->Execute();
889     command->Finish();
890     ASSERT_EQ(command->remoteProtocol_.statusCode, Constant::SUCCESS);
891 }
892 
893 /**
894  * @tc.name: AddDeviceInfo001
895  * @tc.desc: DeviceInfoManager::AddDeviceInfo function test
896  * @tc.type: FUNC
897  * @tc.require:
898  */
899 HWTEST_F(TokenSyncServiceTest, AddDeviceInfo001, TestSize.Level1)
900 {
901     std::string networkId;
902     std::string universallyUniqueId;
903     std::string uniqueDeviceId;
904     std::string deviceName;
905     std::string deviceType;
906     ASSERT_EQ("", networkId);
907     ASSERT_EQ("", universallyUniqueId);
908     ASSERT_EQ("", uniqueDeviceId);
909     ASSERT_EQ("", deviceName);
910     ASSERT_EQ("", deviceType);
911     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
912         deviceType); // all empty
913 
914     networkId = "123";
915     universallyUniqueId = "123";
916     uniqueDeviceId = "123";
917     deviceName = "123";
918     deviceType = "123";
919     ASSERT_NE("", networkId);
920     ASSERT_NE("", universallyUniqueId);
921     ASSERT_NE("", uniqueDeviceId);
922     ASSERT_NE("", deviceName);
923     ASSERT_NE("", deviceType);
924     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
925         deviceType); // all valued
926 
927     std::string nodeId = uniqueDeviceId;
928     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
929     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
930 }
931 
932 /**
933  * @tc.name: RemoveAllRemoteDeviceInfo001
934  * @tc.desc: DeviceInfoManager::RemoveAllRemoteDeviceInfo function test
935  * @tc.type: FUNC
936  * @tc.require:
937  */
938 HWTEST_F(TokenSyncServiceTest, RemoveAllRemoteDeviceInfo001, TestSize.Level1)
939 {
940     DeviceInfoManager::GetInstance().RemoveAllRemoteDeviceInfo(); // FindDeviceInfo false
941 
942     std::string networkId = "123";
943     std::string universallyUniqueId = "123";
944     std::string uniqueDeviceId;
945     std::string deviceName = "123";
946     std::string deviceType = "123";
947     uniqueDeviceId = ConstantCommon::GetLocalDeviceId();
948     ASSERT_EQ("local:udid-001", uniqueDeviceId);
949 
950     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
951         deviceType);
952     DeviceInfoManager::GetInstance().RemoveAllRemoteDeviceInfo(); // FindDeviceInfo true
953 
954     std::string nodeId = uniqueDeviceId;
955     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
956     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
957 }
958 
959 /**
960  * @tc.name: RemoveRemoteDeviceInfo001
961  * @tc.desc: DeviceInfoManager::RemoveRemoteDeviceInfo function test
962  * @tc.type: FUNC
963  * @tc.require:
964  */
965 HWTEST_F(TokenSyncServiceTest, RemoveRemoteDeviceInfo001, TestSize.Level1)
966 {
967     std::string nodeId;
968     DeviceIdType deviceIdType = DeviceIdType::UNKNOWN;
969     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType); // nodeId invalid
970     ASSERT_EQ("", nodeId);
971 
972     nodeId = "123";
973     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType); // FindDeviceInfo false
974 
975     std::string networkId = "123";
976     std::string universallyUniqueId = "123";
977     std::string uniqueDeviceId = "123";
978     std::string deviceName = "123";
979     std::string deviceType = "123";
980     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
981         deviceType); // add 123 nodeid
982 
983     networkId = "456";
984     universallyUniqueId = "456";
985     uniqueDeviceId = ConstantCommon::GetLocalDeviceId();
986     ASSERT_EQ("local:udid-001", uniqueDeviceId);
987     deviceName = "456";
988     deviceType = "456";
989     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
990         deviceType); // add local unique deviceid
991 
992     nodeId = "123";
993     deviceIdType = DeviceIdType::UNIQUE_DISABILITY_ID;
994     // FindDeviceInfo true + uniqueDeviceId != localDevice true
995     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType); // delete 123
996 
997     nodeId = uniqueDeviceId;
998     // FindDeviceInfo true + uniqueDeviceId != localDevice false
999     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType);
1000 
1001     nodeId = uniqueDeviceId;
1002     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
1003     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete local unique deviceid
1004 }
1005 
1006 /**
1007  * @tc.name: ConvertToUniversallyUniqueIdOrFetch001
1008  * @tc.desc: DeviceInfoManager::ConvertToUniversallyUniqueIdOrFetch function test
1009  * @tc.type: FUNC
1010  * @tc.require:
1011  */
1012 HWTEST_F(TokenSyncServiceTest, ConvertToUniversallyUniqueIdOrFetch001, TestSize.Level1)
1013 {
1014     std::string nodeId;
1015     ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId)); // nodeId invalid
1016 
1017     nodeId = "123";
1018     // FindDeviceInfo false
1019     ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId));
1020 
1021     std::string networkId = "123";
1022     std::string universallyUniqueId = "123";
1023     std::string uniqueDeviceId = "123";
1024     std::string deviceName = "123";
1025     std::string deviceType = "123";
1026     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
1027         deviceType); // add 123 nodeid
1028 
1029     nodeId = "123";
1030     // FindDeviceInfo true + universallyUniqueId is not empty
1031     DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId);
1032 
1033     nodeId = uniqueDeviceId;
1034     // FindDeviceInfo true + uniqueDeviceId != localDevice false
1035     DeviceIdType deviceIdType = DeviceIdType::UNIQUE_DISABILITY_ID;
1036     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType);
1037 
1038     nodeId = uniqueDeviceId;
1039     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
1040     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
1041 }
1042 
1043 /**
1044  * @tc.name: ConvertToUniqueDeviceIdOrFetch001
1045  * @tc.desc: DeviceInfoManager::ConvertToUniqueDeviceIdOrFetch function test
1046  * @tc.type: FUNC
1047  * @tc.require:
1048  */
1049 HWTEST_F(TokenSyncServiceTest, ConvertToUniqueDeviceIdOrFetch001, TestSize.Level1)
1050 {
1051     std::string nodeId;
1052     ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId)); // nodeId invalid
1053 
1054     nodeId = "123";
1055     // FindDeviceInfo false
1056     ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId));
1057 
1058     std::string networkId = "123";
1059     std::string universallyUniqueId = "123";
1060     std::string uniqueDeviceId = "123";
1061     std::string deviceName = "123";
1062     std::string deviceType = "123";
1063     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
1064         deviceType); // add 123 nodeid
1065 
1066     nodeId = "123";
1067     // FindDeviceInfo true + universallyUniqueId is not empty
1068     DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId);
1069 
1070     nodeId = uniqueDeviceId;
1071     // FindDeviceInfo true + uniqueDeviceId != localDevice false
1072     DeviceIdType deviceIdType = DeviceIdType::UNIQUE_DISABILITY_ID;
1073     DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(nodeId, deviceIdType);
1074 
1075     nodeId = uniqueDeviceId;
1076     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
1077     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
1078 }
1079 
1080 /**
1081  * @tc.name: IsDeviceUniversallyUniqueId001
1082  * @tc.desc: DeviceInfoManager::IsDeviceUniversallyUniqueId function test
1083  * @tc.type: FUNC
1084  * @tc.require:
1085  */
1086 HWTEST_F(TokenSyncServiceTest, IsDeviceUniversallyUniqueId001, TestSize.Level1)
1087 {
1088     std::string nodeId;
1089     ASSERT_EQ(false, DeviceInfoManager::GetInstance().IsDeviceUniversallyUniqueId(nodeId)); // nodeId invalid
1090 
1091     nodeId = "123";
1092     ASSERT_EQ(false, DeviceInfoManager::GetInstance().IsDeviceUniversallyUniqueId(nodeId)); // FindDeviceInfo false
1093 
1094     std::string networkId = "123";
1095     std::string universallyUniqueId = "123";
1096     std::string uniqueDeviceId = "123";
1097     std::string deviceName = "123";
1098     std::string deviceType = "123";
1099     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
1100         deviceType); // add 123 nodeid
1101 
1102     ASSERT_EQ(true, DeviceInfoManager::GetInstance().IsDeviceUniversallyUniqueId(nodeId)); // FindDeviceInfo true
1103 
1104     nodeId = uniqueDeviceId;
1105     DeviceIdType type = DeviceIdType::UNIQUE_DISABILITY_ID;
1106     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
1107 }
1108 
1109 /**
1110  * @tc.name: FindDeviceInfo001
1111  * @tc.desc: DeviceInfoRepository::FindDeviceInfo function test
1112  * @tc.type: FUNC
1113  * @tc.require:
1114  */
1115 HWTEST_F(TokenSyncServiceTest, FindDeviceInfo001, TestSize.Level1)
1116 {
1117     std::string networkId = "123";
1118     std::string universallyUniqueId = "123";
1119     std::string uniqueDeviceId = "123";
1120     std::string deviceName = "123";
1121     std::string deviceType = "123";
1122 
1123     DeviceId deviceId;
1124     deviceId.networkId = networkId;
1125     deviceId.universallyUniqueId = universallyUniqueId;
1126     deviceId.uniqueDeviceId = uniqueDeviceId;
1127     DeviceInfo deviceInfo;
1128     // count > 0 false
1129     DeviceIdType type = DeviceIdType::UNKNOWN;
1130     ASSERT_EQ(false, DeviceInfoRepository::GetInstance().FindDeviceInfo("456", type, deviceInfo));
1131 
1132     DeviceInfoRepository::GetInstance().SaveDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
1133         deviceType); // add 123 nodeid
1134 
1135     type = DeviceIdType::NETWORK_ID;
1136     // count > 0 true
1137     ASSERT_EQ(true, DeviceInfoRepository::GetInstance().FindDeviceInfo(networkId, type, deviceInfo));
1138 
1139     type = DeviceIdType::UNIVERSALLY_UNIQUE_ID;
1140     // count > 0 true
1141     ASSERT_EQ(true, DeviceInfoRepository::GetInstance().FindDeviceInfo(universallyUniqueId, type, deviceInfo));
1142 
1143     type = DeviceIdType::UNIQUE_DISABILITY_ID;
1144     // count > 0 true
1145     ASSERT_EQ(true, DeviceInfoRepository::GetInstance().FindDeviceInfo(uniqueDeviceId, type, deviceInfo));
1146 
1147     type = DeviceIdType::UNKNOWN;
1148     // count > 0 true
1149     ASSERT_EQ(true, DeviceInfoRepository::GetInstance().FindDeviceInfo(networkId, type, deviceInfo));
1150 
1151     std::string nodeId = uniqueDeviceId;
1152     type = DeviceIdType::UNIQUE_DISABILITY_ID;
1153     DeviceInfoRepository::GetInstance().DeleteDeviceInfo(nodeId, type); // delete 123
1154 }
1155 
1156 /**
1157  * @tc.name: GetRemoteHapTokenInfo001
1158  * @tc.desc: TokenSyncManagerService::GetRemoteHapTokenInfo function test
1159  * @tc.type: FUNC
1160  * @tc.require:
1161  */
1162 HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo001, TestSize.Level1)
1163 {
1164     std::string deviceID = "dev-001";
1165     AccessTokenID tokenID = 123; // 123 is random input
1166 
1167     // FindDeviceInfo failed
1168     ASSERT_EQ(TokenSyncError::TOKEN_SYNC_REMOTE_DEVICE_INVALID,
1169         tokenSyncManagerService_->GetRemoteHapTokenInfo(deviceID, tokenID));
1170 }
1171 
1172 /**
1173  * @tc.name: DeleteRemoteHapTokenInfo001
1174  * @tc.desc: TokenSyncManagerService::DeleteRemoteHapTokenInfo function test
1175  * @tc.type: FUNC
1176  * @tc.require:
1177  */
1178 HWTEST_F(TokenSyncServiceTest, DeleteRemoteHapTokenInfo001, TestSize.Level1)
1179 {
1180     AccessTokenID tokenId;
1181 
1182     tokenId = 0;
1183     // Params is wrong, token id is invalid
1184     ASSERT_EQ(TokenSyncError::TOKEN_SYNC_PARAMS_INVALID,
1185         tokenSyncManagerService_->DeleteRemoteHapTokenInfo(tokenId));
1186 
1187     std::string networkId = "123";
1188     std::string universallyUniqueId = "123";
1189     std::string uniqueDeviceId = "123";
1190     std::string deviceName = "123";
1191     std::string deviceType = "123";
1192     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, uniqueDeviceId, deviceName,
1193         deviceType); // add nodeId 123
1194     networkId = "456";
1195     universallyUniqueId = "456";
1196     std::string localUdid = ConstantCommon::GetLocalDeviceId();
1197     deviceName = "456";
1198     deviceType = "456";
1199     DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, universallyUniqueId, localUdid, deviceName,
1200         deviceType); // add nodeId 456
1201     tokenId = 123; // 123 is random input
1202     // no need notify local device
1203     ASSERT_EQ(TokenSyncError::TOKEN_SYNC_SUCCESS, tokenSyncManagerService_->DeleteRemoteHapTokenInfo(tokenId));
1204 
1205     HapTokenInfoForSync tokenInfo;
1206     ASSERT_EQ(TokenSyncError::TOKEN_SYNC_SUCCESS, tokenSyncManagerService_->UpdateRemoteHapTokenInfo(tokenInfo));
1207 }
1208 
1209 /**
1210  * @tc.name: ExistDeviceInfo001
1211  * @tc.desc: TokenSyncManagerService::ExistDeviceInfo function test
1212  * @tc.type: FUNC
1213  * @tc.require:
1214  */
1215 HWTEST_F(TokenSyncServiceTest, ExistDeviceInfo001, TestSize.Level1)
1216 {
1217     std::string nodeId = "111";
1218     DeviceIdType type = DeviceIdType::NETWORK_ID;
1219     EXPECT_FALSE(DeviceInfoManager::GetInstance().ExistDeviceInfo(nodeId, type));
1220 }
1221 
1222 class TestStub : public TokenSyncManagerStub {
1223 public:
1224     TestStub() = default;
1225     virtual ~TestStub() = default;
1226 
GetRemoteHapTokenInfo(const std::string & deviceID,AccessTokenID tokenID)1227     int GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID)
1228     {
1229         return 0;
1230     }
1231 
DeleteRemoteHapTokenInfo(AccessTokenID tokenID)1232     int DeleteRemoteHapTokenInfo(AccessTokenID tokenID)
1233     {
1234         return 0;
1235     }
1236 
UpdateRemoteHapTokenInfo(const HapTokenInfoForSync & tokenInfo)1237     int UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo)
1238     {
1239         return 0;
1240     }
1241 };
1242 
1243 /**
1244  * @tc.name: OnRemoteRequest001
1245  * @tc.desc: TokenSyncManagerStub::OnRemoteRequest function test
1246  * @tc.type: FUNC
1247  * @tc.require:
1248  */
1249 HWTEST_F(TokenSyncServiceTest, OnRemoteRequest001, TestSize.Level1)
1250 {
1251     OHOS::MessageParcel data;
1252     OHOS::MessageParcel reply;
1253     OHOS::MessageOption option(OHOS::MessageOption::TF_SYNC);
1254     TestStub sub;
1255 
1256     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1257     uint32_t code = 10;
1258     ASSERT_NE(0, sub.OnRemoteRequest(code, data, reply, option)); // msgCode default
1259 
1260     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1261     // msgCode GET_REMOTE_HAP_TOKEN_INFO + type != TOKEN_NATIVE
1262     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1263         TokenSyncInterfaceCode::GET_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1264 
1265     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1266     // msgCode DELETE_REMOTE_HAP_TOKEN_INFO + type != TOKEN_NATIVE
1267     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1268         TokenSyncInterfaceCode::DELETE_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1269 
1270     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1271     // msgCode UPDATE_REMOTE_HAP_TOKEN_INFO + type != TOKEN_NATIVE
1272     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1273         TokenSyncInterfaceCode::UPDATE_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1274 }
1275 
1276 /**
1277  * @tc.name: OnRemoteRequest002
1278  * @tc.desc: TokenSyncManagerStub::OnRemoteRequest function test
1279  * @tc.type: FUNC
1280  * @tc.require:
1281  */
1282 HWTEST_F(TokenSyncServiceTest, OnRemoteRequest002, TestSize.Level1)
1283 {
1284     OHOS::MessageParcel data;
1285     OHOS::MessageParcel reply;
1286     OHOS::MessageOption option(OHOS::MessageOption::TF_SYNC);
1287     TestStub sub;
1288     auto tokenId = GetSelfTokenID();
1289     EXPECT_EQ(0, SetSelfTokenID(g_selfTokenId));
1290     setuid(1234);
1291     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1292 
1293     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1294         TokenSyncInterfaceCode::GET_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1295 
1296     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1297 
1298     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1299         TokenSyncInterfaceCode::DELETE_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1300 
1301     ASSERT_EQ(true, data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()));
1302 
1303     ASSERT_EQ(NO_ERROR, sub.OnRemoteRequest(static_cast<uint32_t>(
1304         TokenSyncInterfaceCode::UPDATE_REMOTE_HAP_TOKEN_INFO), data, reply, option));
1305 
1306     ASSERT_EQ(ERR_IDENTITY_CHECK_FAILED, reply.ReadInt32());
1307 
1308     setuid(g_selfUid);
1309     EXPECT_EQ(0, SetSelfTokenID(tokenId));
1310 }
1311 
1312 /**
1313  * @tc.name: OnStart001
1314  * @tc.desc: TokenSyncManagerStub::OnStart function test
1315  * @tc.type: FUNC
1316  * @tc.require:
1317  */
1318 HWTEST_F(TokenSyncServiceTest, OnStart001, TestSize.Level1)
1319 {
1320     tokenSyncManagerService_->OnStop();
1321     ASSERT_EQ(ServiceRunningState::STATE_NOT_START, tokenSyncManagerService_->state_);
1322     tokenSyncManagerService_->OnStart();
1323     ASSERT_EQ(ServiceRunningState::STATE_RUNNING, tokenSyncManagerService_->state_);
1324     tokenSyncManagerService_->OnStart();
1325 }
1326 
1327 /**
1328  * @tc.name: RemoteCommandManager001
1329  * @tc.desc: RemoteCommandManager001 function test
1330  * @tc.type: FUNC
1331  * @tc.require:
1332  */
1333 HWTEST_F(TokenSyncServiceTest, RemoteCommandManager001, TestSize.Level1)
1334 {
1335     RemoteCommandManager::GetInstance().Init();
1336     std::string udid = "test_udId";
1337     auto cmd = std::make_shared<TestBaseRemoteCommand>();
1338     char networkId[DEVICEID_MAX_LEN + 1];
1339     int recvLen = 0x1000;
1340     strcpy_s(networkId, DEVICEID_MAX_LEN, "deviceid-1:udid-001");
1341     PeerSocketInfo info = {
1342         .networkId = networkId,
1343     };
1344     SoftBusSocketListener::OnBind(0, info);
1345     int32_t ret = RemoteCommandManager::GetInstance().AddCommand(udid, cmd);
1346     ASSERT_EQ(Constant::SUCCESS, ret);
1347     ret = RemoteCommandManager::GetInstance().AddCommand("", cmd);
1348     ASSERT_EQ(Constant::FAILURE, ret);
1349     SoftBusSocketListener::OnServiceBytes(0, nullptr, recvLen);
1350     ret = RemoteCommandManager::GetInstance().AddCommand(udid, nullptr);
1351     ASSERT_EQ(Constant::FAILURE, ret);
1352     SoftBusSocketListener::OnClientBytes(0, nullptr, recvLen);
1353     ret = RemoteCommandManager::GetInstance().AddCommand("", nullptr);
1354     ASSERT_EQ(Constant::FAILURE, ret);
1355     SoftBusSocketListener::OnShutdown(0, SHUTDOWN_REASON_UNKNOWN);
1356 }
1357 
1358 /**
1359  * @tc.name: RemoteCommandManager002
1360  * @tc.desc: RemoteCommandManager002 function test
1361  * @tc.type: FUNC
1362  * @tc.require:
1363  */
1364 HWTEST_F(TokenSyncServiceTest, RemoteCommandManager002, TestSize.Level1)
1365 {
1366     RemoteCommandManager::GetInstance().Init();
1367     std::string udid = "test_udId_1";
1368     int32_t ret = RemoteCommandManager::GetInstance().ProcessDeviceCommandImmediately(udid);
1369     ASSERT_EQ(Constant::FAILURE, ret);
1370     ret = RemoteCommandManager::GetInstance().ProcessDeviceCommandImmediately("");
1371     ASSERT_EQ(Constant::FAILURE, ret);
1372     SoftBusSocketListener::OnShutdown(1, SHUTDOWN_REASON_UNKNOWN);
1373 }
1374 
1375 /**
1376  * @tc.name: RemoteCommandManager003
1377  * @tc.desc: RemoteCommandManager003 function test
1378  * @tc.type: FUNC
1379  * @tc.require:
1380  */
1381 HWTEST_F(TokenSyncServiceTest, RemoteCommandManager003, TestSize.Level1)
1382 {
1383     RemoteCommandManager::GetInstance().Init();
1384     std::string nodeId = "test_udId";
1385     int32_t ret = RemoteCommandManager::GetInstance().NotifyDeviceOnline("");
1386     ASSERT_EQ(Constant::FAILURE, ret);
1387     ret = RemoteCommandManager::GetInstance().NotifyDeviceOnline(nodeId);
1388     ASSERT_EQ(Constant::SUCCESS, ret);
1389     SoftBusSocketListener::OnShutdown(OUT_OF_MAP_SOCKET, SHUTDOWN_REASON_UNKNOWN);
1390 }
1391 
1392 /**
1393  * @tc.name: ProcessDeviceCommandImmediately001
1394  * @tc.desc: ProcessDeviceCommandImmediately function test
1395  * @tc.type: FUNC
1396  * @tc.require:
1397  */
1398 HWTEST_F(TokenSyncServiceTest, ProcessDeviceCommandImmediately001, TestSize.Level1)
1399 {
1400     std::string udid = "test_udId_1";
1401     RemoteCommandManager::GetInstance().executors_[udid] = nullptr;
1402     int32_t ret = RemoteCommandManager::GetInstance().ProcessDeviceCommandImmediately(udid);
1403     ASSERT_EQ(Constant::FAILURE, ret);
1404     ASSERT_EQ(1, RemoteCommandManager::GetInstance().executors_.erase(udid));
1405 }
1406 
1407 /**
1408  * @tc.name: ProcessBufferedCommandsWithThread001
1409  * @tc.desc: RemoteCommandExecutor::ProcessBufferedCommandsWithThread function test
1410  * @tc.type: FUNC
1411  * @tc.require:
1412  */
1413 HWTEST_F(TokenSyncServiceTest, ProcessBufferedCommandsWithThread001, TestSize.Level1)
1414 {
1415     std::string nodeId = "test_nodeId";
1416     auto executor = std::make_shared<RemoteCommandExecutor>(nodeId);
1417     executor->ProcessBufferedCommandsWithThread();
1418     EXPECT_FALSE(executor->running_);
1419     auto cmd = std::make_shared<TestBaseRemoteCommand>();
1420     cmd->remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY;
1421     executor->commands_.emplace_back(cmd);
1422     executor->running_ = true;
1423     executor->ProcessBufferedCommandsWithThread();
1424     executor->running_ = false;
1425     executor->ProcessBufferedCommandsWithThread();
1426     EXPECT_TRUE(executor->running_);
1427 }
1428 
1429 namespace {
1430 PermissionStatus g_infoManagerTestUpdateState1 = {
1431     .permissionName = "ohos.permission.CAMERA",
1432     .grantStatus = PermissionState::PERMISSION_DENIED,
1433     .grantFlag = 1
1434 };
1435 
1436 PermissionStatus g_infoManagerTestUpdateState2 = {
1437     .permissionName = "ohos.permission.ANSWER_CALL",
1438     .grantStatus = PermissionState::PERMISSION_DENIED,
1439     .grantFlag = 1
1440 };
1441 
1442 HapTokenInfo g_remoteHapInfoBasic = {
1443     .ver = 1,
1444     .userID = 1,
1445     .bundleName = "accesstoken_test",
1446     .instIndex = 1,
1447     .tokenID = 0x20000001,
1448     .tokenAttr = 0
1449 };
1450 
1451 HapTokenInfoForSync g_remoteHapInfo = {
1452     .baseInfo = g_remoteHapInfoBasic,
1453     .permStateList = {g_infoManagerTestUpdateState1, g_infoManagerTestUpdateState2}
1454 };
1455 }
1456 }  // namespace AccessToken
1457 }  // namespace Security
1458 }  // namespace OHOS
1459