diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 79a20235132133..1ec4fbf43e26f2 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -63,11 +63,7 @@ declare_args() { config("enhanced_setup_flow_config") { defines = [] if (chip_config_tc_required) { - defines += [ - "CHIP_CONFIG_TC_REQUIRED=1", - "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS=${chip_config_tc_required_acknowledgements}", - "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION=${chip_config_tc_required_acknowledgements_version}", - ] + defines += [ "CHIP_CONFIG_TC_REQUIRED=1" ] } else { defines += [ "CHIP_CONFIG_TC_REQUIRED=0" ] } @@ -93,6 +89,13 @@ buildconfig_header("app_buildconfig") { "CHIP_CONFIG_ENABLE_BUSY_HANDLING_FOR_OPERATIONAL_SESSION_SETUP=${chip_enable_busy_handling_for_operational_session_setup}", ] + if (chip_config_tc_required) { + defines += [ + "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS=${chip_config_tc_required_acknowledgements}", + "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION=${chip_config_tc_required_acknowledgements_version}", + ] + } + if (chip_use_data_model_interface == "disabled") { defines += [ "CHIP_CONFIG_USE_DATA_MODEL_INTERFACE=0", diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index a8d8b979643a9b..f1b7bd6b15f516 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -304,8 +304,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( else { #if CHIP_CONFIG_TC_REQUIRED - // CheckSuccess(CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(response.errorCode), Failure); - EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider(); Optional acceptedTermsAndConditions; diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp index f90ca2cb609140..e157fb220d0e82 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp @@ -24,9 +24,7 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider) { VerifyOrReturnError(nullptr != inTermsAndConditionsProvider, CHIP_ERROR_INVALID_ARGUMENT); - mTermsAndConditionsProvider = inTermsAndConditionsProvider; - return CHIP_NO_ERROR; } @@ -55,11 +53,17 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::SetTermsAndConditionsAcc return CHIP_NO_ERROR; } +CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::ResetTermsAndConditionsAcceptance() +{ + VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED); + ReturnErrorOnFailure(mTermsAndConditionsProvider->ResetAcceptance()); + return CHIP_NO_ERROR; +} + CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::RevertTermsAndConditionsAcceptance() { VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED); ReturnErrorOnFailure(mTermsAndConditionsProvider->RevertAcceptance()); - return CHIP_NO_ERROR; } @@ -67,6 +71,5 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::CommitTermsAndConditions { VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED); ReturnErrorOnFailure(mTermsAndConditionsProvider->CommitAcceptance()); - return CHIP_NO_ERROR; } diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.h b/src/app/server/DefaultEnhancedSetupFlowProvider.h index 0dba132d306ec4..8a20427a2ba98c 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.h +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.h @@ -45,6 +45,8 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider virtual CHIP_ERROR SetTermsAndConditionsAcceptance(const Optional & inTermsAndConditions) override; + virtual CHIP_ERROR ResetTermsAndConditionsAcceptance() override; + virtual CHIP_ERROR RevertTermsAndConditionsAcceptance() override; virtual CHIP_ERROR CommitTermsAndConditionsAcceptance() override; diff --git a/src/app/server/DefaultTermsAndConditionsProvider.cpp b/src/app/server/DefaultTermsAndConditionsProvider.cpp index e3acb855948ce5..b07cafc9ad2cfc 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.cpp +++ b/src/app/server/DefaultTermsAndConditionsProvider.cpp @@ -26,6 +26,37 @@ #include #include +#if 0 +/** + * @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS + * + * @brief Configures the required terms and conditions acknowledgements bitmask. + * + * This macro defines the required terms and conditions acknowledgements bitmask. The bit-field is 16 bits long, so the possible + * value range is [0, 65535). This setting can be used to require that terms and conditions are presented to the user during + * commissioning. + */ +#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS +#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS must be defined when CHIP_CONFIG_TC_REQUIRED is enabled." +#endif + +/** + * @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION + * + * @brief Configures the latest known version of the terms and conditions. + * + * This macro defines the version number of the latest terms and conditions. It allows the application to iterate on revisions of + * the terms and conditions. A value of 0 indicates that no specific version is required. This setting can be used to enforce + * version-specific terms and conditions acknowledgements in the application. When the set of terms and conditions needs to be + * changed, the version number should be monotonically increased. If the latest terms and conditions version is updated (most + * likely during an OTA), then this may signal to the Administrator that updated terms and conditions should be presented to the + * user. + */ +#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION +#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION must be defined when CHIP_CONFIG_TC_REQUIRED is enabled." +#endif +#endif // 0 + namespace { constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::ContextTag(1); constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(2); @@ -39,16 +70,14 @@ constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(siz 2; // Extra space for rollback compatibility } // namespace -CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate) +CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init( + chip::PersistentStorageDelegate * const inPersistentStorageDelegate, + const chip::Optional & inRequiredTermsAndConditions) { VerifyOrReturnError(nullptr != inPersistentStorageDelegate, CHIP_ERROR_INVALID_ARGUMENT); mPersistentStorageDelegate = inPersistentStorageDelegate; - - mRequiredAcknowledgements = Optional({ - .value = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS, - .version = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION, - }); + mRequiredAcknowledgements = inRequiredTermsAndConditions; if (CHIP_NO_ERROR == LoadAcceptance(mLatchedAcceptance)) { @@ -60,7 +89,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentSt CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::RevertAcceptance() { - mTemporalAcceptance.SetValue(mLatchedAcceptance.Value()); + mTemporalAcceptance = mLatchedAcceptance; return CHIP_NO_ERROR; } @@ -77,23 +106,13 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::CommitAcceptance() CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(Optional & outTermsAndConditions) const { - if (!mTemporalAcceptance.HasValue()) - { - return CHIP_ERROR_INCORRECT_STATE; - } - - outTermsAndConditions.SetValue(mTemporalAcceptance.Value()); + outTermsAndConditions = mTemporalAcceptance; return CHIP_NO_ERROR; } CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(Optional & outTermsAndConditions) const { - if (!mRequiredAcknowledgements.HasValue()) - { - return CHIP_ERROR_INCORRECT_STATE; - } - - outTermsAndConditions.SetValue(mRequiredAcknowledgements.Value()); + outTermsAndConditions = mRequiredAcknowledgements; return CHIP_NO_ERROR; } diff --git a/src/app/server/DefaultTermsAndConditionsProvider.h b/src/app/server/DefaultTermsAndConditionsProvider.h index af86f8a4c95fed..fc3e49e61f7613 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.h +++ b/src/app/server/DefaultTermsAndConditionsProvider.h @@ -36,7 +36,8 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider * * @param[in] inPersistentStorageDelegate Persistent storage delegate dependency. */ - CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate); + CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate, + const chip::Optional & inRequiredTermsAndConditions); CHIP_ERROR SetAcceptance(const Optional & inTermsAndConditions) override; diff --git a/src/app/server/EnhancedSetupFlowProvider.h b/src/app/server/EnhancedSetupFlowProvider.h index e4b5ce7ce89864..800bf699b3cf73 100644 --- a/src/app/server/EnhancedSetupFlowProvider.h +++ b/src/app/server/EnhancedSetupFlowProvider.h @@ -41,6 +41,8 @@ class EnhancedSetupFlowProvider virtual CHIP_ERROR SetTermsAndConditionsAcceptance(const Optional & inTermsAndConditions) = 0; + virtual CHIP_ERROR ResetTermsAndConditionsAcceptance() = 0; + virtual CHIP_ERROR RevertTermsAndConditionsAcceptance() = 0; virtual CHIP_ERROR CommitTermsAndConditionsAcceptance() = 0; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 2e6e961f1f87b3..ce750e2413f814 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -599,8 +599,7 @@ void Server::ScheduleFactoryReset() PlatformMgr().HandleServerShuttingDown(); ConfigurationMgr().InitiateFactoryReset(); #if CHIP_CONFIG_TC_REQUIRED - // Clear accepted terms and conditions - GetInstance().GetEnhancedSetupFlowProvider()->RevertTermsAndConditionsAcceptance(); + GetInstance().GetEnhancedSetupFlowProvider()->ResetTermsAndConditionsAcceptance(); #endif }); } diff --git a/src/app/server/Server.h b/src/app/server/Server.h index f9dd82071dcfd3..d43d00e3692d88 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -322,9 +322,16 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams #if CHIP_CONFIG_TC_REQUIRED static app::DefaultEnhancedSetupFlowProvider sDefaultEnhancedSetupFlowProviderInstance; static app::DefaultTermsAndConditionsProvider sDefaultTermsAndConditionsProviderInstance; + if (this->termsAndConditionsProvider == nullptr) { - ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate)); + Optional termsAndConditions = Optional({ + .value = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS, + .version = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION, + }); + + ReturnErrorOnFailure( + sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate, termsAndConditions)); this->termsAndConditionsProvider = &sDefaultTermsAndConditionsProviderInstance; } diff --git a/src/app/server/TermsAndConditionsProvider.h b/src/app/server/TermsAndConditionsProvider.h index 5a1909e9c51e6b..4cd9641641e4ef 100644 --- a/src/app/server/TermsAndConditionsProvider.h +++ b/src/app/server/TermsAndConditionsProvider.h @@ -20,7 +20,6 @@ #include -#include #include #include diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 40cf05ecda478a..a26ac70f31c05e 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -199,7 +199,6 @@ chip_test_suite("tests") { "TestCommandPathParams.cpp", "TestConcreteAttributePath.cpp", "TestDataModelSerialization.cpp", - "TestDefaultEnhancedSetupFlowProvider.cpp", "TestDefaultOTARequestorStorage.cpp", "TestDefaultTermsAndConditionsProvider.cpp", "TestDefaultThreadNetworkDirectoryStorage.cpp", diff --git a/src/app/tests/TestDefaultEnhancedSetupFlowProvider.cpp b/src/app/tests/TestDefaultEnhancedSetupFlowProvider.cpp deleted file mode 100644 index 24213068e6b1a2..00000000000000 --- a/src/app/tests/TestDefaultEnhancedSetupFlowProvider.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (c) 2024 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app/server/DefaultEnhancedSetupFlowProvider.h" - -#include -#include -#include - -class FakeTermsAndConditionsProvider : public chip::app::TermsAndConditionsProvider -{ -public: - FakeTermsAndConditionsProvider(uint16_t inAcceptedAcknowledgements, uint16_t inAcceptedAcknowledgementsVersion, - uint16_t inRequiredAcknowledgements, uint16_t inRequiredAcknowledgementsVersion) : - mAcceptedAcknowledgements(inAcceptedAcknowledgements), - mAcceptedAcknowledgementsVersion(inAcceptedAcknowledgementsVersion), mRequiredAcknowledgements(inRequiredAcknowledgements), - mRequiredAcknowledgementsVersion(inRequiredAcknowledgementsVersion) - {} - - CHIP_ERROR RevertAcceptance() override - { - mAcceptedAcknowledgements = 0; - mAcceptedAcknowledgementsVersion = 0; - return CHIP_NO_ERROR; - } - - CHIP_ERROR CommitAcceptance() override { return CHIP_NO_ERROR; } - - CHIP_ERROR GetAcceptance(uint16_t & outAcknowledgements, uint16_t & outAcknowledgementsVersion) const override - { - outAcknowledgements = mAcceptedAcknowledgements; - outAcknowledgementsVersion = mAcceptedAcknowledgementsVersion; - return CHIP_NO_ERROR; - } - - CHIP_ERROR GetRequirements(uint16_t & outAcknowledgements, uint16_t & outAcknowledgementsVersion) const override - { - outAcknowledgements = mRequiredAcknowledgements; - outAcknowledgementsVersion = mRequiredAcknowledgementsVersion; - return CHIP_NO_ERROR; - } - - CHIP_ERROR HasAcceptance(bool & outHasAcceptance) const override { return CHIP_NO_ERROR; } - - CHIP_ERROR SetAcceptance(uint16_t inAcknowledgements, uint16_t inAcknowledgementsVersion) override - { - mAcceptedAcknowledgements = inAcknowledgements; - mAcceptedAcknowledgementsVersion = inAcknowledgementsVersion; - return CHIP_NO_ERROR; - } - - CHIP_ERROR ResetAcceptance() override { return CHIP_NO_ERROR; } - -private: - uint16_t mAcceptedAcknowledgements; - uint16_t mAcceptedAcknowledgementsVersion; - uint16_t mRequiredAcknowledgements; - uint16_t mRequiredAcknowledgementsVersion; -}; - -TEST(DefaultEnhancedSetupFlowProvider, TestNoAcceptanceRequiredCheckAcknowledgementsAcceptedSuccess) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - - FakeTermsAndConditionsProvider tncProvider(0, 0, 0, 0); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestNoAcceptanceRequiredCheckAcknowledgementsVersionAcceptedSuccess) -{ - CHIP_ERROR err; - bool hasTermsVersionBeenAccepted; - - FakeTermsAndConditionsProvider tncProvider(0, 0, 0, 0); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestAcceptanceRequiredNoTermsAcceptedCheckAcknowledgementsAcceptedFailure) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - - FakeTermsAndConditionsProvider tncProvider(0, 0, 1, 1); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_FALSE(hasTermsBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, - TestAcceptanceRequiredTermsAcceptedTermsVersionOutdatedCheckAcknowledgementsVersionAcceptedFailure) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - bool hasTermsVersionBeenAccepted; - - FakeTermsAndConditionsProvider tncProvider(0, 0, 1, 1); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.SetTermsAndConditionsAcceptance(1, 0); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsBeenAccepted); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_FALSE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestAcceptanceRequiredTermsAcceptedFutureVersionCheckAcknowledgementsAcceptedSuccess) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - bool hasTermsVersionBeenAccepted; - - uint16_t acceptedTerms = 1; - uint16_t requiredTerms = 1; - uint16_t acceptedTermsVersion = 2; - uint16_t requiredTermsVersion = 1; - - FakeTermsAndConditionsProvider tncProvider(acceptedTerms, acceptedTermsVersion, requiredTerms, requiredTermsVersion); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsBeenAccepted); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestAcceptanceRequiredTermsAcceptedSuccess) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - bool hasTermsVersionBeenAccepted; - - FakeTermsAndConditionsProvider tncProvider(0, 0, 1, 1); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.SetTermsAndConditionsAcceptance(1, 1); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsBeenAccepted); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestAcceptanceRequiredTermsMissingFailure) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - bool hasTermsVersionBeenAccepted; - - uint16_t acceptedTerms = 0b0111'1111'1111'1111; - uint16_t requiredTerms = 0b1111'1111'1111'1111; - uint16_t acceptedTermsVersion = 1; - uint16_t requiredTermsVersion = 1; - - FakeTermsAndConditionsProvider tncProvider(acceptedTerms, acceptedTermsVersion, requiredTerms, requiredTermsVersion); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_FALSE(hasTermsBeenAccepted); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestAcceptanceRequiredAllTermsAcceptedCheckAcknowledgementsAcceptedSuccess) -{ - CHIP_ERROR err; - bool hasTermsBeenAccepted; - bool hasTermsVersionBeenAccepted; - - uint16_t acceptedTerms = 0b1111'1111'1111'1111; - uint16_t requiredTerms = 0b1111'1111'1111'1111; - uint16_t acceptedTermsVersion = 1; - uint16_t requiredTermsVersion = 1; - - FakeTermsAndConditionsProvider tncProvider(acceptedTerms, acceptedTermsVersion, requiredTerms, requiredTermsVersion); - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasTermsBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsBeenAccepted); - - err = esfProvider.HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasTermsVersionBeenAccepted); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_TRUE(hasTermsVersionBeenAccepted); -} - -TEST(DefaultEnhancedSetupFlowProvider, TestRevertAcceptanceRetainsRequirements) -{ - CHIP_ERROR err; - - uint16_t initialAcceptedTermsAndConditions = 0; - uint16_t initialRequiredTermsAndConditions = 0b1111'1111'1111'1111; - uint16_t initialAcceptedTermsAndConditionsVersion = 0; - uint16_t initialRequiredTermsAndConditionsVersion = 1; - - uint16_t outAcceptedTermsAndConditions; - uint16_t outRequiredTermsAndConditions; - uint16_t outAcceptedTermsAndConditionsVersion; - uint16_t outRequiredTermsAndConditionsVersion; - - uint16_t updatedAcceptedTermsAndConditions = 0b1111'1111'1111'1111; - uint16_t updatedAcceptedTermsAndConditionsVersion = 1; - - FakeTermsAndConditionsProvider tncProvider(initialAcceptedTermsAndConditions, initialAcceptedTermsAndConditionsVersion, - initialRequiredTermsAndConditions, initialRequiredTermsAndConditionsVersion); - - chip::app::DefaultEnhancedSetupFlowProvider esfProvider; - - err = esfProvider.Init(&tncProvider); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.SetTermsAndConditionsAcceptance(updatedAcceptedTermsAndConditions, updatedAcceptedTermsAndConditionsVersion); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.GetTermsAndConditionsRequiredAcknowledgements(outRequiredTermsAndConditions); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outRequiredTermsAndConditions, initialRequiredTermsAndConditions); - - err = esfProvider.GetTermsAndConditionsRequiredAcknowledgementsVersion(outRequiredTermsAndConditionsVersion); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outRequiredTermsAndConditionsVersion, initialRequiredTermsAndConditionsVersion); - - err = esfProvider.GetTermsAndConditionsAcceptedAcknowledgements(outAcceptedTermsAndConditions); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outAcceptedTermsAndConditions, updatedAcceptedTermsAndConditions); - - err = esfProvider.GetTermsAndConditionsAcceptedAcknowledgementsVersion(outAcceptedTermsAndConditionsVersion); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outAcceptedTermsAndConditionsVersion, updatedAcceptedTermsAndConditionsVersion); - - err = esfProvider.RevertTermsAndConditionsAcceptance(); - EXPECT_EQ(CHIP_NO_ERROR, err); - - err = esfProvider.GetTermsAndConditionsRequiredAcknowledgements(outRequiredTermsAndConditions); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outRequiredTermsAndConditions, initialRequiredTermsAndConditions); - - err = esfProvider.GetTermsAndConditionsRequiredAcknowledgementsVersion(outRequiredTermsAndConditionsVersion); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outRequiredTermsAndConditionsVersion, initialRequiredTermsAndConditionsVersion); - - err = esfProvider.GetTermsAndConditionsAcceptedAcknowledgements(outAcceptedTermsAndConditions); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outAcceptedTermsAndConditions, 0); - - err = esfProvider.GetTermsAndConditionsAcceptedAcknowledgementsVersion(outAcceptedTermsAndConditionsVersion); - EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(outAcceptedTermsAndConditionsVersion, 0); -} diff --git a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp index 474dda7a6b2785..bb1fff24806b2a 100644 --- a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp +++ b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp @@ -17,6 +17,7 @@ */ #include "app/server/DefaultTermsAndConditionsProvider.h" +#include "app/server/TermsAndConditionsProvider.h" #include #include @@ -30,9 +31,12 @@ TEST(DefaultTermsAndConditionsProvider, TestInitSuccess) chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 1; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); } @@ -43,17 +47,15 @@ TEST(DefaultTermsAndConditionsProvider, TestNoRequirementsGetRequirementsSuccess chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 0; - uint16_t requiredAcknowledgementsVersion = 0; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional(); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetAcceptance(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(0, outAcceptance); - EXPECT_EQ(0, outAcknowledgementsVersion); + EXPECT_FALSE(outTermsAndConditions.HasValue()); } TEST(DefaultTermsAndConditionsProvider, TestNeverAcceptanceGetAcceptanceSuccess) @@ -63,17 +65,18 @@ TEST(DefaultTermsAndConditionsProvider, TestNeverAcceptanceGetAcceptanceSuccess) chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 0b1111'1111'1111'1111; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 0b1111'1111'1111'1111, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetAcceptance(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(0, outAcceptance); - EXPECT_EQ(0, outAcknowledgementsVersion); + EXPECT_FALSE(outTermsAndConditions.HasValue()); } TEST(DefaultTermsAndConditionsProvider, TestTermsAcceptedPersistsSuccess) @@ -84,35 +87,41 @@ TEST(DefaultTermsAndConditionsProvider, TestTermsAcceptedPersistsSuccess) chip::app::DefaultTermsAndConditionsProvider tncProvider; chip::app::DefaultTermsAndConditionsProvider anotherTncProvider; - uint16_t requiredAcknowledgements = 1; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t acceptedTermsAndConditions = 1; - uint16_t acceptedTermsAndConditionsVersion = 1; - err = tncProvider.SetAcceptance(acceptedTermsAndConditions, acceptedTermsAndConditionsVersion); + chip::Optional newTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.SetAcceptance(newTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetAcceptance(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); err = tncProvider.CommitAcceptance(); + err = tncProvider.GetAcceptance(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); - err = anotherTncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + err = anotherTncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - err = anotherTncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + err = anotherTncProvider.GetAcceptance(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); } TEST(DefaultTermsAndConditionsProvider, TestTermsRequiredGetRequirementsSuccess) @@ -122,17 +131,19 @@ TEST(DefaultTermsAndConditionsProvider, TestTermsRequiredGetRequirementsSuccess) chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t initialRequiredAcknowledgements = 1; - uint16_t initialRequiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, initialRequiredAcknowledgements, initialRequiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outRequiredAcknowledgements; - uint16_t outRequiredAcknowledgementsVersion; - err = tncProvider.GetRequirements(outRequiredAcknowledgements, outRequiredAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetRequirements(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outRequiredAcknowledgements); - EXPECT_EQ(1, outRequiredAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); } TEST(DefaultTermsAndConditionsProvider, TestSetAcceptanceGetAcceptanceSuccess) @@ -142,22 +153,26 @@ TEST(DefaultTermsAndConditionsProvider, TestSetAcceptanceGetAcceptanceSuccess) chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 1; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t acceptedTermsAndConditions = 1; - uint16_t acceptedTermsAndConditionsVersion = 1; - err = tncProvider.SetAcceptance(acceptedTermsAndConditions, acceptedTermsAndConditionsVersion); + chip::Optional acceptedTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + err = tncProvider.SetAcceptance(acceptedTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetRequirements(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); } TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptanceGetAcceptanceSuccess) @@ -167,32 +182,34 @@ TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptanceGetAcceptanceSuccess chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 1; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional termsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + err = tncProvider.Init(&storageDelegate, termsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t acceptedTermsAndConditions = 1; - uint16_t acceptedTermsAndConditionsVersion = 1; - err = tncProvider.SetAcceptance(acceptedTermsAndConditions, acceptedTermsAndConditionsVersion); + chip::Optional acceptedTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + err = tncProvider.SetAcceptance(acceptedTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outTermsAndConditions; + err = tncProvider.GetRequirements(outTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outTermsAndConditions.Value().value); + EXPECT_EQ(1, outTermsAndConditions.Value().version); err = tncProvider.RevertAcceptance(); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance2; - uint16_t outAcknowledgementsVersion2; - err = tncProvider.GetAcceptance(outAcceptance2, outAcknowledgementsVersion2); + chip::Optional outAcceptance2; + err = tncProvider.GetAcceptance(outAcceptance2); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(0, outAcceptance2); - EXPECT_EQ(0, outAcknowledgementsVersion2); + EXPECT_FALSE(outAcceptance2.HasValue()); } TEST(DefaultTermsAndConditionsProvider, TestAcceptanceRequiredTermsMissingFailure) @@ -202,30 +219,32 @@ TEST(DefaultTermsAndConditionsProvider, TestAcceptanceRequiredTermsMissingFailur chip::TestPersistentStorageDelegate storageDelegate; chip::app::DefaultTermsAndConditionsProvider tncProvider; - uint16_t requiredAcknowledgements = 1; - uint16_t requiredAcknowledgementsVersion = 1; - err = tncProvider.Init(&storageDelegate, requiredAcknowledgements, requiredAcknowledgementsVersion); + chip::Optional requiredTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + err = tncProvider.Init(&storageDelegate, requiredTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t acceptedTermsAndConditions = 1; - uint16_t acceptedTermsAndConditionsVersion = 1; - err = tncProvider.SetAcceptance(acceptedTermsAndConditions, acceptedTermsAndConditionsVersion); + chip::Optional acceptedTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + err = tncProvider.SetAcceptance(acceptedTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outAcceptance; - uint16_t outAcknowledgementsVersion; - err = tncProvider.GetAcceptance(outAcceptance, outAcknowledgementsVersion); + chip::Optional outAcknowledgementTermsAndConditions; + err = tncProvider.GetAcceptance(outAcknowledgementTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outAcceptance); - EXPECT_EQ(1, outAcknowledgementsVersion); + EXPECT_EQ(1, outAcknowledgementTermsAndConditions.Value().value); + EXPECT_EQ(1, outAcknowledgementTermsAndConditions.Value().version); err = tncProvider.RevertAcceptance(); EXPECT_EQ(CHIP_NO_ERROR, err); - uint16_t outRequiredAcknowledgements; - uint16_t outRequiredAcknowledgementsVersion; - err = tncProvider.GetRequirements(outRequiredAcknowledgements, outRequiredAcknowledgementsVersion); + chip::Optional outRequiredTermsAndConditions; + err = tncProvider.GetRequirements(outRequiredTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); - EXPECT_EQ(1, outRequiredAcknowledgements); - EXPECT_EQ(1, outRequiredAcknowledgementsVersion); + EXPECT_EQ(1, outRequiredTermsAndConditions.Value().value); + EXPECT_EQ(1, outRequiredTermsAndConditions.Value().version); } diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index 2cfd53a314b772..443fb9cdd958a4 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -1849,39 +1849,6 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #define CHIP_CONFIG_TC_REQUIRED (0) #endif -#if CHIP_CONFIG_TC_REQUIRED - -/** - * @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS - * - * @brief Configures the required terms and conditions acknowledgements bitmask. - * - * This macro defines the required terms and conditions acknowledgements bitmask. The bit-field is 16 bits long, so the possible - * value range is [0, 65535). This setting can be used to require that terms and conditions are presented to the user during - * commissioning. - */ -#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS -#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS must be defined when CHIP_CONFIG_TC_REQUIRED is enabled." -#endif - -/** - * @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION - * - * @brief Configures the latest known version of the terms and conditions. - * - * This macro defines the version number of the latest terms and conditions. It allows the application to iterate on revisions of - * the terms and conditions. A value of 0 indicates that no specific version is required. This setting can be used to enforce - * version-specific terms and conditions acknowledgements in the application. When the set of terms and conditions needs to be - * changed, the version number should be monotonically increased. If the latest terms and conditions version is updated (most - * likely during an OTA), then this may signal to the Administrator that updated terms and conditions should be presented to the - * user. - */ -#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION -#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION must be defined when CHIP_CONFIG_TC_REQUIRED is enabled." -#endif - -#endif // CHIP_CONFIG_TC_REQUIRED - /** * @} */