diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index ff6635cbf..2f14be12f 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -466,6 +466,7 @@ void BorderAgent::RegisterService(void) uint16_t txtDataBufferSize; uint16_t txtDataLength; + VerifyOrExit(IsEnabled()); VerifyOrExit(Get().IsReady()); // Allocate a large enough buffer to fit both the TXT data diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 51fe3502c..08794d04c 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -1786,6 +1786,26 @@ void TestBorderAgentServiceRegistration(void) sBrowseOutcomes.Clear(); + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Log("Change the base service name while agent is disabled and validate no service is registered"); + + SuccessOrQuit(node0.Get().SetServiceBaseName("NewName")); + + VerifyOrQuit(!node0.Get().IsEnabled()); + + nexus.AdvanceTime(30 * Time::kOneSecondInMsec); + + iterator = node0.Get().AllocateIterator(); + VerifyOrQuit(iterator != nullptr); + + VerifyOrQuit(node0.Get().GetNextService(*iterator, service, entryState) == kErrorNotFound); + + node0.Get().FreeIterator(*iterator); + + VerifyOrQuit(sBrowseOutcomes.IsEmpty()); + + SuccessOrQuit(node0.Get().SetServiceBaseName("OpenThreadAgent")); + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Re-enable Border Agent and validate that service is registered again");