Skip to content

Commit ea8356f

Browse files
committed
Another unit test for AAI this time for unsupported read
1 parent 39b4b11 commit ea8356f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/app/codegen-data-model/tests/TestCodegenModelViaMocks.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,28 @@ CHIP_ERROR DecodeList(TLV::TLVReader & reader, std::vector<T> & out)
373373
}
374374
}
375375

376+
class UnsupportedReadAccessInterface : public AttributeAccessInterface
377+
{
378+
public:
379+
UnsupportedReadAccessInterface(ConcreteAttributePath path) :
380+
AttributeAccessInterface(MakeOptional(path.mEndpointId), path.mClusterId), mPath(path)
381+
{}
382+
~UnsupportedReadAccessInterface() = default;
383+
384+
CHIP_ERROR Read(const ConcreteReadAttributePath & path, AttributeValueEncoder & encoder) override
385+
{
386+
if (static_cast<const ConcreteAttributePath &>(path) != mPath)
387+
{
388+
// returning without trying to handle means "I do not handle this"
389+
return CHIP_NO_ERROR;
390+
}
391+
392+
return CHIP_IM_GLOBAL_STATUS(UnsupportedRead);
393+
}
394+
private:
395+
ConcreteAttributePath mPath;
396+
};
397+
376398
class StructAttributeAccessInterface : public AttributeAccessInterface
377399
{
378400
public:
@@ -1049,6 +1071,27 @@ TEST(TestCodegenModelViaMocks, EmberAttributePathExpansionAccessDeniedRead)
10491071
ASSERT_FALSE(encoder->TriedEncode());
10501072
}
10511073

1074+
TEST(TestCodegenModelViaMocks, AccessInterfaceUnsupportedRead) {
1075+
UseMockNodeConfig config(gTestNodeConfig);
1076+
chip::app::CodegenDataModel model;
1077+
ScopedMockAccessControl accessControl;
1078+
1079+
const ConcreteAttributePath kTestPath(kMockEndpoint3, MockClusterId(4),
1080+
MOCK_ATTRIBUTE_ID_FOR_NON_NULLABLE_TYPE(ZCL_STRUCT_ATTRIBUTE_TYPE));
1081+
1082+
TestReadRequest testRequest(kAdminSubjectDescriptor, kTestPath);
1083+
RegisteredAttributeAccessInterface<UnsupportedReadAccessInterface> aai(kTestPath);
1084+
1085+
testRequest.request.path.mExpanded = true;
1086+
1087+
// For expanded paths, unsupported read from AAI (i.e. reading write-only data)
1088+
// succeed without attempting to encode.
1089+
// This is temporary until ACL checks are moved inside the IM/ReportEngine
1090+
std::unique_ptr<AttributeValueEncoder> encoder = testRequest.StartEncoding(&model);
1091+
ASSERT_EQ(model.ReadAttribute(testRequest.request, *encoder), CHIP_NO_ERROR);
1092+
ASSERT_FALSE(encoder->TriedEncode());
1093+
}
1094+
10521095
TEST(TestCodegenModelViaMocks, EmberAttributeReadInt32S)
10531096
{
10541097
TestEmberScalarTypeRead<int32_t, ZCL_INT32S_ATTRIBUTE_TYPE>(-1234);

0 commit comments

Comments
 (0)