Skip to content

Commit

Permalink
Add unit tests for SetShouldAdvertiseIdentity.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Sep 17, 2024
1 parent f6e2216 commit 972c655
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/credentials/tests/TestFabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ TEST_F(TestFabricTable, TestBasicAddNocUpdateNocFlow)
{
EXPECT_EQ(iterFabricInfo.GetNodeId(), nodeId);
EXPECT_EQ(iterFabricInfo.GetFabricId(), fabricId);
EXPECT_TRUE(iterFabricInfo.ShouldAdvertiseIdentity());
saw1 = true;
}
}
Expand Down Expand Up @@ -817,12 +818,14 @@ TEST_F(TestFabricTable, TestBasicAddNocUpdateNocFlow)
{
EXPECT_EQ(iterFabricInfo.GetNodeId(), 55u);
EXPECT_EQ(iterFabricInfo.GetFabricId(), 11u);
EXPECT_TRUE(iterFabricInfo.ShouldAdvertiseIdentity());
saw1 = true;
}
if (iterFabricInfo.GetFabricIndex() == 2)
{
EXPECT_EQ(iterFabricInfo.GetNodeId(), 999u);
EXPECT_EQ(iterFabricInfo.GetFabricId(), 44u);
EXPECT_TRUE(iterFabricInfo.ShouldAdvertiseIdentity());
saw2 = true;
}
}
Expand Down Expand Up @@ -1104,7 +1107,9 @@ TEST_F(TestFabricTable, TestAddMultipleSameRootDifferentFabricId)
EXPECT_EQ(fabricTable.FabricCount(), 0);
EXPECT_EQ(fabricTable.AddNewPendingTrustedRootCert(rcac), CHIP_NO_ERROR);
FabricIndex newFabricIndex = kUndefinedFabricIndex;
EXPECT_EQ(fabricTable.AddNewPendingFabricWithOperationalKeystore(noc, icac, kVendorId, &newFabricIndex), CHIP_NO_ERROR);
EXPECT_EQ(fabricTable.AddNewPendingFabricWithOperationalKeystore(noc, icac, kVendorId, &newFabricIndex,
FabricTable::AdvertiseIdentity::No),
CHIP_NO_ERROR);
EXPECT_EQ(fabricTable.FabricCount(), 1);
EXPECT_EQ(newFabricIndex, 1);

Expand All @@ -1118,6 +1123,23 @@ TEST_F(TestFabricTable, TestAddMultipleSameRootDifferentFabricId)
EXPECT_EQ(fabricInfo->GetFabricId(), 1111u);
EXPECT_EQ(fabricInfo->GetVendorId(), kVendorId);
EXPECT_EQ(fabricInfo->GetFabricLabel().size(), 0u);
EXPECT_FALSE(fabricInfo->ShouldAdvertiseIdentity());

EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(newFabricIndex, FabricTable::AdvertiseIdentity::Yes), CHIP_NO_ERROR);
EXPECT_TRUE(fabricInfo->ShouldAdvertiseIdentity());

// Check that for indices we don't have a fabric for, SetShouldAdvertiseIdentity fails.
EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(kUndefinedFabricIndex, FabricTable::AdvertiseIdentity::No),
CHIP_ERROR_INVALID_FABRIC_INDEX);
EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(kUndefinedFabricIndex, FabricTable::AdvertiseIdentity::Yes),
CHIP_ERROR_INVALID_FABRIC_INDEX);
EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(2, FabricTable::AdvertiseIdentity::Yes), CHIP_ERROR_INVALID_FABRIC_INDEX);
EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(2, FabricTable::AdvertiseIdentity::No), CHIP_ERROR_INVALID_FABRIC_INDEX);

EXPECT_TRUE(fabricInfo->ShouldAdvertiseIdentity());

EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(newFabricIndex, FabricTable::AdvertiseIdentity::No), CHIP_NO_ERROR);
EXPECT_FALSE(fabricInfo->ShouldAdvertiseIdentity());
}
size_t numStorageKeysAfterFirstAdd = storage.GetNumKeys();
EXPECT_EQ(numStorageKeysAfterFirstAdd, 7u); // Metadata, index, 3 certs, 1 opkey, last known good time
Expand Down Expand Up @@ -1155,6 +1177,14 @@ TEST_F(TestFabricTable, TestAddMultipleSameRootDifferentFabricId)
EXPECT_EQ(fabricInfo->GetFabricId(), 2222u);
EXPECT_EQ(fabricInfo->GetVendorId(), kVendorId);
EXPECT_EQ(fabricInfo->GetFabricLabel().size(), 0u);

EXPECT_TRUE(fabricInfo->ShouldAdvertiseIdentity());

EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(newFabricIndex, FabricTable::AdvertiseIdentity::No), CHIP_NO_ERROR);
EXPECT_FALSE(fabricInfo->ShouldAdvertiseIdentity());

EXPECT_EQ(fabricTable.SetShouldAdvertiseIdentity(newFabricIndex, FabricTable::AdvertiseIdentity::Yes), CHIP_NO_ERROR);
EXPECT_TRUE(fabricInfo->ShouldAdvertiseIdentity());
}
size_t numStorageKeysAfterSecondAdd = storage.GetNumKeys();
EXPECT_EQ(numStorageKeysAfterSecondAdd, (numStorageKeysAfterFirstAdd + 5)); // Add 3 certs, 1 metadata, 1 opkey
Expand Down

0 comments on commit 972c655

Please sign in to comment.