From 1daa450471cc6007b29310a12aa02e3d3190926f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Oct 2021 20:16:11 +0000 Subject: [PATCH 1/3] Restyled by whitespace --- src/access/AccessControl.h | 2 +- src/access/DataProvider.h | 10 +++++----- src/access/SubjectDescriptor.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/access/AccessControl.h b/src/access/AccessControl.h index 44ac19f59a93e2..f4af5c29ebbcac 100644 --- a/src/access/AccessControl.h +++ b/src/access/AccessControl.h @@ -54,7 +54,7 @@ class AccessControl /** * Initialize the access control module. Will also initialize its data * provider. - * + * * @retval various errors, probably fatal. * @retval #CHIP_NO_ERROR on success. */ diff --git a/src/access/DataProvider.h b/src/access/DataProvider.h index 99ec289bfdbb67..20884091b7ffdc 100644 --- a/src/access/DataProvider.h +++ b/src/access/DataProvider.h @@ -83,14 +83,14 @@ class EntryIterator /** * Returns the next entry. Must only be called if a next entry exists (see * HasNext). - * + * * @retval the next entry. */ virtual Entry& Next() = 0; /** * Whether a next entry exists. - * + * * @retval true if a next entry exists (next can be called). * @retval false if no next entry exists (next must not be called). */ @@ -124,7 +124,7 @@ class DataProvider /** * Initialize the data provider. - * + * * @retval various errors, probably fatal. * @retval #CHIP_NO_ERROR on success. */ @@ -137,7 +137,7 @@ class DataProvider /** * Get an iterator over all entries. - * + * * @retval iterator, release when finished. * @retval nullptr if error, probably fatal, generally should not happen. */ @@ -145,7 +145,7 @@ class DataProvider /** * Get an iterator over all entries for a particular fabric. - * + * * @retval iterator, release when finished. * @retval nullptr if error, probably fatal, generally should not happen. */ diff --git a/src/access/SubjectDescriptor.h b/src/access/SubjectDescriptor.h index 49482fc0f03611..3042becc83ddfe 100644 --- a/src/access/SubjectDescriptor.h +++ b/src/access/SubjectDescriptor.h @@ -26,7 +26,7 @@ namespace access { /** * @typedef SubjectId - * + * * @brief Access control subject identifier. Can store a PasscodeId, NodeId, * CatId, GroupId, etc. as appropriate. */ @@ -34,7 +34,7 @@ typedef uint64_t SubjectId; /** * @class SubjectDescriptor - * + * * @brief Access control subject descriptor. */ struct SubjectDescriptor From ff1614bca2d5ad47796c99e997d074946bfa3cf9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Oct 2021 20:16:21 +0000 Subject: [PATCH 2/3] Restyled by clang-format --- src/access/AccessControl.cpp | 2 +- src/access/AccessControl.h | 15 +- src/access/AuthMode.h | 6 +- src/access/Config.h | 11 +- src/access/DataProvider.h | 6 +- src/access/DataProviderImpl.cpp | 8 +- src/access/DataProviderImpl.h | 6 +- src/access/Privilege.h | 8 +- src/access/RequestPath.h | 2 +- src/access/tests/TestAccessControl.cpp | 184 +++++++++++-------------- 10 files changed, 105 insertions(+), 143 deletions(-) diff --git a/src/access/AccessControl.cpp b/src/access/AccessControl.cpp index 56a15eedf2fc5a..a4959746a18948 100644 --- a/src/access/AccessControl.cpp +++ b/src/access/AccessControl.cpp @@ -49,7 +49,7 @@ CHIP_ERROR AccessControl::Check(const SubjectDescriptor & subjectDescriptor, con { CHIP_ERROR err = CHIP_ERROR_ACCESS_DENIED; - EntryIterator* iterator = mDataProvider.Entries(subjectDescriptor.fabricIndex); + EntryIterator * iterator = mDataProvider.Entries(subjectDescriptor.fabricIndex); #if 0 ReturnErrorCodeIf(iterator == nullptr, CHIP_ERROR_INTERNAL); #else diff --git a/src/access/AccessControl.h b/src/access/AccessControl.h index f4af5c29ebbcac..9bead9c873f911 100644 --- a/src/access/AccessControl.h +++ b/src/access/AccessControl.h @@ -43,10 +43,7 @@ class AccessControl * uninitialized DataProvider must be provided, and the module must then be * initialized before use, and deinitialized when finished. */ - AccessControl(DataProvider & dataProvider) - : mDataProvider(dataProvider) - { - } + AccessControl(DataProvider & dataProvider) : mDataProvider(dataProvider) {} AccessControl(const AccessControl &) = delete; AccessControl & operator=(const AccessControl &) = delete; @@ -84,20 +81,14 @@ class AccessControl * * @retval nullptr if configured so. */ - static AccessControl * GetInstance() - { - return mInstance; - } + static AccessControl * GetInstance() { return mInstance; } /** * Set the configured instance, for advanced use (e.g. testing). Does not * call Init or Finish (so ensure that happens appropriately). The * configured instance can be cleared (by setting to nullptr). */ - static void SetInstance(AccessControl * instance) - { - mInstance = instance; - } + static void SetInstance(AccessControl * instance) { mInstance = instance; } private: DataProvider & mDataProvider; diff --git a/src/access/AuthMode.h b/src/access/AuthMode.h index b004f73da3d293..6cdd1872b3f90e 100644 --- a/src/access/AuthMode.h +++ b/src/access/AuthMode.h @@ -29,9 +29,9 @@ namespace access { */ enum AuthMode { - kNone = 0, - kPase = 1 << 5, - kCase = 1 << 6, + kNone = 0, + kPase = 1 << 5, + kCase = 1 << 6, kGroup = 1 << 7 }; diff --git a/src/access/Config.h b/src/access/Config.h index c29da75e831830..d5aac62f9f10cc 100644 --- a/src/access/Config.h +++ b/src/access/Config.h @@ -26,15 +26,14 @@ namespace access { struct Config { -// Data provider implementation used by AccessControl configured instance. -typedef DataProviderImpl DataProvider; + // Data provider implementation used by AccessControl configured instance. + typedef DataProviderImpl DataProvider; -static const int kSubjectsPerEntry = 4; + static const int kSubjectsPerEntry = 4; -static const int kTargetsPerEntry = 3; - -static const int kEntriesPerFabric = 3; + static const int kTargetsPerEntry = 3; + static const int kEntriesPerFabric = 3; }; } // namespace access diff --git a/src/access/DataProvider.h b/src/access/DataProvider.h index 20884091b7ffdc..8645a8eba1bcca 100644 --- a/src/access/DataProvider.h +++ b/src/access/DataProvider.h @@ -86,7 +86,7 @@ class EntryIterator * * @retval the next entry. */ - virtual Entry& Next() = 0; + virtual Entry & Next() = 0; /** * Whether a next entry exists. @@ -141,7 +141,7 @@ class DataProvider * @retval iterator, release when finished. * @retval nullptr if error, probably fatal, generally should not happen. */ - virtual EntryIterator* Entries() const = 0; + virtual EntryIterator * Entries() const = 0; /** * Get an iterator over all entries for a particular fabric. @@ -149,7 +149,7 @@ class DataProvider * @retval iterator, release when finished. * @retval nullptr if error, probably fatal, generally should not happen. */ - virtual EntryIterator* Entries(FabricIndex fabricIndex) const = 0; + virtual EntryIterator * Entries(FabricIndex fabricIndex) const = 0; }; } // namespace access diff --git a/src/access/DataProviderImpl.cpp b/src/access/DataProviderImpl.cpp index 67ef687c4a3590..6c590c15243700 100644 --- a/src/access/DataProviderImpl.cpp +++ b/src/access/DataProviderImpl.cpp @@ -26,17 +26,15 @@ CHIP_ERROR DataProviderImpl::Init() return CHIP_NO_ERROR; } -void DataProviderImpl::Finish() -{ -} +void DataProviderImpl::Finish() {} -EntryIterator* DataProviderImpl::Entries() const +EntryIterator * DataProviderImpl::Entries() const { // TODO: provide iterator return nullptr; } -EntryIterator* DataProviderImpl::Entries(FabricIndex fabricIndex) const +EntryIterator * DataProviderImpl::Entries(FabricIndex fabricIndex) const { // TODO: provide iterator return nullptr; diff --git a/src/access/DataProviderImpl.h b/src/access/DataProviderImpl.h index 7f573ff873bafe..008b56a1744b4b 100644 --- a/src/access/DataProviderImpl.h +++ b/src/access/DataProviderImpl.h @@ -31,14 +31,14 @@ namespace access { class DataProviderImpl : public DataProvider { public: - DataProviderImpl() = default; + DataProviderImpl() = default; virtual ~DataProviderImpl() = default; CHIP_ERROR Init() override; void Finish() override; - EntryIterator* Entries() const override; - EntryIterator* Entries(FabricIndex fabricIndex) const override; + EntryIterator * Entries() const override; + EntryIterator * Entries(FabricIndex fabricIndex) const override; }; } // namespace access diff --git a/src/access/Privilege.h b/src/access/Privilege.h index 63122a8f7c4aeb..381f179ea8cdc8 100644 --- a/src/access/Privilege.h +++ b/src/access/Privilege.h @@ -29,10 +29,10 @@ namespace access { */ enum Privilege { - kView = 1 << 0, - kProxyView = 1 << 1, - kOperate = 1 << 2, - kManage = 1 << 3, + kView = 1 << 0, + kProxyView = 1 << 1, + kOperate = 1 << 2, + kManage = 1 << 3, kAdminister = 1 << 4 }; diff --git a/src/access/RequestPath.h b/src/access/RequestPath.h index 26b8d89d4fbcbc..badcc836353820 100644 --- a/src/access/RequestPath.h +++ b/src/access/RequestPath.h @@ -32,7 +32,7 @@ struct RequestPath { // TODO: don't worry about node for now (proxy source) EndpointId endpoint = 0; - ClusterId cluster = 0; + ClusterId cluster = 0; }; } // namespace access diff --git a/src/access/tests/TestAccessControl.cpp b/src/access/tests/TestAccessControl.cpp index 45a91db3adcb40..a4d58d11289c79 100644 --- a/src/access/tests/TestAccessControl.cpp +++ b/src/access/tests/TestAccessControl.cpp @@ -30,9 +30,9 @@ namespace { using namespace chip::access; // Some cluster IDs -const ClusterId ONOFF = 0x00000006; -const ClusterId LEVELCONTROL = 0x00000008; -const ClusterId COLORCONTROL = 0x00000300; +const ClusterId ONOFF = 0x00000006; +const ClusterId LEVELCONTROL = 0x00000008; +const ClusterId COLORCONTROL = 0x00000300; const ClusterId ACCESSCONTROL = 0x0000001F; // Used to detect empty subjects, targets, etc. @@ -77,8 +77,8 @@ struct TestTarget enum Flag { kDeviceType = 1 << 0, - kEndpoint = 1 << 1, - kCluster = 1 << 2, + kEndpoint = 1 << 1, + kCluster = 1 << 2, }; int flags = SENTINEL; @@ -89,11 +89,7 @@ struct TestTarget TestTarget Target(EndpointId endpoint, ClusterId cluster) { - return { - .flags = TestTarget::kEndpoint | TestTarget::kCluster, - .endpoint = endpoint, - .cluster = cluster - }; + return { .flags = TestTarget::kEndpoint | TestTarget::kCluster, .endpoint = endpoint, .cluster = cluster }; } #if 0 @@ -111,54 +107,53 @@ TestTarget Target(ClusterId cluster) struct TestEntryDelegate { FabricIndex fabricIndex = 0; - AuthMode authMode = AuthMode::kNone; // aka SENTINEL - Privilege privilege = Privilege::kView; + AuthMode authMode = AuthMode::kNone; // aka SENTINEL + Privilege privilege = Privilege::kView; TestSubject subjects[Config::kSubjectsPerEntry + 1]; TestTarget targets[Config::kTargetsPerEntry + 1]; }; -TestEntryDelegate entries[] = -{ +TestEntryDelegate entries[] = { { .fabricIndex = 1, - .authMode = AuthMode::kCase, - .privilege = Privilege::kAdminister, - .subjects = { Node(0x1122334455667788) }, + .authMode = AuthMode::kCase, + .privilege = Privilege::kAdminister, + .subjects = { Node(0x1122334455667788) }, }, { .fabricIndex = 2, - .authMode = AuthMode::kCase, - .privilege = Privilege::kAdminister, - .subjects = { Node(0x8877665544332211) }, + .authMode = AuthMode::kCase, + .privilege = Privilege::kAdminister, + .subjects = { Node(0x8877665544332211) }, }, { .fabricIndex = 2, - .authMode = AuthMode::kCase, - .privilege = Privilege::kView, + .authMode = AuthMode::kCase, + .privilege = Privilege::kView, }, { .fabricIndex = 1, - .authMode = AuthMode::kPase, - .privilege = Privilege::kView, - .targets = { Target(2, ONOFF )}, + .authMode = AuthMode::kPase, + .privilege = Privilege::kView, + .targets = { Target(2, ONOFF) }, }, { .fabricIndex = 1, - .authMode = AuthMode::kCase, - .privilege = Privilege::kView, - .targets = { Target(1, LEVELCONTROL )}, + .authMode = AuthMode::kCase, + .privilege = Privilege::kView, + .targets = { Target(1, LEVELCONTROL) }, }, { .fabricIndex = 1, - .authMode = AuthMode::kCase, - .privilege = Privilege::kOperate, - .targets = { Target(1, COLORCONTROL )}, + .authMode = AuthMode::kCase, + .privilege = Privilege::kOperate, + .targets = { Target(1, COLORCONTROL) }, }, { .fabricIndex = 1, - .authMode = AuthMode::kCase, - .privilege = Privilege::kView, - .targets = { Target(2, ONOFF )}, + .authMode = AuthMode::kCase, + .privilege = Privilege::kView, + .targets = { Target(2, ONOFF) }, }, {} // sentinel entry }; @@ -168,37 +163,37 @@ class TestEntry : public Entry public: virtual ~TestEntry() = default; - bool MatchesAuthMode(AuthMode authMode) const override - { - return delegate->authMode == authMode; - } + bool MatchesAuthMode(AuthMode authMode) const override { return delegate->authMode == authMode; } - bool MatchesFabric(FabricIndex fabricIndex) const override - { - return delegate->fabricIndex == fabricIndex; - } + bool MatchesFabric(FabricIndex fabricIndex) const override { return delegate->fabricIndex == fabricIndex; } bool MatchesPrivilege(Privilege privilege) const override { switch (privilege) { - case Privilege::kProxyView: - return (delegate->privilege == Privilege::kProxyView) - || (delegate->privilege == Privilege::kAdminister); - case Privilege::kView: if (delegate->privilege == Privilege::kView) return true; - // fall through - case Privilege::kOperate: if (delegate->privilege == Privilege::kOperate) return true; - // fall through - case Privilege::kManage: if (delegate->privilege == Privilege::kManage) return true; - // fall through - case Privilege::kAdminister: return delegate->privilege == Privilege::kAdminister; + case Privilege::kProxyView: + return (delegate->privilege == Privilege::kProxyView) || (delegate->privilege == Privilege::kAdminister); + case Privilege::kView: + if (delegate->privilege == Privilege::kView) + return true; + // fall through + case Privilege::kOperate: + if (delegate->privilege == Privilege::kOperate) + return true; + // fall through + case Privilege::kManage: + if (delegate->privilege == Privilege::kManage) + return true; + // fall through + case Privilege::kAdminister: + return delegate->privilege == Privilege::kAdminister; } return false; } bool MatchesSubject(SubjectId subject) const override { - TestSubject* p = delegate->subjects; + TestSubject * p = delegate->subjects; if (p->id == SENTINEL) return true; for (; p->id != SENTINEL; ++p) @@ -211,13 +206,13 @@ class TestEntry : public Entry bool MatchesTarget(EndpointId endpoint, ClusterId cluster) const override { - TestTarget* p = delegate->targets; + TestTarget * p = delegate->targets; if (p->flags == SENTINEL) return true; for (; p->flags != SENTINEL; ++p) { - if (((p->flags & TestTarget::kEndpoint) == 0 || p->endpoint == endpoint) - && ((p->flags & TestTarget::kCluster) == 0 || p->cluster == cluster)) + if (((p->flags & TestTarget::kEndpoint) == 0 || p->endpoint == endpoint) && + ((p->flags & TestTarget::kCluster) == 0 || p->cluster == cluster)) return true; } return false; @@ -240,9 +235,9 @@ class TestEntryIterator : public EntryIterator void Initialize(FabricIndex fabricIndex_) { - fabricFiltered = true; + fabricFiltered = true; this->fabricIndex = fabricIndex_; - entry.delegate = nullptr; + entry.delegate = nullptr; FindNext(); } @@ -261,7 +256,7 @@ class TestEntryIterator : public EntryIterator } } - Entry& Next() override + Entry & Next() override { if (HasNext()) { @@ -271,14 +266,9 @@ class TestEntryIterator : public EntryIterator return entry; } - bool HasNext() override - { - return next != nullptr; - } + bool HasNext() override { return next != nullptr; } - void Release() override - { - } + void Release() override {} bool fabricFiltered; FabricIndex fabricIndex; @@ -290,25 +280,20 @@ class TestEntryIterator : public EntryIterator class TestDataProvider : public DataProvider { public: - TestDataProvider() = default; + TestDataProvider() = default; virtual ~TestDataProvider() = default; - CHIP_ERROR Init() override - { - return CHIP_NO_ERROR; - } + CHIP_ERROR Init() override { return CHIP_NO_ERROR; } - void Finish() override - { - } + void Finish() override {} - EntryIterator* Entries() const override + EntryIterator * Entries() const override { iterator.Initialize(); return &iterator; } - EntryIterator* Entries(FabricIndex fabricIndex) const override + EntryIterator * Entries(FabricIndex fabricIndex) const override { iterator.Initialize(fabricIndex); return &iterator; @@ -320,23 +305,22 @@ class TestDataProvider : public DataProvider TestDataProvider testDataProvider; AccessControl testAccessControl(testDataProvider); -#define USE_CONTEXT() \ - AccessControl & context = *reinterpret_cast(inContext); +#define USE_CONTEXT() AccessControl & context = *reinterpret_cast(inContext); void MetaTestIterator(nlTestSuite * inSuite, void * inContext) { - EntryIterator* iterator = testDataProvider.Entries(); + EntryIterator * iterator = testDataProvider.Entries(); NL_TEST_ASSERT(inSuite, iterator != nullptr); - TestEntryDelegate* p = entries; + TestEntryDelegate * p = entries; while (iterator->HasNext()) { auto & entry = iterator->Next(); - NL_TEST_ASSERT_LOOP(inSuite, int(p - entries), static_cast(entry).delegate == p); + NL_TEST_ASSERT_LOOP(inSuite, int(p - entries), static_cast(entry).delegate == p); ++p; } - NL_TEST_ASSERT(inSuite, p == entries + sizeof(entries)/sizeof(entries[0]) - 1); + NL_TEST_ASSERT(inSuite, p == entries + sizeof(entries) / sizeof(entries[0]) - 1); } void TestCheck(nlTestSuite * inSuite, void * inContext) @@ -347,16 +331,12 @@ void TestCheck(nlTestSuite * inSuite, void * inContext) // TODO: make this table driven, add a bunch more test cases - err = context.Check( - {.subject = 0x1122334455667788, .authMode = AuthMode::kCase, .fabricIndex = 1}, - {.endpoint = 1, .cluster = ONOFF}, - Privilege::kAdminister); + err = context.Check({ .subject = 0x1122334455667788, .authMode = AuthMode::kCase, .fabricIndex = 1 }, + { .endpoint = 1, .cluster = ONOFF }, Privilege::kAdminister); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = context.Check( - {.subject = 0x8877665544332211, .authMode = AuthMode::kCase, .fabricIndex = 1}, - {.endpoint = 1, .cluster = ONOFF}, - Privilege::kAdminister); + err = context.Check({ .subject = 0x8877665544332211, .authMode = AuthMode::kCase, .fabricIndex = 1 }, + { .endpoint = 1, .cluster = ONOFF }, Privilege::kAdminister); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED); } @@ -405,22 +385,16 @@ int Terminate(void * inContext) int TestAccessControl() { - const nlTest tests[] = - { - NL_TEST_DEF("MetaTestIterator", MetaTestIterator), - NL_TEST_DEF("TestInstance", TestInstance), - NL_TEST_DEF("TestCheck", TestCheck), - NL_TEST_SENTINEL() - }; - - nlTestSuite suite = - { - .name = "AccessControl", - .tests = tests, - .setup = Setup, - .tear_down = Teardown, + const nlTest tests[] = { NL_TEST_DEF("MetaTestIterator", MetaTestIterator), NL_TEST_DEF("TestInstance", TestInstance), + NL_TEST_DEF("TestCheck", TestCheck), NL_TEST_SENTINEL() }; + + nlTestSuite suite = { + .name = "AccessControl", + .tests = tests, + .setup = Setup, + .tear_down = Teardown, .initialize = Initialize, - .terminate = Terminate, + .terminate = Terminate, }; nlTestRunner(&suite, &testAccessControl); From 6ec895407d2c373effde408b49c48d937ef22a47 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Oct 2021 20:16:27 +0000 Subject: [PATCH 3/3] Restyled by gn --- src/access/tests/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/access/tests/BUILD.gn b/src/access/tests/BUILD.gn index 7bc63312158b5b..c6986e5934c9b3 100644 --- a/src/access/tests/BUILD.gn +++ b/src/access/tests/BUILD.gn @@ -21,9 +21,7 @@ import("${chip_root}/build/chip/chip_test_suite.gni") chip_test_suite("tests") { output_name = "libaccesstest" - test_sources = [ - "TestAccessControl.cpp", - ] + test_sources = [ "TestAccessControl.cpp" ] cflags = [ "-Wconversion" ]