Skip to content

Commit

Permalink
Restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
jlatusek committed May 17, 2024
1 parent a25fa33 commit 983ce88
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
9 changes: 4 additions & 5 deletions src/protocols/secure_channel/tests/TestCASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ TEST_F(TestCASESession, DestinationIdTest)
EXPECT_FALSE(destinationIdSpan.data_equal(ByteSpan(kExpectedDestinationIdFromSpec)));
}


template <typename Params>
static CHIP_ERROR EncodeSigma1(MutableByteSpan & buf)
{
Expand Down Expand Up @@ -1002,9 +1001,9 @@ TEST_F(TestCASESession, SessionResumptionStorage)
CHIP_NO_ERROR);
ExchangeContext * contextCommissioner = NewUnauthenticatedExchangeToBob(pairingCommissioner);
auto establishmentReturnVal = pairingCommissioner->EstablishSession(
GetSecureSessionManager(), &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex },
contextCommissioner, &testVectors[i].initiatorStorage, nullptr, &delegateCommissioner,
Optional<ReliableMessageProtocolConfig>::Missing());
GetSecureSessionManager(), &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex },
contextCommissioner, &testVectors[i].initiatorStorage, nullptr, &delegateCommissioner,
Optional<ReliableMessageProtocolConfig>::Missing());
ServiceEvents();
EXPECT_EQ(establishmentReturnVal, CHIP_NO_ERROR);
EXPECT_EQ(loopback.mSentMessageCount, testVectors[i].expectedSentMessageCount);
Expand All @@ -1016,7 +1015,7 @@ TEST_F(TestCASESession, SessionResumptionStorage)
gPairingServer.Shutdown();
}
}
// #endif

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
TEST_F_FROM_FIXTURE(TestCASESession, SimulateUpdateNOCInvalidatePendingEstablishment)
{
Expand Down
44 changes: 19 additions & 25 deletions src/protocols/secure_channel/tests/TestCheckinMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include <crypto/DefaultSessionKeystore.h>
#include <crypto/RandUtils.h>
#include <gtest/gtest.h>
#include <lib/support/BufferWriter.h>
#include <lib/support/CHIPMem.h>
#include <gtest/gtest.h>
#include <protocols/Protocols.h>
#include <protocols/secure_channel/CheckinMessage.h>
#include <protocols/secure_channel/Constants.h>
Expand All @@ -34,9 +34,7 @@ using namespace chip::Protocols::SecureChannel;
using namespace chip::Crypto;
using TestSessionKeystoreImpl = Crypto::DefaultSessionKeystore;

namespace chip {
namespace Protocols {
namespace SecureChannel {
namespace {

class TestCheckInMsg : public ::testing::Test
{
Expand Down Expand Up @@ -75,7 +73,6 @@ CHIP_ERROR TestCheckInMsg::GenerateAndVerifyPayload(MutableByteSpan & output, co
memcpy(hmacKeyMaterial, vector.key, vector.key_len);

Aes128KeyHandle aes128KeyHandle;

EXPECT_EQ(keystore.CreateKey(aesKeyMaterial, aes128KeyHandle), CHIP_NO_ERROR);

Hmac128KeyHandle hmac128KeyHandle;
Expand Down Expand Up @@ -237,7 +234,6 @@ TEST_F(TestCheckInMsg, TestCheckinMessageGenerate_ValidInputsTooSmallOutput)

// Create output buffer with 0 size
MutableByteSpan output;

EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, GenerateAndVerifyPayload(output, vector));
}

Expand Down Expand Up @@ -268,10 +264,10 @@ TEST_F(TestCheckInMsg, TestCheckInMessageGenerate_EmptyAesKeyHandle)
// Create application data ByteSpan
ByteSpan applicationData(vector.application_data, vector.application_data_len);

/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
#if 0
// Verify that the generation fails with an empty key handle
NL_TEST_ASSERT_(inSuite,
Expand Down Expand Up @@ -310,10 +306,10 @@ TEST_F(TestCheckInMsg, TestCheckInMessageGenerate_EmptyHmacKeyHandle)
// Create application data ByteSpan
ByteSpan applicationData(vector.application_data, vector.application_data_len);

/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
#if 0
// Verify that the generation fails with an empty key handle
NL_TEST_ASSERT_(inSuite,
Expand Down Expand Up @@ -403,10 +399,10 @@ TEST_F(TestCheckInMsg, TestCheckInMessageParse_EmptyAesKeyHandle)
Hmac128KeyHandle hmac128KeyHandle;
EXPECT_EQ(keystore.CreateKey(hmacKeyMaterial, hmac128KeyHandle), CHIP_NO_ERROR);

/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
#if 0
// Verify that the generation fails with an empty key handle
EXPECT_EQ(
Expand Down Expand Up @@ -447,10 +443,10 @@ TEST_F(TestCheckInMsg, TestCheckInMessageParse_EmptyHmacKeyHandle)
Aes128KeyHandle aes128KeyHandle;
EXPECT_EQ(keystore.CreateKey(aesKeyMaterial, aes128KeyHandle), CHIP_NO_ERROR);

/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
/*
TODO(#28986): Passing an empty key handle while using PSA crypto will result in a failure.
When using OpenSSL this same test result in a success.
*/
#if 0
// Verify that the generation fails with an empty key handle
EXPECT_EQ(
Expand Down Expand Up @@ -525,6 +521,4 @@ TEST_F(TestCheckInMsg, TestCheckInMessagePayloadSizeNullBuffer)
EXPECT_EQ(calculated_size, 0u);
}

} // namespace SecureChannel
} // namespace Protocols
} // namespace chip
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* limitations under the License.
*/

#include <gtest/gtest.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/TestPersistentStorageDelegate.h>

#include <gtest/gtest.h>

// DefaultSessionResumptionStorage is a partial implementation.
// Use SimpleSessionResumptionStorage, which extends it, to test.
#include <protocols/secure_channel/SimpleSessionResumptionStorage.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ TEST(TestSimpleSessionResumptionStorage, TestLink)
sessionStorage.Init(&storage);

chip::SimpleSessionResumptionStorage::ResumptionIdStorage resumptionId;
EXPECT_EQ( chip::Crypto::DRBG_get_bytes(resumptionId.data(), resumptionId.size()), CHIP_NO_ERROR);
EXPECT_EQ(chip::Crypto::DRBG_get_bytes(resumptionId.data(), resumptionId.size()), CHIP_NO_ERROR);

EXPECT_EQ( sessionStorage.SaveLink(resumptionId, chip::ScopedNodeId(node1, fabric1)), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.SaveLink(resumptionId, chip::ScopedNodeId(node1, fabric1)), CHIP_NO_ERROR);

chip::ScopedNodeId node;
EXPECT_EQ( sessionStorage.LoadLink(resumptionId, node), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.LoadLink(resumptionId, node), CHIP_NO_ERROR);
EXPECT_EQ(node, chip::ScopedNodeId(node1, fabric1));

EXPECT_EQ( sessionStorage.DeleteLink(resumptionId), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.DeleteLink(resumptionId), CHIP_NO_ERROR);

EXPECT_EQ(sessionStorage.LoadLink(resumptionId, node), CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
}
Expand All @@ -54,26 +54,27 @@ TEST(TestSimpleSessionResumptionStorage, TestState)
chip::ScopedNodeId node(node1, fabric1);

chip::SimpleSessionResumptionStorage::ResumptionIdStorage resumptionId;
EXPECT_EQ( chip::Crypto::DRBG_get_bytes(resumptionId.data(), resumptionId.size()), CHIP_NO_ERROR);
EXPECT_EQ(chip::Crypto::DRBG_get_bytes(resumptionId.data(), resumptionId.size()), CHIP_NO_ERROR);

chip::Crypto::P256ECDHDerivedSecret sharedSecret;
sharedSecret.SetLength(sharedSecret.Capacity());
EXPECT_EQ( chip::Crypto::DRBG_get_bytes(sharedSecret.Bytes(), sharedSecret.Length()), CHIP_NO_ERROR);
EXPECT_EQ(chip::Crypto::DRBG_get_bytes(sharedSecret.Bytes(), sharedSecret.Length()), CHIP_NO_ERROR);

chip::CATValues peerCATs;

EXPECT_EQ( sessionStorage.SaveState(node, resumptionId, sharedSecret, peerCATs), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.SaveState(node, resumptionId, sharedSecret, peerCATs), CHIP_NO_ERROR);

chip::SimpleSessionResumptionStorage::ResumptionIdStorage resumptionId2;
chip::Crypto::P256ECDHDerivedSecret sharedSecret2;
chip::CATValues peerCATs2;
EXPECT_EQ( sessionStorage.LoadState(node, resumptionId2, sharedSecret2, peerCATs2), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.LoadState(node, resumptionId2, sharedSecret2, peerCATs2), CHIP_NO_ERROR);
EXPECT_EQ(resumptionId, resumptionId2);
EXPECT_EQ(memcmp(sharedSecret.Bytes(), sharedSecret2.Bytes(), sharedSecret.Length()), 0);

EXPECT_EQ( sessionStorage.DeleteState(node), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.DeleteState(node), CHIP_NO_ERROR);

EXPECT_EQ( sessionStorage.LoadState(node, resumptionId2, sharedSecret2, peerCATs2), CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
EXPECT_EQ(sessionStorage.LoadState(node, resumptionId2, sharedSecret2, peerCATs2),
CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
}

TEST(TestSimpleSessionResumptionStorage, TestIndex)
Expand All @@ -85,14 +86,14 @@ TEST(TestSimpleSessionResumptionStorage, TestIndex)
chip::ScopedNodeId node(node1, fabric1);

chip::DefaultSessionResumptionStorage::SessionIndex index0o;
EXPECT_EQ( sessionStorage.LoadIndex(index0o), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.LoadIndex(index0o), CHIP_NO_ERROR);
EXPECT_EQ(index0o.mSize, 0u);

chip::DefaultSessionResumptionStorage::SessionIndex index1;
index1.mSize = 0;
EXPECT_EQ( sessionStorage.SaveIndex(index1), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.SaveIndex(index1), CHIP_NO_ERROR);
chip::DefaultSessionResumptionStorage::SessionIndex index1o;
EXPECT_EQ( sessionStorage.LoadIndex(index1o), CHIP_NO_ERROR);
EXPECT_EQ(sessionStorage.LoadIndex(index1o), CHIP_NO_ERROR);
EXPECT_EQ(index1o.mSize, 0u);

chip::DefaultSessionResumptionStorage::SessionIndex index2;
Expand Down

0 comments on commit 983ce88

Please sign in to comment.