• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "data_collect_kit_test.h"
17 
18 #include "file_ex.h"
19 #include "nativetoken_kit.h"
20 #include "securec.h"
21 #include "token_setproc.h"
22 #include "accesstoken_kit.h"
23 #include "sg_obtaindata_client.h"
24 #define private public
25 #include "data_collect_manager.h"
26 #include "security_guard_define.h"
27 #include "sg_collect_client.h"
28 #undef private
29 
30 using namespace testing::ext;
31 using namespace OHOS::Security::SecurityGuardTest;
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36     int32_t ReportSecurityInfo(const struct EventInfoSt *info);
37     int32_t ReportSecurityInfoAsync(const struct EventInfoSt *info);
38 #ifdef __cplusplus
39 }
40 #endif
41 
42 namespace OHOS::Security::SecurityGuardTest {
43 
SetUpTestCase()44 void DataCollectKitTest::SetUpTestCase()
45 {
46     string isEnforcing;
47     LoadStringFromFile("/sys/fs/selinux/enforce", isEnforcing);
48     if (isEnforcing.compare("1") == 0) {
49         DataCollectKitTest::isEnforcing_ = true;
50         SaveStringToFile("/sys/fs/selinux/enforce", "0");
51     }
52 }
53 
TearDownTestCase()54 void DataCollectKitTest::TearDownTestCase()
55 {
56     if (DataCollectKitTest::isEnforcing_) {
57         SaveStringToFile("/sys/fs/selinux/enforce", "1");
58     }
59 }
60 
SetUp()61 void DataCollectKitTest::SetUp()
62 {
63 }
64 
TearDown()65 void DataCollectKitTest::TearDown()
66 {
67 }
68 
69 bool DataCollectKitTest::isEnforcing_ = false;
RequestSecurityEventInfoCallBackFunc(const DeviceIdentify * devId,const char * eventBuffList,uint32_t status)70 void DataCollectKitTest::RequestSecurityEventInfoCallBackFunc(const DeviceIdentify *devId, const char *eventBuffList,
71     uint32_t status)
72 {
73     EXPECT_TRUE(devId != nullptr);
74     EXPECT_TRUE(eventBuffList != nullptr);
75 }
76 /**
77  * @tc.name: ReportSecurityInfo001
78  * @tc.desc: ReportSecurityInfo with right param
79  * @tc.type: FUNC
80  * @tc.require: SR000H96L5
81  */
82 HWTEST_F(DataCollectKitTest, ReportSecurityInfo001, TestSize.Level1)
83 {
84     static int64_t eventId = 1011009000;
85     static std::string version = "0";
86     static std::string content = "{\"cred\":0,\"extra\":\"\",\"status\":0}";
87     EventInfoSt info;
88     info.eventId = eventId;
89     info.version = version.c_str();
90     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
91     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
92     EXPECT_TRUE(rc == EOK);
93     info.contentLen = static_cast<uint32_t>(content.length());
94     int ret = ReportSecurityInfo(&info);
95     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
96 }
97 
98 /**
99  * @tc.name: ReportSecurityInfo002
100  * @tc.desc: ReportSecurityInfo with wrong cred
101  * @tc.type: FUNC
102  * @tc.require: SR000H96L5
103  */
104 HWTEST_F(DataCollectKitTest, ReportSecurityInfo002, TestSize.Level1)
105 {
106     static int64_t eventId = 1011009000;
107     static std::string version = "0";
108     static std::string content = "{\"cred\":\"0\",\"extra\":\"\",\"status\":0}";
109     EventInfoSt info;
110     info.eventId = eventId;
111     info.version = version.c_str();
112     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
113     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
114     EXPECT_TRUE(rc == EOK);
115     info.contentLen = static_cast<uint32_t>(content.length());
116     int ret = ReportSecurityInfo(&info);
117     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
118 }
119 
120 /**
121  * @tc.name: ReportSecurityInfo003
122  * @tc.desc: ReportSecurityInfo with wrong extra
123  * @tc.type: FUNC
124  * @tc.require: SR000H96L5
125  */
126 HWTEST_F(DataCollectKitTest, ReportSecurityInfo003, TestSize.Level1)
127 {
128     static int64_t eventId = 1011009000;
129     static std::string version = "0";
130     static std::string content = "{\"cred\":0,\"extra\":0,\"status\":0}";
131     EventInfoSt info;
132     info.eventId = eventId;
133     info.version = version.c_str();
134     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
135     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
136     EXPECT_TRUE(rc == EOK);
137     info.contentLen = static_cast<uint32_t>(content.length());
138     int ret = ReportSecurityInfo(&info);
139     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
140 }
141 
142 /**
143  * @tc.name: ReportSecurityInfo004
144  * @tc.desc: ReportSecurityInfo with wrong status
145  * @tc.type: FUNC
146  * @tc.require: SR000H96L5
147  */
148 HWTEST_F(DataCollectKitTest, ReportSecurityInfo004, TestSize.Level1)
149 {
150     static int64_t eventId = 1011009000;
151     static std::string version = "0";
152     static std::string content = "{\"cred\":0,\"extra\":\"\",\"status\":\"0\"}";
153     EventInfoSt info;
154     info.eventId = eventId;
155     info.version = version.c_str();
156     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
157     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
158     EXPECT_TRUE(rc == EOK);
159     info.contentLen = static_cast<uint32_t>(content.length());
160     int ret = ReportSecurityInfo(&info);
161     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
162 }
163 
164 /**
165  * @tc.name: ReportSecurityInfo005
166  * @tc.desc: ReportSecurityInfo with wrong eventId
167  * @tc.type: FUNC
168  * @tc.require: SR000H96L5
169  */
170 HWTEST_F(DataCollectKitTest, ReportSecurityInfo005, TestSize.Level1)
171 {
172     static int64_t eventId = 0;
173     static std::string version = "0";
174     static std::string content = "{\"cred\":0,\"extra\":\"\",\"status\":0}";
175     EventInfoSt info;
176     info.eventId = eventId;
177     info.version = version.c_str();
178     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
179     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
180     EXPECT_TRUE(rc == EOK);
181     info.contentLen = static_cast<uint32_t>(content.length());
182     int ret = ReportSecurityInfo(&info);
183     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
184 }
185 
186 /**
187  * @tc.name: ReportSecurityInfo006
188  * @tc.desc: ReportSecurityInfo with null info
189  * @tc.type: FUNC
190  * @tc.require: SR000H96L5
191  */
192 HWTEST_F(DataCollectKitTest, ReportSecurityInfo006, TestSize.Level1)
193 {
194     int ret = ReportSecurityInfo(nullptr);
195     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
196 }
197 
198 /**
199  * @tc.name: ReportSecurityInfoAsync001
200  * @tc.desc: ReportSecurityInfoAsync with right param
201  * @tc.type: FUNC
202  * @tc.require: SR000H96L5
203  */
204 HWTEST_F(DataCollectKitTest, ReportSecurityInfoAsync001, TestSize.Level1)
205 {
206     static int64_t eventId = 1011009000;
207     static std::string version = "0";
208     static std::string content = "{\"cred\":0,\"extra\":\"\",\"status\":0}";
209     EventInfoSt info;
210     info.eventId = eventId;
211     info.version = version.c_str();
212     (void) memset_s(info.content, CONTENT_MAX_LEN, 0, CONTENT_MAX_LEN);
213     errno_t rc = memcpy_s(info.content, CONTENT_MAX_LEN, content.c_str(), content.length());
214     EXPECT_TRUE(rc == EOK);
215     info.contentLen = static_cast<uint32_t>(content.length());
216     int ret = ReportSecurityInfoAsync(&info);
217     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
218 }
219 
220 HWTEST_F(DataCollectKitTest, ConfigUpdate001, TestSize.Level1)
221 {
222     EXPECT_NE(SecurityGuardConfigUpdate(-1, "test"), SecurityGuard::SUCCESS);
223 }
224 
225 /**
226  * @tc.name: Subscribe001
227  * @tc.desc: AcquireDataManager Subscribe
228  * @tc.type: FUNC
229  * @tc.require: AR000IENKB
230  */
231 class MockSubscriberPtr : public SecurityCollector::ICollectorSubscriber {
232 public:
MockSubscriberPtr(const SecurityCollector::Event & event)233     explicit MockSubscriberPtr(const SecurityCollector::Event &event) : ICollectorSubscriber(
234         event, -1, false, "securityGroup") {};
235     ~MockSubscriberPtr() override = default;
OnNotify(const SecurityCollector::Event & event)236     int32_t OnNotify(const SecurityCollector::Event &event) override {return 0;};
237 };
238 
239 HWTEST_F(DataCollectKitTest, Subscribe001, TestSize.Level1)
240 {
241     int ret = SecurityGuard::DataCollectManager::GetInstance().Subscribe(nullptr);
242     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
243 }
244 
245 SecurityCollector::Event g_event {};
246 auto g_sub = std::make_shared<MockSubscriberPtr>(g_event);
247 
248 HWTEST_F(DataCollectKitTest, Subscribe002, TestSize.Level1)
249 {
250     SecurityGuard::DataCollectManager::GetInstance().subscribers_.insert(g_sub);
251     int ret = SecurityGuard::DataCollectManager::GetInstance().Subscribe(g_sub);
252     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
253     auto sub = std::make_shared<MockSubscriberPtr>(g_event);
254     ret = SecurityGuard::DataCollectManager::GetInstance().Subscribe(sub);
255     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
256     SecurityGuard::DataCollectManager::GetInstance().subscribers_.clear();
257     ret = SecurityGuard::DataCollectManager::GetInstance().Subscribe(g_sub);
258     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
259 }
260 
261 /**
262  * @tc.name: Unsubscribe001
263  * @tc.desc: AcquireDataManager Unsubscribe
264  * @tc.type: FUNC
265  * @tc.require: AR000IENKB
266  */
267 HWTEST_F(DataCollectKitTest, Unsubscribe001, TestSize.Level1)
268 {
269     int ret = SecurityGuard::DataCollectManager::GetInstance().Unsubscribe(nullptr);
270     SecurityGuard::DataCollectManager::DeathRecipient recipient = SecurityGuard::DataCollectManager::DeathRecipient();
271     recipient.OnRemoteDied(nullptr);
272     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
273 }
274 
275 HWTEST_F(DataCollectKitTest, Unsubscribe002, TestSize.Level1)
276 {
277     int ret = SecurityGuard::DataCollectManager::GetInstance().Unsubscribe(g_sub);
278     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
279     SecurityGuard::DataCollectManager::GetInstance().subscribers_.insert(g_sub);
280     ret = SecurityGuard::DataCollectManager::GetInstance().Unsubscribe(g_sub);
281     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
282     auto sub = std::make_shared<MockSubscriberPtr>(g_event);
283     SecurityGuard::DataCollectManager::GetInstance().subscribers_.insert(sub);
284     ret = SecurityGuard::DataCollectManager::GetInstance().Unsubscribe(g_sub);
285     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
286     EXPECT_EQ(SecurityGuard::DataCollectManager::GetInstance().subscribers_.count(g_sub), 0);
287 }
288 /**
289  * @tc.name: RequestSecurityEventInfoAsync001
290  * @tc.desc: RequestSecurityEventInfoAsync with right param
291  * @tc.type: FUNC
292  * @tc.require: SR000H96FD
293  */
294 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync001, TestSize.Level1)
295 {
296     DeviceIdentify deviceIdentify = {};
297     static std::string eventList = "{\"eventId\":[1011009000]}";
298     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
299     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
300 }
301 
302 /**
303  * @tc.name: RequestSecurityEventInfoAsync002
304  * @tc.desc: RequestSecurityEventInfoAsync with right param, get all info
305  * @tc.type: FUNC
306  * @tc.require: SR000H96FD
307  */
308 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync002, TestSize.Level1)
309 {
310     DeviceIdentify deviceIdentify = {};
311     static std::string eventList = "{\"eventId\":[-1]}";
312     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
313     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
314 }
315 
316 /**
317  * @tc.name: RequestSecurityEventInfoAsync003
318  * @tc.desc: RequestSecurityEventInfoAsync with wrong eventList key
319  * @tc.type: FUNC
320  * @tc.require: SR000H96FD
321  */
322 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync003, TestSize.Level1)
323 {
324     DeviceIdentify deviceIdentify = {};
325     static std::string eventList = "{\"eventIds\":[1011009000]}";
326     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
327     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
328 }
329 
330 /**
331  * @tc.name: RequestSecurityEventInfoAsync004
332  * @tc.desc: RequestSecurityEventInfoAsync with wrong eventList content
333  * @tc.type: FUNC
334  * @tc.require: SR000H96FD
335  */
336 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync004, TestSize.Level1)
337 {
338     DeviceIdentify deviceIdentify = {};
339     static std::string eventList = "{eventId:[1011009000]}";
340     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
341     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
342 }
343 
344 /**
345  * @tc.name: RequestSecurityEventInfoAsync005
346  * @tc.desc: RequestSecurityEventInfoAsync with wrong eventList null
347  * @tc.type: FUNC
348  * @tc.require: SR000H96FD
349  */
350 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync005, TestSize.Level1)
351 {
352     DeviceIdentify deviceIdentify = {};
353     static std::string eventList = "{\"eventIds\":[]}";
354     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
355     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
356 }
357 
358 /**
359  * @tc.name: RequestSecurityEventInfoAsync006
360  * @tc.desc: RequestSecurityEventInfoAsync with wrong eventList not contain right eventId
361  * @tc.type: FUNC
362  * @tc.require: SR000H96FD
363  */
364 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync006, TestSize.Level1)
365 {
366     DeviceIdentify deviceIdentify = {};
367     static std::string eventList = "{\"eventIds\":[0]}";
368     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
369     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
370 }
371 
372 /**
373  * @tc.name: RequestSecurityEventInfoAsync007
374  * @tc.desc: RequestSecurityEventInfoAsync with null devId
375  * @tc.type: FUNC
376  * @tc.require: SR000H96FD
377  */
378 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync007, TestSize.Level1)
379 {
380     static std::string eventList = "{\"eventIds\":[0]}";
381     int ret = RequestSecurityEventInfoAsync(nullptr, eventList.c_str(), RequestSecurityEventInfoCallBackFunc);
382     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
383 }
384 
385 /**
386  * @tc.name: RequestSecurityEventInfoAsync008
387  * @tc.desc: RequestSecurityEventInfoAsync with null eventList
388  * @tc.type: FUNC
389  * @tc.require: SR000H96FD
390  */
391 HWTEST_F(DataCollectKitTest, RequestSecurityEventInfoAsync008, TestSize.Level1)
392 {
393     DeviceIdentify deviceIdentify = {};
394     int ret = RequestSecurityEventInfoAsync(&deviceIdentify, nullptr, RequestSecurityEventInfoCallBackFunc);
395     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
396 }
397 
398 /**
399  * @tc.name: QuerySecurityEvent001
400  * @tc.desc: DataCollectManager QuerySecurityEvent
401  * @tc.type: FUNC
402  * @tc.require: AR000IENKB
403  */
404 HWTEST_F(DataCollectKitTest, QuerySecurityEvent001, TestSize.Level1)
405 {
406     std::vector<SecurityCollector::SecurityEventRuler> rulers {};
407     int ret = SecurityGuard::DataCollectManager::GetInstance().QuerySecurityEvent(rulers, nullptr);
408     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
409 }
410 
411 class MockNapiSecurityEventQuerier : public SecurityGuard::SecurityEventQueryCallback {
412 public:
413     MockNapiSecurityEventQuerier() = default;
414     ~MockNapiSecurityEventQuerier() override = default;
OnQuery(const std::vector<SecurityCollector::SecurityEvent> & events)415     void OnQuery(const std::vector<SecurityCollector::SecurityEvent> &events) override {};
OnComplete()416     void OnComplete() override {};
OnError(const std::string & message)417     void OnError(const std::string &message) override {};
418 };
419 
420 HWTEST_F(DataCollectKitTest, QuerySecurityEvent002, TestSize.Level1)
421 {
422     std::vector<SecurityCollector::SecurityEventRuler> rulers {};
423     auto callback = std::make_shared<MockNapiSecurityEventQuerier>();
424     int ret = SecurityGuard::DataCollectManager::GetInstance().QuerySecurityEvent(rulers, callback);
425     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
426 }
427 
428 HWTEST_F(DataCollectKitTest, Mute001, TestSize.Level1)
429 {
430     auto muteinfo = std::make_shared<SecurityGuard::EventMuteFilter> ();
431     muteinfo->eventGroup = "securityGroup";
432     int ret = SecurityGuard::DataCollectManager::GetInstance().Mute(muteinfo);
433     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
434     muteinfo->eventGroup = "";
435     ret = SecurityGuard::DataCollectManager::GetInstance().Mute(muteinfo);
436     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
437     ret = SecurityGuard::DataCollectManager::GetInstance().Mute(nullptr);
438     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
439 }
440 
441 HWTEST_F(DataCollectKitTest, UnMute001, TestSize.Level1)
442 {
443     auto muteinfo = std::make_shared<SecurityGuard::EventMuteFilter> ();
444     muteinfo->eventGroup = "securityGroup";
445     int ret = SecurityGuard::DataCollectManager::GetInstance().Unmute(muteinfo);
446     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
447     muteinfo->eventGroup = "";
448     ret = SecurityGuard::DataCollectManager::GetInstance().Unmute(muteinfo);
449     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
450     ret = SecurityGuard::DataCollectManager::GetInstance().Unmute(nullptr);
451     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
452 }
453 
454 HWTEST_F(DataCollectKitTest, StartCollector001, TestSize.Level1)
455 {
456     SecurityCollector::Event event {};
457     int64_t duration = 0;
458     int ret = SecurityGuard::DataCollectManager::GetInstance().StartCollector(event, duration);
459     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
460 }
461 
462 HWTEST_F(DataCollectKitTest, StopCollector001, TestSize.Level1)
463 {
464     SecurityCollector::Event event {};
465     int ret = SecurityGuard::DataCollectManager::GetInstance().StopCollector(event);
466     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
467 }
468 
469 HWTEST_F(DataCollectKitTest, Mute002, testing::ext::TestSize.Level1)
470 {
471     SecurityGuard::EventMuteFilter info {};
472     SecurityGuard::SecurityEventFilter filter(info);
473     Parcel parcel;
474     bool ret = filter.Marshalling(parcel);
475     EXPECT_TRUE(ret);
476     SecurityGuard::SecurityEventFilter *retInfo = filter.Unmarshalling(parcel);
477     EXPECT_FALSE(retInfo == nullptr);
478 }
479 
480 HWTEST_F(DataCollectKitTest, Mute003, testing::ext::TestSize.Level1)
481 {
482     SecurityGuard::EventMuteFilter info {};
483     SecurityGuard::SecurityEventFilter filter(info);
484     Parcel parcel {};
485     int64_t int64 = 0;
486     uint32_t uint32 = 0;
487     std::string string = "111";
488 
489     bool ret = filter.ReadFromParcel(parcel);
490     EXPECT_FALSE(ret);
491 
492     parcel.WriteInt64(int64);
493     ret = filter.ReadFromParcel(parcel);
494     EXPECT_FALSE(ret);
495 
496     parcel.WriteInt64(int64);
497     parcel.WriteInt64(int64);
498     ret = filter.ReadFromParcel(parcel);
499     EXPECT_FALSE(ret);
500 
501     parcel.WriteInt64(int64);
502     parcel.WriteInt64(int64);
503     parcel.WriteString(string);
504     ret = filter.ReadFromParcel(parcel);
505     EXPECT_FALSE(ret);
506 
507     parcel.WriteInt64(int64);
508     parcel.WriteInt64(int64);
509     parcel.WriteString(string);
510     parcel.WriteUint32(uint32);
511     ret = filter.ReadFromParcel(parcel);
512     EXPECT_TRUE(ret);
513 
514     parcel.WriteInt64(int64);
515     parcel.WriteInt64(int64);
516     parcel.WriteString(string);
517     parcel.WriteUint32(1);
518     ret = filter.ReadFromParcel(parcel);
519     EXPECT_FALSE(ret);
520 
521     parcel.WriteInt64(int64);
522     parcel.WriteInt64(int64);
523     parcel.WriteString(string);
524     parcel.WriteUint32(1);
525     parcel.WriteString(string);
526     ret = filter.ReadFromParcel(parcel);
527     EXPECT_TRUE(ret);
528 
529     SecurityGuard::SecurityEventFilter *retInfo = filter.Unmarshalling(parcel);
530     EXPECT_TRUE(retInfo == nullptr);
531 }
532 
533 HWTEST_F(DataCollectKitTest, Mute004, testing::ext::TestSize.Level1)
534 {
535     SecurityGuard::EventMuteFilter info {};
536     SecurityGuard::SecurityEventFilter filter(info);
537     Parcel parcel {};
538     int64_t int64 = 0;
539     uint32_t uint32 = 10;
540     std::string string = "111";
541     parcel.WriteInt64(int64);
542     parcel.WriteInt64(int64);
543     parcel.WriteString(string);
544     parcel.WriteUint32(uint32);
545     parcel.WriteString(string);
546     bool ret = filter.ReadFromParcel(parcel);
547     EXPECT_FALSE(ret);
548     EXPECT_EQ(filter.GetMuteFilter().eventId, 0);
549 }
550 
551 HWTEST_F(DataCollectKitTest, CallBackIsNull, TestSize.Level1)
552 {
553     SecurityGuard::DataCollectManager::GetInstance().callback_ = nullptr;
554     auto muteinfo = std::make_shared<SecurityGuard::EventMuteFilter> ();
555     muteinfo->eventGroup = "securityGroup";
556     int ret = SecurityGuard::DataCollectManager::GetInstance().Unmute(muteinfo);
557     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
558     ret = SecurityGuard::DataCollectManager::GetInstance().Mute(muteinfo);
559     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
560     ret = SecurityGuard::DataCollectManager::GetInstance().Unsubscribe(g_sub);
561     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
562     ret = SecurityGuard::DataCollectManager::GetInstance().Subscribe(g_sub);
563     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
564 }
565 
566 HWTEST_F(DataCollectKitTest, ReportSecurityEvent01, TestSize.Level1)
567 {
568     int ret = SecurityGuard::DataCollectManager::GetInstance().ReportSecurityEvent(nullptr, true);
569     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
570 }
571 
572 HWTEST_F(DataCollectKitTest, QuerySecurityEventConfig01, TestSize.Level1)
573 {
574     std::string result;
575     int ret = SecurityGuard::DataCollectManager::GetInstance().QuerySecurityEventConfig(result);
576     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
577 }
578 }