Skip to content

Commit

Permalink
Fix test cases that use invalid ByteSpans
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple committed Sep 17, 2023
1 parent ac9685c commit bdae657
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/credentials/tests/TestDeviceAttestationCredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static void TestAttestationTrustStore(nlTestSuite * inSuite, void * inContext)
ByteSpan kPaaFFF1BadSkidSpan1{ TestCerts::sTestCert_PAA_FFF1_Cert.data(), TestCerts::sTestCert_PAA_FFF1_Cert.size() - 1 };

// SKID to trigger CHIP_ERROR_INVALID_ARGUMENT
ByteSpan kPaaFFF1BadSkidSpan2{ nullptr, TestCerts::sTestCert_PAA_FFF1_Cert.size() };
ByteSpan kPaaFFF1BadSkidSpan2;

// SKID to trigger CHIP_ERROR_CA_CERT_NOT_FOUND
uint8_t kPaaGoodSkidNotPresent[] = { 0x6A, 0xFD, 0x22, 0x77, 0x1F, 0x51, 0x71, 0x1F, 0xEC, 0xBF,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/support/tests/TestThreadOperationalDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void TestInit(nlTestSuite * inSuite, void * inContext)
{
Thread::OperationalDataset & dataset = *static_cast<Thread::OperationalDataset *>(inContext);

NL_TEST_ASSERT(inSuite, dataset.Init(ByteSpan(nullptr, 255)) == CHIP_ERROR_INVALID_ARGUMENT);
uint8_t longerThanOperationalDatasetSize[255]{};
NL_TEST_ASSERT(inSuite, dataset.Init(ByteSpan(longerThanOperationalDatasetSize)) == CHIP_ERROR_INVALID_ARGUMENT);
NL_TEST_ASSERT(inSuite, dataset.Init(ByteSpan(nullptr, 0)) == CHIP_NO_ERROR);

{
Expand Down
2 changes: 0 additions & 2 deletions src/transport/CryptoContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ CHIP_ERROR CryptoContext::InitFromSecret(SessionKeystore & keystore, const ByteS
SessionInfoType infoType, SessionRole role)
{
VerifyOrReturnError(mKeyAvailable == false, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(secret.data() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(secret.size() > 0, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError((salt.size() == 0) || (salt.data() != nullptr), CHIP_ERROR_INVALID_ARGUMENT);

ByteSpan info = (infoType == SessionInfoType::kSessionResumption) ? ByteSpan(RSEKeysInfo) : ByteSpan(SEKeysInfo);

Expand Down
6 changes: 0 additions & 6 deletions src/transport/tests/TestSecureSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ void SecureChannelInitTest(nlTestSuite * inSuite, void * inContext)
P256Keypair keypair2;
NL_TEST_ASSERT(inSuite, keypair2.Initialize(ECPKeyTarget::ECDH) == CHIP_NO_ERROR);

// Test all combinations of invalid parameters
NL_TEST_ASSERT(inSuite,
channel.InitFromKeyPair(sessionKeystore, keypair, keypair2.Pubkey(), ByteSpan(nullptr, 10),
CryptoContext::SessionInfoType::kSessionEstablishment,
CryptoContext::SessionRole::kInitiator) == CHIP_ERROR_INVALID_ARGUMENT);

// Test the channel is successfully created with valid parameters
NL_TEST_ASSERT(inSuite,
channel.InitFromKeyPair(sessionKeystore, keypair, keypair2.Pubkey(), ByteSpan(nullptr, 0),
Expand Down

0 comments on commit bdae657

Please sign in to comment.