@@ -333,6 +333,7 @@ class TestReadInteraction
333
333
static void TestReadClientGenerateOneEventPaths (nlTestSuite * apSuite, void * apContext);
334
334
static void TestReadClientGenerateTwoEventPaths (nlTestSuite * apSuite, void * apContext);
335
335
static void TestReadClientInvalidReport (nlTestSuite * apSuite, void * apContext);
336
+ static void TestReadClientInvalidAttributeId (nlTestSuite * apSuite, void * apContext);
336
337
static void TestReadHandlerInvalidAttributePath (nlTestSuite * apSuite, void * apContext);
337
338
static void TestProcessSubscribeRequest (nlTestSuite * apSuite, void * apContext);
338
339
#if CHIP_CONFIG_ENABLE_ICD_SERVER
@@ -390,12 +391,19 @@ class TestReadInteraction
390
391
static void TestReadHandlerMalformedSubscribeRequest (nlTestSuite * apSuite, void * apContext);
391
392
392
393
private:
394
+ enum class ReportType : uint8_t
395
+ {
396
+ kValid ,
397
+ kInvalidNoAttributeId ,
398
+ kInvalidOutOfRangeAttributeId ,
399
+ };
400
+
393
401
static void GenerateReportData (nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
394
- bool aNeedInvalidReport , bool aSuppressResponse, bool aHasSubscriptionId);
402
+ ReportType aReportType , bool aSuppressResponse, bool aHasSubscriptionId);
395
403
};
396
404
397
405
void TestReadInteraction::GenerateReportData (nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
398
- bool aNeedInvalidReport , bool aSuppressResponse, bool aHasSubscriptionId = false )
406
+ ReportType aReportType , bool aSuppressResponse, bool aHasSubscriptionId = false )
399
407
{
400
408
CHIP_ERROR err = CHIP_NO_ERROR;
401
409
System::PacketBufferTLVWriter writer;
@@ -428,12 +436,17 @@ void TestReadInteraction::GenerateReportData(nlTestSuite * apSuite, void * apCon
428
436
AttributePathIB::Builder & attributePathBuilder = attributeDataIBBuilder.CreatePath ();
429
437
NL_TEST_ASSERT (apSuite, attributeDataIBBuilder.GetError () == CHIP_NO_ERROR);
430
438
431
- if (aNeedInvalidReport )
439
+ if (aReportType == ReportType:: kInvalidNoAttributeId )
432
440
{
433
441
attributePathBuilder.Node (1 ).Endpoint (2 ).Cluster (3 ).ListIndex (5 ).EndOfAttributePathIB ();
434
442
}
443
+ else if (aReportType == ReportType::kInvalidOutOfRangeAttributeId )
444
+ {
445
+ attributePathBuilder.Node (1 ).Endpoint (2 ).Cluster (3 ).Attribute (0xFFF18000 ).EndOfAttributePathIB ();
446
+ }
435
447
else
436
448
{
449
+ NL_TEST_ASSERT (apSuite, aReportType == ReportType::kValid );
437
450
attributePathBuilder.Node (1 ).Endpoint (2 ).Cluster (3 ).Attribute (4 ).EndOfAttributePathIB ();
438
451
}
439
452
@@ -496,7 +509,7 @@ void TestReadInteraction::TestReadClient(nlTestSuite * apSuite, void * apContext
496
509
ctx.GetLoopback ().mNumMessagesToDrop = 1 ;
497
510
ctx.DrainAndServiceIO ();
498
511
499
- GenerateReportData (apSuite, apContext, buf, false /* aNeedInvalidReport */ , true /* aSuppressResponse*/ );
512
+ GenerateReportData (apSuite, apContext, buf, ReportType:: kValid , true /* aSuppressResponse*/ );
500
513
err = readClient.ProcessReportData (std::move (buf), ReadClient::ReportType::kContinuingTransaction );
501
514
NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
502
515
}
@@ -521,8 +534,7 @@ void TestReadInteraction::TestReadUnexpectedSubscriptionId(nlTestSuite * apSuite
521
534
ctx.DrainAndServiceIO ();
522
535
523
536
// For read, we don't expect there is subscription id in report data.
524
- GenerateReportData (apSuite, apContext, buf, false /* aNeedInvalidReport*/ , true /* aSuppressResponse*/ ,
525
- true /* aHasSubscriptionId*/ );
537
+ GenerateReportData (apSuite, apContext, buf, ReportType::kValid , true /* aSuppressResponse*/ , true /* aHasSubscriptionId*/ );
526
538
err = readClient.ProcessReportData (std::move (buf), ReadClient::ReportType::kContinuingTransaction );
527
539
NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INVALID_ARGUMENT);
528
540
}
@@ -547,7 +559,7 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex
547
559
ReadHandler readHandler (nullCallback, exchangeCtx, chip::app::ReadHandler::InteractionType::Read,
548
560
app::reporting::GetDefaultReportScheduler ());
549
561
550
- GenerateReportData (apSuite, apContext, reportDatabuf, false /* aNeedInvalidReport */ , false /* aSuppressResponse*/ );
562
+ GenerateReportData (apSuite, apContext, reportDatabuf, ReportType:: kValid , false /* aSuppressResponse*/ );
551
563
err = readHandler.SendReportData (std::move (reportDatabuf), false );
552
564
NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
553
565
@@ -665,12 +677,46 @@ void TestReadInteraction::TestReadClientInvalidReport(nlTestSuite * apSuite, voi
665
677
ctx.GetLoopback ().mNumMessagesToDrop = 1 ;
666
678
ctx.DrainAndServiceIO ();
667
679
668
- GenerateReportData (apSuite, apContext, buf, true /* aNeedInvalidReport */ , true /* aSuppressResponse*/ );
680
+ GenerateReportData (apSuite, apContext, buf, ReportType:: kInvalidNoAttributeId , true /* aSuppressResponse*/ );
669
681
670
682
err = readClient.ProcessReportData (std::move (buf), ReadClient::ReportType::kContinuingTransaction );
671
683
NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB);
672
684
}
673
685
686
+ void TestReadInteraction::TestReadClientInvalidAttributeId (nlTestSuite * apSuite, void * apContext)
687
+ {
688
+ CHIP_ERROR err = CHIP_NO_ERROR;
689
+ TestContext & ctx = *static_cast <TestContext *>(apContext);
690
+ MockInteractionModelApp delegate;
691
+
692
+ System::PacketBufferHandle buf = System::PacketBufferHandle::New (System::PacketBuffer::kMaxSize );
693
+
694
+ app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &ctx.GetExchangeManager (), delegate,
695
+ chip::app::ReadClient::InteractionType::Read);
696
+
697
+ ReadPrepareParams readPrepareParams (ctx.GetSessionBobToAlice ());
698
+ err = readClient.SendRequest (readPrepareParams);
699
+ NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
700
+
701
+ // We don't actually want to deliver that message, because we want to
702
+ // synthesize the read response. But we don't want it hanging around
703
+ // forever either.
704
+ ctx.GetLoopback ().mNumMessagesToDrop = 1 ;
705
+ ctx.DrainAndServiceIO ();
706
+
707
+ GenerateReportData (apSuite, apContext, buf, ReportType::kInvalidOutOfRangeAttributeId , true /* aSuppressResponse*/ );
708
+
709
+ err = readClient.ProcessReportData (std::move (buf), ReadClient::ReportType::kContinuingTransaction );
710
+ // Overall processing should succeed.
711
+ NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
712
+
713
+ // We should not have gotten any attribute reports or errors.
714
+ NL_TEST_ASSERT (apSuite, !delegate.mGotEventResponse );
715
+ NL_TEST_ASSERT (apSuite, delegate.mNumAttributeResponse == 0 );
716
+ NL_TEST_ASSERT (apSuite, !delegate.mGotReport );
717
+ NL_TEST_ASSERT (apSuite, !delegate.mReadError );
718
+ }
719
+
674
720
void TestReadInteraction::TestReadHandlerInvalidAttributePath (nlTestSuite * apSuite, void * apContext)
675
721
{
676
722
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -691,7 +737,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu
691
737
ReadHandler readHandler (nullCallback, exchangeCtx, chip::app::ReadHandler::InteractionType::Read,
692
738
app::reporting::GetDefaultReportScheduler ());
693
739
694
- GenerateReportData (apSuite, apContext, reportDatabuf, false /* aNeedInvalidReport */ , false /* aSuppressResponse*/ );
740
+ GenerateReportData (apSuite, apContext, reportDatabuf, ReportType:: kValid , false /* aSuppressResponse*/ );
695
741
err = readHandler.SendReportData (std::move (reportDatabuf), false );
696
742
NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
697
743
@@ -4941,6 +4987,7 @@ const nlTest sTests[] =
4941
4987
NL_TEST_DEF (" TestReadClientGenerateOneEventPaths" , chip::app::TestReadInteraction::TestReadClientGenerateOneEventPaths),
4942
4988
NL_TEST_DEF (" TestReadClientGenerateTwoEventPaths" , chip::app::TestReadInteraction::TestReadClientGenerateTwoEventPaths),
4943
4989
NL_TEST_DEF (" TestReadClientInvalidReport" , chip::app::TestReadInteraction::TestReadClientInvalidReport),
4990
+ NL_TEST_DEF (" TestReadClientInvalidAttributeId" , chip::app::TestReadInteraction::TestReadClientInvalidAttributeId),
4944
4991
NL_TEST_DEF (" TestReadHandlerInvalidAttributePath" , chip::app::TestReadInteraction::TestReadHandlerInvalidAttributePath),
4945
4992
NL_TEST_DEF (" TestProcessSubscribeRequest" , chip::app::TestReadInteraction::TestProcessSubscribeRequest),
4946
4993
/*
0 commit comments