proxygen
fizz::client::test Namespace Reference

Classes

class  ActionMoveVisitor
 
class  AsyncFizzClientTest
 
class  ClientProtocolTest
 
class  FizzClientTest
 
class  MockAsyncFizzClient
 
class  MockClientExtensions
 
class  MockClientStateMachine
 
class  MockClientStateMachineInstance
 
class  MockConnectCallback
 
class  MockHandshakeCallbackT
 
class  MockPskCache
 
class  SynchronizedLruPskCacheTest
 
class  TestFizzClient
 

Typedefs

using MockHandshakeCallback = MockHandshakeCallbackT< ClientStateMachine >
 

Functions

 MATCHER_P (BufMatches, expected,"")
 
 TEST_F (AsyncFizzClientTest, TestConnect)
 
 TEST_F (AsyncFizzClientTest, TestReadSingle)
 
 TEST_F (AsyncFizzClientTest, TestReadMulti)
 
 TEST_F (AsyncFizzClientTest, TestWrite)
 
 TEST_F (AsyncFizzClientTest, TestWriteMulti)
 
 TEST_F (AsyncFizzClientTest, TestWriteErrorState)
 
 TEST_F (AsyncFizzClientTest, TestHandshake)
 
 TEST_F (AsyncFizzClientTest, TestExporterAPI)
 
 TEST_F (AsyncFizzClientTest, TestHandshakeError)
 
 TEST_F (AsyncFizzClientTest, TestHandshakeErrorDelete)
 
 TEST_F (AsyncFizzClientTest, TestDeliverAppData)
 
 TEST_F (AsyncFizzClientTest, TestWriteToSocket)
 
 TEST_F (AsyncFizzClientTest, TestMutateState)
 
 TEST_F (AsyncFizzClientTest, TestCloseHandshake)
 
 TEST_F (AsyncFizzClientTest, TestConnecting)
 
 TEST_F (AsyncFizzClientTest, TestGoodSocket)
 
 TEST_F (AsyncFizzClientTest, TestGoodState)
 
 TEST_F (AsyncFizzClientTest, TestSocketConnect)
 
 TEST_F (AsyncFizzClientTest, TestSocketConnectWithUnsupportedTransport)
 
 TEST_F (AsyncFizzClientTest, TestHandshakeConnectWithUnopenedSocket)
 
 TEST_F (AsyncFizzClientTest, TestSocketConnectWithOpenSocket)
 
 TEST_F (AsyncFizzClientTest, TestApplicationProtocol)
 
 TEST_F (AsyncFizzClientTest, TestApplicationProtocolNone)
 
 TEST_F (AsyncFizzClientTest, TestPskResumed)
 
 TEST_F (AsyncFizzClientTest, TestNoPskResumption)
 
 TEST_F (AsyncFizzClientTest, TestGetCertsNone)
 
 TEST_F (AsyncFizzClientTest, TestGetCerts)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshake)
 
 TEST_F (AsyncFizzClientTest, TestEarlyParams)
 
 TEST_F (AsyncFizzClientTest, TestEarlyApplicationProtocolNone)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeWrite)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeReplaySafeCallback)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeReplaySafeCallbackRemoved)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeOverLimit)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeAllOverLimit)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedFatalError)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedPendingWriteError)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedAutoResendNoData)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedAutoResend)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedAutoResendOrder)
 
 TEST_F (AsyncFizzClientTest, TestEarlyHandshakeRejectedAutoResendDeletedBuffer)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectResendDifferentAlpn)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectResendDifferentNoAlpn)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectResendDifferentVersion)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectResendDifferentCipher)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectNoClientCert)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectNoServerCert)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectDifferentServerIdentity)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectSameServerIdentity)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectDifferentClientIdentity)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectSameClientIdentity)
 
 TEST_F (AsyncFizzClientTest, TestEarlyRejectRemovePsk)
 
 TEST_F (AsyncFizzClientTest, TestEarlyWriteRejected)
 
 TEST_F (AsyncFizzClientTest, TestEarlyWriteRejectedNullCallback)
 
 TEST_F (AsyncFizzClientTest, TestErrorStopsActions)
 
 TEST_F (AsyncFizzClientTest, TestNewCachedPskActions)
 
 TEST_F (AsyncFizzClientTest, TestNewCachedPskActionsWithEmptyPskIdentity)
 
 TEST_F (ClientProtocolTest, TestInvalidTransitionNoAlert)
 
 TEST_F (ClientProtocolTest, TestInvalidWriteNewSessionTicket)
 
 TEST_F (ClientProtocolTest, TestInvalidTransitionAlert)
 
 TEST_F (ClientProtocolTest, TestInvalidTransitionError)
 
 TEST_F (ClientProtocolTest, TestConnectFlow)
 
 TEST_F (ClientProtocolTest, TestConnectPskFlow)
 
 TEST_F (ClientProtocolTest, TestConnectPskEarlyFlow)
 
 TEST_F (ClientProtocolTest, TestConnectNoHostNoPsk)
 
 TEST_F (ClientProtocolTest, TestConnectPskBadVersion)
 
 TEST_F (ClientProtocolTest, TestConnectPskBadCipher)
 
 TEST_F (ClientProtocolTest, TestConnectSeparatePskIdentity)
 
 TEST_F (ClientProtocolTest, TestConnectPskIdentityWithoutSni)
 
 TEST_F (ClientProtocolTest, TestConnectNoSni)
 
 TEST_F (ClientProtocolTest, TestConnectNoAlpn)
 
 TEST_F (ClientProtocolTest, TestConnectExtension)
 
 TEST_F (ClientProtocolTest, TestConnectMultipleShares)
 
 TEST_F (ClientProtocolTest, TestConnectCachedGroup)
 
 TEST_F (ClientProtocolTest, TestConnectNoShares)
 
 TEST_F (ClientProtocolTest, TestConnectPskEarly)
 
 TEST_F (ClientProtocolTest, TestConnectPskEarlyNoAlpn)
 
 TEST_F (ClientProtocolTest, TestConnectPskEarlyDisabled)
 
 TEST_F (ClientProtocolTest, TestConnectPskEarlyAlpnMismatch)
 
 TEST_F (ClientProtocolTest, TestConnectCompat)
 
 TEST_F (ClientProtocolTest, TestConnectCompatEarly)
 
 TEST_F (ClientProtocolTest, TestServerHelloFlow)
 
 TEST_F (ClientProtocolTest, TestServerHelloAfterHrrFlow)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskFlow)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskNoDhFlow)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskAfterHrrFlow)
 
 TEST_F (ClientProtocolTest, TestServerHello)
 
 TEST_F (ClientProtocolTest, TestServerHelloPsk)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskRejected)
 
 TEST_F (ClientProtocolTest, TestServerHelloExtraData)
 
 TEST_F (ClientProtocolTest, TestServerHelloBadVersion)
 
 TEST_F (ClientProtocolTest, TestServerHelloBadCipher)
 
 TEST_F (ClientProtocolTest, TestServerHelloBadGroup)
 
 TEST_F (ClientProtocolTest, TestServerHelloNoKeyShare)
 
 TEST_F (ClientProtocolTest, TestServerHelloHrrBadVersion)
 
 TEST_F (ClientProtocolTest, TestServerHelloHrrBadCipher)
 
 TEST_F (ClientProtocolTest, TestServerHelloHrrBadGroup)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskAcceptedNotSent)
 
 TEST_F (ClientProtocolTest, TestServerHelloOtherPskAccepted)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskDifferentHash)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskDifferentCompatibleCipher)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskDheNotSupported)
 
 TEST_F (ClientProtocolTest, TestServerHelloExtensions)
 
 TEST_F (ClientProtocolTest, TestServerHelloPskKeNotSupported)
 
 TEST_F (ClientProtocolTest, TestServerHelloBadSessionId)
 
 TEST_F (ClientProtocolTest, TestConnectPskKeNoShares)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestFlow)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestPskFlow)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequest)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestPskDifferentHash)
 
 TEST_F (ClientProtocolTest, TestDoubleHelloRetryRequest)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestBadVersion)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestBadCipher)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestBadGroup)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestGroupAlreadySent)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestNoKeyShare)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestCookie)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestAttemptedEarly)
 
 TEST_F (ClientProtocolTest, TestHelloRetryRequestCompat)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsFlow)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsPsk)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsAlpn)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEmptyAlpn)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsAlpnMismatch)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsNoAlpn)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsDisallowedExtension)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsUnrequestedExtension)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyAccepted)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyRejected)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyAlreadyRejected)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyAcceptedHrr)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyCipherMismatch)
 
 TEST_F (ClientProtocolTest, TestEncryptedExtensionsEarlyAlpnMismatch)
 
 TEST_F (ClientProtocolTest, TestCertificateFlow)
 
 TEST_F (ClientProtocolTest, TestCertificate)
 
 TEST_F (ClientProtocolTest, TestCertificateWithRequestContext)
 
 TEST_F (ClientProtocolTest, TestCertificateEmpty)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificateFlow)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificate)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificateUnknownAlgo)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificateDecompressionFailed)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificateWithRequestContext)
 
 TEST_F (ClientProtocolTest, TestCompressedCertificateEmpty)
 
 TEST_F (ClientProtocolTest, TestUnexpectedCompressedCertificate)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyFlow)
 
 TEST_F (ClientProtocolTest, TestCertificateVerify)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyNoVerifier)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyUnsupportedAlgorithm)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyFailure)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyVerifierFailure)
 
 TEST_F (ClientProtocolTest, TestCertificateVerifyVerifierFailureOtherException)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestNoCert)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestDuplicated)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestAlgosMismatch)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestContextAlgosUnsupported)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestPrefersContextOrder)
 
 TEST_F (ClientProtocolTest, TestCertificateRequestMatch)
 
 TEST_F (ClientProtocolTest, TestFinishedFlow)
 
 TEST_F (ClientProtocolTest, TestFinishedCertNoMatchFlow)
 
 TEST_F (ClientProtocolTest, TestFinishedCertSentFlow)
 
 TEST_F (ClientProtocolTest, TestFinishedEarlyFlow)
 
 TEST_F (ClientProtocolTest, TestFinished)
 
 TEST_F (ClientProtocolTest, TestFinishedExtraData)
 
 TEST_F (ClientProtocolTest, TestFinishedMismatch)
 
 TEST_F (ClientProtocolTest, TestFinishedRejectedEarly)
 
 TEST_F (ClientProtocolTest, TestFinishedCompat)
 
 TEST_F (ClientProtocolTest, TestNewSessionTicket)
 
 TEST_F (ClientProtocolTest, TestNewSessionTicketNonce)
 
 TEST_F (ClientProtocolTest, TestNewSessionTicketEarlyData)
 
 TEST_F (ClientProtocolTest, TestAppData)
 
 TEST_F (ClientProtocolTest, TestAppWrite)
 
 TEST_F (ClientProtocolTest, TestKeyUpdateNotRequested)
 
 TEST_F (ClientProtocolTest, TestKeyUpdateExtraData)
 
 TEST_F (ClientProtocolTest, TestKeyUpdateRequestFlow)
 
 TEST_F (ClientProtocolTest, TestInvalidEarlyWrite)
 
 TEST_F (ClientProtocolTest, TestExpectingSHEarlyWrite)
 
 TEST_F (ClientProtocolTest, TestEarlyEncryptionLevelRecvSHLO)
 
 TEST_F (ClientProtocolTest, TestEarlyEncryptionLevelRecvFinished)
 
 TEST_F (ClientProtocolTest, TestEarlyWriteCompat)
 
 TEST_F (ClientProtocolTest, TestEarlyWriteCompatCCSAlreadySent)
 
 TEST_F (ClientProtocolTest, TestEarlyAcceptedCompatNoEarlyData)
 
 TEST_F (ClientProtocolTest, TestExpectingSHEarlyWriteRejected)
 
 TEST_F (ClientProtocolTest, TestExpectingEEEarlyWrite)
 
 TEST_F (ClientProtocolTest, TestExpectingEEEarlyWriteRejected)
 
 TEST_F (ClientProtocolTest, TestExpectingCertEarlyWriteRejected)
 
 TEST_F (ClientProtocolTest, TestExpectingCertVerifyEarlyWriteRejected)
 
 TEST_F (ClientProtocolTest, TestExpectingFinishedEarlyWrite)
 
 TEST_F (ClientProtocolTest, TestExpectingFinishedEarlyWriteRejected)
 
 TEST_F (ClientProtocolTest, TestEstablishedEarlyWrite)
 
 TEST_F (ClientProtocolTest, TestEstablishedEarlyWriteRejected)
 
 TEST_F (FizzClientTest, TestConnect)
 
 TEST_F (FizzClientTest, TestConnectPskIdentity)
 
 TEST_F (SynchronizedLruPskCacheTest, TestBasic)
 
 TEST_F (SynchronizedLruPskCacheTest, TestEviction)
 
CachedPsk getTestPsk (std::string pskName, std::chrono::system_clock::time_point issueTime)
 
void pskEq (const CachedPsk &psk1, const CachedPsk &psk2)
 

Typedef Documentation

Function Documentation

CachedPsk fizz::client::test::getTestPsk ( std::string  pskName,
std::chrono::system_clock::time_point  issueTime 
)

Definition at line 16 of file Utilities.h.

References fizz::client::CachedPsk::alpn, fizz::client::CachedPsk::cipher, fizz::client::CachedPsk::group, fizz::client::CachedPsk::maxEarlyDataSize, folly::gen::move, fizz::client::CachedPsk::psk, fizz::Resumption, fizz::client::CachedPsk::secret, fizz::client::CachedPsk::ticketAgeAdd, fizz::client::CachedPsk::ticketExpirationTime, fizz::client::CachedPsk::ticketIssueTime, fizz::tls_1_3, fizz::TLS_AES_128_GCM_SHA256, fizz::client::CachedPsk::type, fizz::client::CachedPsk::version, and fizz::x25519.

Referenced by fizz::client::test::SynchronizedLruPskCacheTest::getCachedPsk(), and fizz::client::test::ClientProtocolTest::getCachedPsk().

18  {
19  CachedPsk psk;
20  psk.psk = std::move(pskName);
21  psk.secret = "resumptionsecret";
22  psk.type = PskType::Resumption;
23  psk.version = ProtocolVersion::tls_1_3;
24  psk.cipher = CipherSuite::TLS_AES_128_GCM_SHA256;
25  psk.group = NamedGroup::x25519;
26  psk.maxEarlyDataSize = 0;
27  psk.ticketAgeAdd = 0x11111111;
28  psk.ticketIssueTime = issueTime;
29  psk.ticketExpirationTime = issueTime + std::chrono::seconds(10);
30  psk.alpn = "h2";
31  return psk;
32 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
fizz::client::test::MATCHER_P ( BufMatches  ,
expected  ,
""   
)

Definition at line 179 of file AsyncFizzClientTest.cpp.

References folly::eq.

179  {
181  return eq(*arg, *expected);
182 }
void fizz::client::test::pskEq ( const CachedPsk psk1,
const CachedPsk psk2 
)

Definition at line 34 of file Utilities.h.

References fizz::client::CachedPsk::alpn, fizz::client::CachedPsk::cipher, EXPECT_EQ, fizz::client::CachedPsk::group, fizz::client::CachedPsk::maxEarlyDataSize, fizz::client::CachedPsk::psk, fizz::client::CachedPsk::secret, fizz::client::CachedPsk::ticketAgeAdd, fizz::client::CachedPsk::ticketExpirationTime, fizz::client::CachedPsk::ticketIssueTime, fizz::client::CachedPsk::type, and fizz::client::CachedPsk::version.

Referenced by TEST_F().

34  {
35  EXPECT_EQ(psk1.psk, psk2.psk);
36  EXPECT_EQ(psk1.secret, psk2.secret);
37  EXPECT_EQ(psk1.type, psk2.type);
38  EXPECT_EQ(psk1.version, psk2.version);
39  EXPECT_EQ(psk1.cipher, psk2.cipher);
40  EXPECT_EQ(psk1.group, psk2.group);
41  EXPECT_EQ(psk1.maxEarlyDataSize, psk2.maxEarlyDataSize);
42  EXPECT_EQ(psk1.ticketAgeAdd, psk2.ticketAgeAdd);
43  EXPECT_EQ(psk1.ticketIssueTime, psk2.ticketIssueTime);
44  EXPECT_EQ(psk1.ticketExpirationTime, psk2.ticketExpirationTime);
45  EXPECT_EQ(psk1.alpn, psk2.alpn);
46 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fizz::client::test::TEST_F ( SynchronizedLruPskCacheTest  ,
TestBasic   
)

Definition at line 39 of file SynchronizedLruPskCacheTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, and pskEq().

39  {
40  auto psk = getCachedPsk();
41  cache_->putPsk("fizz", psk);
42  auto cachedPsk = cache_->getPsk("fizz");
43  EXPECT_TRUE(cachedPsk);
44  pskEq(psk, *cachedPsk);
45 
46  cache_->removePsk("fizz");
47  EXPECT_FALSE(cache_->getPsk("fizz"));
48 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
void pskEq(const CachedPsk &psk1, const CachedPsk &psk2)
Definition: Utilities.h:34
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
fizz::client::test::TEST_F ( SynchronizedLruPskCacheTest  ,
TestEviction   
)

Definition at line 50 of file SynchronizedLruPskCacheTest.cpp.

References EXPECT_FALSE, i, and folly::sformat().

50  {
51  for (int i : {1, 2, 3}) {
52  auto pskName = folly::sformat("psk {}", i);
53  auto psk = getCachedPsk(pskName);
54  cache_->putPsk(pskName, psk);
55  }
56 
57  // Prime 1 to be evicted
58  cache_->getPsk("psk 2");
59  cache_->getPsk("psk 3");
60 
61  auto evictingPsk = getCachedPsk("psk 4");
62  cache_->putPsk("psk 4", evictingPsk);
63 
64  auto psk1 = cache_->getPsk("psk 1");
65  EXPECT_FALSE(psk1);
66 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
fizz::client::test::TEST_F ( FizzClientTest  ,
TestConnect   
)

Definition at line 61 of file FizzClientTest.cpp.

References testing::_, EXPECT_CALL, testing::InvokeWithoutArgs(), folly::none, sni, and string.

61  {
63  *MockClientStateMachineInstance::instance,
64  _processConnect(_, _, _, _, _, _))
65  .WillOnce(InvokeWithoutArgs([] { return Actions(); }));
66  const auto sni = std::string("www.example.com");
67  fizzClient_->fizzClient_.connect(context_, nullptr, sni, folly::none);
68 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
std::vector< Action > Actions
Definition: Actions.h:81
StringPiece sni
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( FizzClientTest  ,
TestConnectPskIdentity   
)

Definition at line 70 of file FizzClientTest.cpp.

References testing::_, context, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, testing::Invoke(), folly::gen::move, fizz::client::CachedPsk::psk, sni, and string.

70  {
71  std::string psk("psk");
73  *MockClientStateMachineInstance::instance,
74  _processConnect(_, _, _, _, _, _))
75  .WillOnce(
76  Invoke([psk](
77  const State&,
78  std::shared_ptr<const FizzClientContext> context,
79  std::shared_ptr<const CertificateVerifier> verifier,
82  const std::shared_ptr<ClientExtensions>& extensions) {
83  EXPECT_TRUE(cachedPsk);
84  EXPECT_EQ(cachedPsk->psk, psk);
85  EXPECT_EQ(sni, "www.example.com");
86  return Actions();
87  }));
88  const auto sni = std::string("www.example.com");
89  CachedPsk cachedPsk;
90  cachedPsk.psk = psk;
91  fizzClient_->fizzClient_.connect(
92  context_, nullptr, sni, std::move(cachedPsk));
93 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
context
Definition: CMakeCache.txt:563
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
State
See Core for details.
Definition: Core.h:43
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::vector< Action > Actions
Definition: Actions.h:81
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
StringPiece sni
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestConnect   
)

Definition at line 184 of file AsyncFizzClientTest.cpp.

References folly::netops::connect().

184  {
185  connect();
186 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestReadSingle   
)

Definition at line 188 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

188  {
189  connect();
190  EXPECT_CALL(*machine_, _processSocketData(_, _))
191  .WillOnce(
192  InvokeWithoutArgs([]() { return detail::actions(WaitForData()); }));
193  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
194 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestReadMulti   
)

Definition at line 196 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

196  {
197  connect();
198  EXPECT_CALL(*machine_, _processSocketData(_, _))
199  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }))
200  .WillOnce(
201  InvokeWithoutArgs([]() { return detail::actions(WaitForData()); }));
202  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
203 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestWrite   
)

Definition at line 205 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

205  {
206  connect();
207  EXPECT_CALL(*machine_, _processAppWrite(_, _))
208  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
209  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP GET"));
210 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestWriteMulti   
)

Definition at line 212 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

212  {
213  connect();
214  EXPECT_CALL(*machine_, _processAppWrite(_, _))
215  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
216  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP GET"));
217  EXPECT_CALL(*machine_, _processAppWrite(_, _))
218  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
219  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP POST"));
220 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestWriteErrorState   
)

Definition at line 222 of file AsyncFizzClientTest.cpp.

References testing::_, folly::netops::connect(), folly::IOBuf::copyBuffer(), folly::pushmi::operators::error(), EXPECT_CALL, ON_CALL, testing::Return(), and socket_.

222  {
223  connect();
224  ON_CALL(*socket_, error()).WillByDefault(Return(true));
225  EXPECT_CALL(writeCallback_, writeErr_(0, _));
226  client_->writeChain(&writeCallback_, IOBuf::copyBuffer("test"));
227 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
AsyncServerSocket::UniquePtr socket_
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define ON_CALL(obj, call)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestHandshake   
)

Definition at line 229 of file AsyncFizzClientTest.cpp.

References EXPECT_TRUE.

229  {
230  completeHandshake();
231  EXPECT_TRUE(client_->isReplaySafe());
232 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestExporterAPI   
)

Definition at line 234 of file AsyncFizzClientTest.cpp.

References EXPECT_THROW.

234  {
235  EXPECT_THROW(
236  client_->getEkm("EXPORTER-Some-Label", nullptr, 32), std::runtime_error);
237  completeHandshake();
238  client_->getEkm("EXPORTER-Some-Label", nullptr, 32);
239 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestHandshakeError   
)

Definition at line 241 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

241  {
242  connect();
243  EXPECT_CALL(*machine_, _processSocketData(_, _))
244  .WillOnce(InvokeWithoutArgs([]() {
245  return detail::actions(ReportError("unit test"), WaitForData());
246  }));
247  EXPECT_CALL(handshakeCallback_, _fizzHandshakeError(_));
248  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
249 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestHandshakeErrorDelete   
)

Definition at line 251 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

251  {
252  connect();
253  EXPECT_CALL(*machine_, _processSocketData(_, _))
254  .WillOnce(InvokeWithoutArgs([]() {
255  return detail::actions(ReportError("unit test"), WaitForData());
256  }));
257  EXPECT_CALL(handshakeCallback_, _fizzHandshakeError(_))
258  .WillOnce(InvokeWithoutArgs([this]() { client_.reset(); }));
259  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
260 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestInvalidTransitionNoAlert   
)

Definition at line 256 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::none, and fizz::client::ClientStateMachine::processAppWrite().

256  {
257  auto actions = ClientStateMachine().processAppWrite(state_, AppWrite());
258  expectError<FizzException>(actions, none, "invalid event");
259 }
Actions actions(Args &&...act)
Definition: Actions.h:86
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestInvalidWriteNewSessionTicket   
)

Definition at line 261 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::none, and fizz::client::ClientStateMachine::processWriteNewSessionTicket().

261  {
262  auto actions = ClientStateMachine().processWriteNewSessionTicket(
263  state_, WriteNewSessionTicket());
264  expectError<FizzException>(actions, none, "invalid event");
265 }
Actions actions(Args &&...act)
Definition: Actions.h:86
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestDeliverAppData   
)

Definition at line 262 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

262  {
263  completeHandshake();
264  client_->setReadCB(&readCallback_);
265  EXPECT_CALL(*machine_, _processSocketData(_, _))
266  .WillOnce(InvokeWithoutArgs([]() {
267  return detail::actions(
268  DeliverAppData{IOBuf::copyBuffer("HI")}, WaitForData());
269  }));
270  EXPECT_CALL(readCallback_, readBufferAvailable_(_));
271  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
272 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestInvalidTransitionAlert   
)

Definition at line 267 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), EXPECT_CALL, fizz::client::ClientStateMachine::processAppWrite(), and fizz::unexpected_message.

267  {
268  setMockRecord();
269  EXPECT_CALL(*mockWrite_, _write(_));
270  auto actions = ClientStateMachine().processAppWrite(state_, AppWrite());
271  expectError<FizzException>(
272  actions, AlertDescription::unexpected_message, "invalid event");
273 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestWriteToSocket   
)

Definition at line 274 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::WriteToSocket::contents, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::TLSContent::encryptionLevel, EXPECT_CALL, fizz::Handshake, fizz::handshake, testing::InvokeWithoutArgs(), folly::gen::move, socket_, and fizz::detail::write().

274  {
275  completeHandshake();
276  client_->setReadCB(&readCallback_);
277  EXPECT_CALL(*machine_, _processSocketData(_, _))
278  .WillOnce(InvokeWithoutArgs([]() {
279  TLSContent record;
280  record.contentType = ContentType::handshake;
281  record.data = IOBuf::copyBuffer("XYZ");
282  record.encryptionLevel = EncryptionLevel::Handshake;
283  WriteToSocket write;
284  write.contents.emplace_back(std::move(record));
285  return detail::actions(std::move(write), WaitForData());
286  }));
287  EXPECT_CALL(*socket_, writeChain(_, _, _));
288  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
289 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestInvalidTransitionError   
)

Definition at line 275 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::Error, and fizz::client::ClientStateMachine::processAppWrite().

275  {
276  state_.state() = StateEnum::Error;
277  auto actions = ClientStateMachine().processAppWrite(state_, AppWrite());
278  expectActions<ReportError>(actions);
279 }
error_stage Error
Actions actions(Args &&...act)
Definition: Actions.h:86
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectFlow   
)

Definition at line 281 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), fizz::TLSContent::contentType, fizz::Connect::context, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::encodeHandshake(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, fizz::handshake, testing::Invoke(), testing::InvokeWithoutArgs(), makeRandom(), folly::gen::move, fizz::NotAttempted, fizz::Plaintext, fizz::client::detail::processEvent(), random(), fizz::Connect::sni, fizz::Connect::verifier, verifier_, fizz::detail::write(), and fizz::x25519.

281  {
282  EXPECT_CALL(*factory_, makePlaintextReadRecordLayer())
283  .WillOnce(Invoke([this]() {
284  auto ret = std::make_unique<MockPlaintextReadRecordLayer>();
285  mockRead_ = ret.get();
286  return ret;
287  }));
288  EXPECT_CALL(*factory_, makePlaintextWriteRecordLayer())
289  .WillOnce(Invoke([this]() {
290  auto ret = std::make_unique<MockPlaintextWriteRecordLayer>();
291  mockWrite_ = ret.get();
292  EXPECT_CALL(*ret, _writeInitialClientHello(_))
293  .WillOnce(Invoke([](Buf& encoded) {
295  encoded, encodeHandshake(getDefaultClientHello())));
296  TLSContent record;
297  record.contentType = ContentType::handshake;
298  record.encryptionLevel = EncryptionLevel::Plaintext;
299  record.data = IOBuf::copyBuffer("writtenchlo");
300  return record;
301  }));
302  return ret;
303  }));
304  EXPECT_CALL(*factory_, makeRandom()).WillOnce(Invoke([]() {
305  Random random;
306  random.fill(0x44);
307  return random;
308  }));
309  MockKeyExchange* mockKex;
310  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::x25519))
311  .WillOnce(InvokeWithoutArgs([&mockKex]() {
312  auto ret = std::make_unique<MockKeyExchange>();
313  EXPECT_CALL(*ret, generateKeyPair());
314  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
315  return IOBuf::copyBuffer("keyshare");
316  }));
317  mockKex = ret.get();
318  return ret;
319  }));
320 
322  connect.context = context_;
323  connect.sni = "www.hostname.com";
324  connect.verifier = verifier_;
325  auto actions = detail::processEvent(state_, std::move(connect));
326 
327  expectActions<MutateState, WriteToSocket>(actions);
328  auto write = expectAction<WriteToSocket>(actions);
329  EXPECT_TRUE(
330  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("writtenchlo")));
331  processStateMutations(actions);
332  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
333  EXPECT_EQ(state_.readRecordLayer().get(), mockRead_);
334  EXPECT_EQ(state_.writeRecordLayer().get(), mockWrite_);
336  *state_.encodedClientHello(), encodeHandshake(getDefaultClientHello())));
337  EXPECT_EQ(state_.keyExchangers()->size(), 1);
338  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::x25519).get(), mockKex);
339  EXPECT_EQ(state_.verifier(), verifier_);
340  EXPECT_EQ(*state_.sni(), "www.hostname.com");
341  Random random;
342  random.fill(0x44);
343  EXPECT_EQ(*state_.clientRandom(), random);
344  EXPECT_FALSE(state_.attemptedPsk().hasValue());
345  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::NotAttempted);
346  EXPECT_EQ(state_.earlyWriteRecordLayer().get(), nullptr);
347  EXPECT_FALSE(state_.earlyDataParams().hasValue());
348 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
Integral2 random(Integral1 low, Integral2 up)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::unique_ptr< folly::IOBuf > makeRandom(size_t n)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestMutateState   
)

Definition at line 291 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::client::Error, EXPECT_CALL, EXPECT_EQ, testing::InvokeWithoutArgs(), fizz::test::State::state(), and uint32_t.

291  {
292  completeHandshake();
293  client_->setReadCB(&readCallback_);
294  uint32_t numTimesRun = 0;
295  EXPECT_CALL(*machine_, _processSocketData(_, _))
296  .WillOnce(InvokeWithoutArgs([&numTimesRun]() {
297  return detail::actions(
298  [&numTimesRun](State& newState) {
299  numTimesRun++;
300  newState.state() = StateEnum::Error;
301  },
302  WaitForData());
303  }));
304  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
305  EXPECT_EQ(client_->getState().state(), StateEnum::Error);
306  EXPECT_EQ(numTimesRun, 1);
307 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
error_stage Error
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
StateEnum state() const
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestCloseHandshake   
)

Definition at line 309 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), folly::netops::connect(), EXPECT_CALL, and socket_.

309  {
310  connect();
311  expectAppClose();
312  EXPECT_CALL(handshakeCallback_, _fizzHandshakeError(_));
313  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
314  client_->closeNow();
315 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
GTEST_API_ Cardinality AtLeast(int n)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestConnecting   
)

Definition at line 317 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::netops::connect(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_FALSE, EXPECT_TRUE, testing::InvokeWithoutArgs(), ON_CALL, testing::Return(), and socket_.

317  {
318  ON_CALL(*socket_, connecting()).WillByDefault(Return(true));
319  EXPECT_TRUE(client_->connecting());
320  ON_CALL(*socket_, connecting()).WillByDefault(Return(false));
321  connect();
322  EXPECT_TRUE(client_->connecting());
323  EXPECT_CALL(*machine_, _processSocketData(_, _))
324  .WillOnce(InvokeWithoutArgs([]() {
325  return detail::actions(ReportHandshakeSuccess(), WaitForData());
326  }));
327  EXPECT_CALL(handshakeCallback_, _fizzHandshakeSuccess());
328  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("ClientHello"));
329  EXPECT_FALSE(client_->connecting());
330 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ON_CALL(obj, call)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestGoodSocket   
)

Definition at line 332 of file AsyncFizzClientTest.cpp.

References folly::netops::connect(), EXPECT_FALSE, EXPECT_TRUE, ON_CALL, testing::Return(), and socket_.

332  {
333  connect();
334  ON_CALL(*socket_, good()).WillByDefault(Return(true));
335  EXPECT_TRUE(client_->good());
336  ON_CALL(*socket_, good()).WillByDefault(Return(false));
337  EXPECT_FALSE(client_->good());
338 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
AsyncServerSocket::UniquePtr socket_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ON_CALL(obj, call)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestGoodState   
)

Definition at line 340 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::client::Error, EXPECT_CALL, EXPECT_FALSE, EXPECT_TRUE, testing::InvokeWithoutArgs(), ON_CALL, testing::Return(), socket_, and fizz::test::State::state().

340  {
341  completeHandshake();
342  ON_CALL(*socket_, good()).WillByDefault(Return(true));
343  EXPECT_TRUE(client_->good());
344  EXPECT_CALL(*machine_, _processSocketData(_, _))
345  .WillOnce(InvokeWithoutArgs([]() {
346  return detail::actions(
347  [](State& newState) { newState.state() = StateEnum::Error; });
348  }));
349  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("Data"));
350  EXPECT_FALSE(client_->good());
351 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
error_stage Error
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
StateEnum state() const
#define ON_CALL(obj, call)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskFlow   
)

Definition at line 350 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::TLSContent::contentType, fizz::Connect::context, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, fizz::detail::getFinishedData(), fizz::handshake, testing::Invoke(), testing::InvokeWithoutArgs(), makeRandom(), folly::gen::move, fizz::NotAttempted, fizz::Plaintext, fizz::client::detail::processEvent(), random(), fizz::ResumptionPskBinder, fizz::Connect::sni, fizz::TLS_AES_128_GCM_SHA256, fizz::Connect::verifier, verifier_, fizz::detail::write(), and fizz::x25519.

350  {
351  auto psk = getCachedPsk();
352  EXPECT_CALL(*factory_, makePlaintextReadRecordLayer())
353  .WillOnce(Invoke([this]() {
354  auto ret = std::make_unique<MockPlaintextReadRecordLayer>();
355  mockRead_ = ret.get();
356  return ret;
357  }));
358  EXPECT_CALL(*factory_, makePlaintextWriteRecordLayer())
359  .WillOnce(Invoke([this]() {
360  auto ret = std::make_unique<MockPlaintextWriteRecordLayer>();
361  mockWrite_ = ret.get();
362  EXPECT_CALL(*ret, _writeInitialClientHello(_))
363  .WillOnce(Invoke([](Buf&) {
364  TLSContent record;
365  record.contentType = ContentType::handshake;
366  record.encryptionLevel = EncryptionLevel::Plaintext;
367  record.data = IOBuf::copyBuffer("writtenchlo");
368  return record;
369  }));
370  return ret;
371  }));
372  EXPECT_CALL(*factory_, makeRandom()).WillOnce(Invoke([]() {
373  Random random;
374  random.fill(0x44);
375  return random;
376  }));
377  MockKeyExchange* mockKex;
378  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::x25519))
379  .WillOnce(InvokeWithoutArgs([&mockKex]() {
380  auto ret = std::make_unique<MockKeyExchange>();
381  EXPECT_CALL(*ret, generateKeyPair());
382  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
383  return IOBuf::copyBuffer("keyshare");
384  }));
385  mockKex = ret.get();
386  return ret;
387  }));
388  mockKeyScheduler_ = new MockKeyScheduler();
389  mockHandshakeContext_ = new MockHandshakeContext();
390  Sequence contextSeq;
391  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
392  .WillOnce(InvokeWithoutArgs(
393  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
394  EXPECT_CALL(
395  *mockKeyScheduler_, deriveEarlySecret(RangeMatches("resumptionsecret")));
396  EXPECT_CALL(
397  *mockKeyScheduler_, getSecret(EarlySecrets::ResumptionPskBinder, _))
398  .WillOnce(InvokeWithoutArgs([]() {
399  return std::vector<uint8_t>({'b', 'k'});
400  }));
401  EXPECT_CALL(
402  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
403  .InSequence(contextSeq)
404  .WillOnce(InvokeWithoutArgs([=]() {
405  return std::unique_ptr<HandshakeContext>(mockHandshakeContext_);
406  }));
407  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
408  .InSequence(contextSeq);
409  EXPECT_CALL(*mockHandshakeContext_, getFinishedData(RangeMatches("bk")))
410  .InSequence(contextSeq)
411  .WillOnce(
412  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("binder"); }));
413  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
414  .InSequence(contextSeq);
415 
417  connect.context = context_;
418  connect.sni = "www.hostname.com";
419  connect.cachedPsk = psk;
420  connect.verifier = verifier_;
421  auto actions = detail::processEvent(state_, std::move(connect));
422 
423  expectActions<MutateState, WriteToSocket>(actions);
424  auto write = expectAction<WriteToSocket>(actions);
425  EXPECT_TRUE(
426  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("writtenchlo")));
427  processStateMutations(actions);
428  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
429  EXPECT_EQ(state_.readRecordLayer().get(), mockRead_);
430  EXPECT_EQ(state_.writeRecordLayer().get(), mockWrite_);
431  EXPECT_EQ(state_.keyExchangers()->size(), 1);
432  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::x25519).get(), mockKex);
433  EXPECT_EQ(state_.verifier(), verifier_);
434  EXPECT_EQ(*state_.sni(), "www.hostname.com");
435  Random random;
436  random.fill(0x44);
437  EXPECT_EQ(*state_.clientRandom(), random);
438  EXPECT_TRUE(state_.legacySessionId().value()->empty());
439  EXPECT_FALSE(state_.sentCCS());
440  EXPECT_EQ(state_.attemptedPsk()->psk, psk.psk);
441  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::NotAttempted);
442  EXPECT_EQ(state_.earlyWriteRecordLayer().get(), nullptr);
443  EXPECT_FALSE(state_.earlyDataParams().hasValue());
444 }
Integral2 random(Integral1 low, Integral2 up)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::unique_ptr< folly::IOBuf > makeRandom(size_t n)
Buf getFinishedData(std::unique_ptr< KeyDerivation > &deriver, Buf &finishedMacKey, const Buf &finishedTranscript)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestSocketConnect   
)

Definition at line 353 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), EXPECT_CALL, fizz::client::test::MockClientStateMachineInstance::instance, testing::Invoke(), testing::InvokeWithoutArgs(), folly::EventBase::loop(), and string.

353  {
354  MockConnectCallback cb;
355  EventBase evb;
356  auto evbClient = AsyncFizzClientT<MockClientStateMachineInstance>::UniquePtr(
357  new AsyncFizzClientT<MockClientStateMachineInstance>(&evb, context_));
358 
359  machine_ = MockClientStateMachineInstance::instance;
360  auto server = std::make_unique<TestServer>();
361 
362  EXPECT_CALL(*machine_, _processConnect(_, _, _, _, _, _))
363  .WillOnce(InvokeWithoutArgs([]() {
364  return detail::actions(ReportHandshakeSuccess(), WaitForData());
365  }));
366  EXPECT_CALL(cb, _connectSuccess()).WillOnce(Invoke([&evbClient]() {
367  evbClient->closeNow();
368  }));
369 
370  evbClient->connect(
371  server->getAddress(),
372  &cb,
373  nullptr,
374  std::string("www.example.com"),
375  pskIdentity_);
376 
377  evb.loop();
378 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestSocketConnectWithUnsupportedTransport   
)

Definition at line 380 of file AsyncFizzClientTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_THAT, testing::HasSubstr(), testing::Invoke(), testing::Return(), socket_, and string.

380  {
381  MockConnectCallback cb;
382  EXPECT_CALL(cb, _connectErr(_))
383  .WillOnce(Invoke([](const AsyncSocketException& ex) {
384  EXPECT_THAT(ex.what(), HasSubstr("could not find underlying socket"));
385  }));
386  EXPECT_CALL(*socket_, getWrappedTransport()).WillOnce(Return(nullptr));
387  client_->connect(
388  SocketAddress(),
389  &cb,
390  nullptr,
391  std::string("www.example.com"),
392  pskIdentity_);
393 }
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_THAT(value, matcher)
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestHandshakeConnectWithUnopenedSocket   
)

Definition at line 395 of file AsyncFizzClientTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_FALSE, EXPECT_THAT, testing::HasSubstr(), fizz::client::test::MockClientStateMachineInstance::instance, testing::Invoke(), string, folly::basic_fbstring< E, T, A, Storage >::toStdString(), and folly::exception_wrapper::what().

395  {
396  client_.reset();
397  EventBase evb;
398  auto evbClient = AsyncFizzClientT<MockClientStateMachineInstance>::UniquePtr(
399  new AsyncFizzClientT<MockClientStateMachineInstance>(&evb, context_));
400  machine_ = MockClientStateMachineInstance::instance;
401  EXPECT_CALL(handshakeCallback_, _fizzHandshakeError(_))
402  .WillOnce(Invoke([](exception_wrapper ex) {
403  EXPECT_THAT(
404  ex.what().toStdString(),
405  HasSubstr("handshake connect called but socket isn't open"));
406  }));
407  EXPECT_CALL(*machine_, _processConnect(_, _, _, _, _, _)).Times(0);
408  evbClient->connect(
409  &handshakeCallback_,
410  nullptr,
411  std::string("www.example.com"),
412  pskIdentity_);
413  EXPECT_FALSE(evbClient->good());
414 }
folly::fbstring what() const
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::basic_string< E, T, A > toStdString() const
Definition: FBString.h:1227
#define EXPECT_THAT(value, matcher)
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestSocketConnectWithOpenSocket   
)

Definition at line 416 of file AsyncFizzClientTest.cpp.

References testing::_, folly::AsyncSocketException::ALREADY_OPEN, folly::AsyncSocket::ConnectCallback::connectErr(), EXPECT_CALL, EXPECT_THAT, testing::HasSubstr(), testing::Invoke(), testing::Return(), socket_, and string.

416  {
417  MockConnectCallback cb;
418  EXPECT_CALL(cb, _connectErr(_))
419  .WillOnce(Invoke([](const AsyncSocketException& ex) {
420  EXPECT_THAT(ex.what(), HasSubstr("socket already open"));
421  }));
422  EventBase evb;
423  MockAsyncSocket mockSocket(&evb);
424  EXPECT_CALL(*socket_, getWrappedTransport()).WillOnce(Return(&mockSocket));
425  EXPECT_CALL(mockSocket, connect_(_, _, _, _, _))
426  .WillOnce(Invoke([](AsyncSocket::ConnectCallback* cb,
427  const SocketAddress&,
428  int,
429  const AsyncSocket::OptionMap&,
430  const SocketAddress&) {
432  AsyncSocketException::ALREADY_OPEN, "socket already open"));
433  }));
434  EXPECT_CALL(*machine_, _processConnect(_, _, _, _, _, _)).Times(0);
435  client_->connect(
436  SocketAddress(),
437  &cb,
438  nullptr,
439  std::string("www.example.com"),
440  pskIdentity_);
441 }
virtual void connectErr(const AsyncSocketException &ex) noexcept=0
std::map< OptionKey, int > OptionMap
Definition: AsyncSocket.h:376
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_THAT(value, matcher)
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestApplicationProtocol   
)

Definition at line 443 of file AsyncFizzClientTest.cpp.

References EXPECT_EQ.

443  {
444  completeHandshake();
445  EXPECT_EQ(client_->getApplicationProtocol(), "h2");
446 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskEarlyFlow   
)

Definition at line 446 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::Attempted, fizz::Connect::cachedPsk, fizz::ClientEarlyTraffic, folly::netops::connect(), fizz::TLSContent::contentType, fizz::Connect::context, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::EarlyExporter, fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, fizz::detail::getFinishedData(), fizz::handshake, testing::Invoke(), testing::InvokeWithoutArgs(), makeRandom(), folly::gen::move, fizz::Plaintext, fizz::client::detail::processEvent(), random(), fizz::ResumptionPskBinder, fizz::Connect::sni, fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, fizz::Connect::verifier, verifier_, fizz::detail::write(), and fizz::x25519.

446  {
447  auto psk = getCachedPsk();
448  psk.maxEarlyDataSize = 9000;
449  EXPECT_CALL(*factory_, makePlaintextReadRecordLayer())
450  .WillOnce(Invoke([this]() {
451  auto ret = std::make_unique<MockPlaintextReadRecordLayer>();
452  mockRead_ = ret.get();
453  return ret;
454  }));
455  EXPECT_CALL(*factory_, makePlaintextWriteRecordLayer())
456  .WillOnce(Invoke([this]() {
457  auto ret = std::make_unique<MockPlaintextWriteRecordLayer>();
458  mockWrite_ = ret.get();
459  EXPECT_CALL(*ret, _writeInitialClientHello(_))
460  .WillOnce(Invoke([](Buf&) {
461  TLSContent record;
462  record.contentType = ContentType::handshake;
463  record.encryptionLevel = EncryptionLevel::Plaintext;
464  record.data = IOBuf::copyBuffer("writtenchlo");
465  return record;
466  }));
467  return ret;
468  }));
469  EXPECT_CALL(*factory_, makeRandom()).WillOnce(Invoke([]() {
470  Random random;
471  random.fill(0x44);
472  return random;
473  }));
474  MockKeyExchange* mockKex;
475  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::x25519))
476  .WillOnce(InvokeWithoutArgs([&mockKex]() {
477  auto ret = std::make_unique<MockKeyExchange>();
478  EXPECT_CALL(*ret, generateKeyPair());
479  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
480  return IOBuf::copyBuffer("keyshare");
481  }));
482  mockKex = ret.get();
483  return ret;
484  }));
485  mockKeyScheduler_ = new MockKeyScheduler();
486  mockHandshakeContext_ = new MockHandshakeContext();
487  Sequence contextSeq;
488  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
489  .WillOnce(InvokeWithoutArgs(
490  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
491  EXPECT_CALL(
492  *mockKeyScheduler_, deriveEarlySecret(RangeMatches("resumptionsecret")));
493  EXPECT_CALL(
494  *mockKeyScheduler_, getSecret(EarlySecrets::ResumptionPskBinder, _))
495  .WillOnce(InvokeWithoutArgs([]() {
496  return std::vector<uint8_t>({'b', 'k'});
497  }));
498  EXPECT_CALL(
499  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
500  .InSequence(contextSeq)
501  .WillOnce(InvokeWithoutArgs([=]() {
502  return std::unique_ptr<HandshakeContext>(mockHandshakeContext_);
503  }));
504  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
505  .InSequence(contextSeq);
506  EXPECT_CALL(*mockHandshakeContext_, getFinishedData(RangeMatches("bk")))
507  .InSequence(contextSeq)
508  .WillOnce(
509  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("binder"); }));
510  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
511  .InSequence(contextSeq);
512  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
513  .WillRepeatedly(
514  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("chlo"); }));
515  EXPECT_CALL(
516  *mockKeyScheduler_,
517  getSecret(EarlySecrets::EarlyExporter, RangeMatches("chlo")))
518  .WillOnce(InvokeWithoutArgs([]() {
519  return std::vector<uint8_t>({'e', 'e'});
520  }));
521 
522  EXPECT_CALL(
523  *mockKeyScheduler_,
524  getSecret(EarlySecrets::ClientEarlyTraffic, RangeMatches("chlo")))
525  .WillOnce(InvokeWithoutArgs([]() {
526  return std::vector<uint8_t>({'c', 'e', 't'});
527  }));
528  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cet"), _, _))
529  .WillOnce(InvokeWithoutArgs([]() {
530  return TrafficKey{IOBuf::copyBuffer("clientearlykey"),
531  IOBuf::copyBuffer("clientearlyiv")};
532  }));
533  MockAead* earlyAead;
534  MockEncryptedWriteRecordLayer* earlyRecordLayer;
535  expectAeadCreation({{"clientearlykey", &earlyAead}});
536  expectEncryptedWriteRecordLayerCreation(
537  &earlyRecordLayer, &earlyAead, StringPiece("cet"));
538 
540  connect.context = context_;
541  connect.sni = "www.hostname.com";
542  connect.cachedPsk = psk;
543  connect.verifier = verifier_;
544  auto actions = detail::processEvent(state_, std::move(connect));
545 
546  expectActions<MutateState, WriteToSocket, ReportEarlyHandshakeSuccess>(
547  actions);
548  auto write = expectAction<WriteToSocket>(actions);
549  EXPECT_TRUE(
550  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("writtenchlo")));
551  auto earlySuccess = expectAction<ReportEarlyHandshakeSuccess>(actions);
552  EXPECT_EQ(earlySuccess.maxEarlyDataSize, 9000);
553  processStateMutations(actions);
554  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
555  EXPECT_EQ(state_.readRecordLayer().get(), mockRead_);
556  EXPECT_EQ(state_.writeRecordLayer().get(), mockWrite_);
557  EXPECT_EQ(state_.keyExchangers()->size(), 1);
558  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::x25519).get(), mockKex);
559  EXPECT_EQ(state_.verifier(), verifier_);
560  EXPECT_EQ(*state_.sni(), "www.hostname.com");
561  Random random;
562  random.fill(0x44);
563  EXPECT_EQ(*state_.clientRandom(), random);
564  EXPECT_TRUE(state_.legacySessionId().value()->empty());
565  EXPECT_FALSE(state_.sentCCS());
566  EXPECT_EQ(state_.attemptedPsk()->psk, psk.psk);
567  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Attempted);
568  EXPECT_EQ(state_.earlyWriteRecordLayer().get(), earlyRecordLayer);
569  EXPECT_EQ(state_.earlyDataParams()->version, TestProtocolVersion);
570  EXPECT_EQ(
571  state_.earlyDataParams()->cipher, CipherSuite::TLS_AES_128_GCM_SHA256);
572  EXPECT_EQ(state_.earlyDataParams()->serverCert, mockLeaf_);
573  EXPECT_EQ(state_.earlyDataParams()->clientCert, mockClientCert_);
574  EXPECT_EQ(state_.earlyDataParams()->alpn, "h2");
576  state_.earlyDataParams()->earlyExporterSecret, IOBuf::copyBuffer("ee")));
577 }
Integral2 random(Integral1 low, Integral2 up)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::unique_ptr< folly::IOBuf > makeRandom(size_t n)
Buf getFinishedData(std::unique_ptr< KeyDerivation > &deriver, Buf &finishedMacKey, const Buf &finishedTranscript)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestApplicationProtocolNone   
)

Definition at line 448 of file AsyncFizzClientTest.cpp.

References folly::netops::connect(), EXPECT_CALL, and EXPECT_EQ.

448  {
449  connect();
450  EXPECT_CALL(handshakeCallback_, _fizzHandshakeSuccess());
451  fullHandshakeSuccess(false, "");
452  EXPECT_EQ(client_->getApplicationProtocol(), "");
453 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestPskResumed   
)

Definition at line 455 of file AsyncFizzClientTest.cpp.

References folly::netops::connect(), EXPECT_CALL, and EXPECT_TRUE.

455  {
456  connect();
457  EXPECT_CALL(handshakeCallback_, _fizzHandshakeSuccess());
458  fullHandshakeSuccess(false, "h2", nullptr, nullptr, true);
459  EXPECT_TRUE(client_->pskResumed());
460 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestNoPskResumption   
)

Definition at line 462 of file AsyncFizzClientTest.cpp.

References folly::netops::connect(), EXPECT_CALL, and EXPECT_FALSE.

462  {
463  connect();
464  EXPECT_CALL(handshakeCallback_, _fizzHandshakeSuccess());
465  fullHandshakeSuccess(false, "h2", nullptr, nullptr, false);
466  EXPECT_FALSE(client_->pskResumed());
467 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_CALL(obj, call)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestGetCertsNone   
)

Definition at line 469 of file AsyncFizzClientTest.cpp.

References EXPECT_EQ.

469  {
470  completeHandshake();
471  EXPECT_EQ(client_->getSelfCert(), nullptr);
472  EXPECT_EQ(client_->getPeerCert(), nullptr);
473 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestGetCerts   
)

Definition at line 475 of file AsyncFizzClientTest.cpp.

References clientCert, folly::netops::connect(), EXPECT_CALL, EXPECT_EQ, and serverCert.

475  {
476  auto clientCert = std::make_shared<MockCert>();
477  auto serverCert = std::make_shared<MockCert>();
478  connect();
479  EXPECT_CALL(handshakeCallback_, _fizzHandshakeSuccess());
480  fullHandshakeSuccess(false, "h2", clientCert, serverCert);
481  EXPECT_CALL(*clientCert, getX509());
482  EXPECT_EQ(client_->getSelfCert(), nullptr);
483  EXPECT_CALL(*serverCert, getX509());
484  EXPECT_EQ(client_->getPeerCert(), nullptr);
485 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::shared_ptr< const Cert > serverCert
std::shared_ptr< const Cert > clientCert
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshake   
)

Definition at line 487 of file AsyncFizzClientTest.cpp.

References EXPECT_TRUE.

487  {
488  completeEarlyHandshake();
489  fullHandshakeSuccess(true);
490  EXPECT_TRUE(client_->isReplaySafe());
491  EXPECT_TRUE(client_->pskResumed());
492 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyParams   
)

Definition at line 494 of file AsyncFizzClientTest.cpp.

References clientCert, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::gen::move, params, and serverCert.

494  {
495  auto clientCert = std::make_shared<MockCert>();
496  auto serverCert = std::make_shared<MockCert>();
497  auto params = getEarlyDataParams();
498  params.clientCert = clientCert;
499  params.serverCert = serverCert;
500  completeEarlyHandshake(std::move(params));
501  EXPECT_EQ(client_->getApplicationProtocol(), "h2");
502  EXPECT_CALL(*clientCert, getX509());
503  EXPECT_EQ(client_->getSelfCert(), nullptr);
504  EXPECT_CALL(*serverCert, getX509());
505  EXPECT_EQ(client_->getPeerCert(), nullptr);
506 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
std::shared_ptr< const Cert > serverCert
std::shared_ptr< const Cert > clientCert
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyApplicationProtocolNone   
)

Definition at line 508 of file AsyncFizzClientTest.cpp.

References EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::gen::move, folly::none, and params.

508  {
509  auto params = getEarlyDataParams();
510  params.alpn = none;
511  completeEarlyHandshake(std::move(params));
512  EXPECT_EQ(client_->getApplicationProtocol(), "");
513 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeWrite   
)

Definition at line 515 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

515  {
516  completeEarlyHandshake();
517 
518  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
519  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
520  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP GET"));
521 
522  fullHandshakeSuccess(true);
523 
524  EXPECT_CALL(*machine_, _processAppWrite(_, _))
525  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
526  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP POST"));
527 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeReplaySafeCallback   
)

Definition at line 529 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, testing::Invoke(), and testing::InvokeWithoutArgs().

529  {
530  completeEarlyHandshake();
531  client_->setReplaySafetyCallback(&mockReplayCallback_);
532 
533  EXPECT_CALL(*machine_, _processAppWrite(_, _))
534  .WillOnce(InvokeWithoutArgs([]() { return detail::actions(); }));
535  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).WillOnce(Invoke([this]() {
536  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP POST"));
537  }));
538  fullHandshakeSuccess(true);
539 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeReplaySafeCallbackRemoved   
)

Definition at line 541 of file AsyncFizzClientTest.cpp.

References EXPECT_CALL.

541  {
542  completeEarlyHandshake();
543  client_->setReplaySafetyCallback(&mockReplayCallback_);
544  client_->setReplaySafetyCallback(nullptr);
545 
546  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
547  fullHandshakeSuccess(true);
548 }
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeOverLimit   
)

Definition at line 550 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), folly::IOBuf::create(), fizz::EarlyAppWrite::data, fizz::AppWrite::data, EXPECT_CALL, EXPECT_TRUE, testing::Invoke(), s, and fizz::detail::write().

550  {
551  completeEarlyHandshake();
552  client_->setReplaySafetyCallback(&mockReplayCallback_);
553 
554  auto earlyWrite = IOBuf::copyBuffer("earlywrite");
555  auto longWrite = IOBuf::create(2000);
556  std::memset(longWrite->writableData(), 'a', 2000);
557  longWrite->append(2000);
558  auto shortWrite = IOBuf::copyBuffer("shortwrite");
559  auto replaySafeWrite = IOBuf::copyBuffer("replaysafe");
560 
561  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
562  .WillOnce(Invoke([&earlyWrite](const State&, EarlyAppWrite& write) {
563  EXPECT_TRUE(IOBufEqualTo()(write.data, earlyWrite));
564  return detail::actions();
565  }));
566  client_->writeChain(nullptr, earlyWrite->clone());
567  client_->writeChain(nullptr, longWrite->clone());
568  client_->writeChain(nullptr, shortWrite->clone());
569 
570  Sequence s;
571  EXPECT_CALL(*machine_, _processAppWrite(_, _))
572  .InSequence(s)
573  .WillOnce(Invoke([&longWrite](const State&, AppWrite& write) {
574  EXPECT_TRUE(IOBufEqualTo()(write.data, longWrite));
575  return detail::actions();
576  }));
577  EXPECT_CALL(*machine_, _processAppWrite(_, _))
578  .InSequence(s)
579  .WillOnce(Invoke([&shortWrite](const State&, AppWrite& write) {
580  EXPECT_TRUE(IOBufEqualTo()(write.data, shortWrite));
581  return detail::actions();
582  }));
583  EXPECT_CALL(*machine_, _processAppWrite(_, _))
584  .InSequence(s)
585  .WillOnce(Invoke([&replaySafeWrite](const State&, AppWrite& write) {
586  EXPECT_TRUE(IOBufEqualTo()(write.data, replaySafeWrite));
587  return detail::actions();
588  }));
589 
590  EXPECT_CALL(mockReplayCallback_, onReplaySafe_())
591  .WillOnce(Invoke([this, &replaySafeWrite]() {
592  client_->writeChain(nullptr, replaySafeWrite->clone());
593  }));
594  fullHandshakeSuccess(true);
595 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectNoHostNoPsk   
)

Definition at line 579 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, and fizz::client::detail::processEvent().

579  {
581  connect.context = context_;
582  auto actions = detail::processEvent(state_, std::move(connect));
583  expectActions<MutateState, WriteToSocket>(actions);
584  processStateMutations(actions);
585  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
586  EXPECT_FALSE(state_.attemptedPsk().hasValue());
587 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskBadVersion   
)

Definition at line 589 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::tls_1_2.

589  {
591  connect.context = context_;
592  auto psk = getCachedPsk();
593  psk.version = ProtocolVersion::tls_1_2;
594  connect.cachedPsk = psk;
595  auto actions = detail::processEvent(state_, std::move(connect));
596  expectActions<MutateState, WriteToSocket>(actions);
597  processStateMutations(actions);
598  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
599  EXPECT_FALSE(state_.attemptedPsk().hasValue());
600 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeAllOverLimit   
)

Definition at line 597 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::create(), fizz::AppWrite::data, EXPECT_CALL, EXPECT_TRUE, testing::Invoke(), and fizz::detail::write().

597  {
598  completeEarlyHandshake();
599  client_->setReplaySafetyCallback(&mockReplayCallback_);
600 
601  auto buf = IOBuf::create(2000);
602  std::memset(buf->writableData(), 'a', 2000);
603  buf->append(2000);
604  client_->writeChain(nullptr, buf->clone());
605 
606  EXPECT_CALL(*machine_, _processAppWrite(_, _))
607  .WillOnce(Invoke([&buf](const State&, AppWrite& write) {
608  EXPECT_TRUE(IOBufEqualTo()(write.data, buf));
609  return detail::actions();
610  }));
611  EXPECT_CALL(mockReplayCallback_, onReplaySafe_());
612  fullHandshakeSuccess(true);
613 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskBadCipher   
)

Definition at line 602 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::client::detail::processEvent(), fizz::TLS_AES_128_GCM_SHA256, and fizz::TLS_AES_256_GCM_SHA384.

602  {
603  context_->setSupportedCiphers({CipherSuite::TLS_AES_128_GCM_SHA256});
605  connect.context = context_;
606  auto psk = getCachedPsk();
607  psk.cipher = CipherSuite::TLS_AES_256_GCM_SHA384;
608  connect.cachedPsk = psk;
609  auto actions = detail::processEvent(state_, std::move(connect));
610  expectActions<MutateState, WriteToSocket>(actions);
611  processStateMutations(actions);
612  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
613  EXPECT_FALSE(state_.attemptedPsk().hasValue());
614 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedFatalError   
)

Definition at line 615 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), folly::IOBuf::copyBuffer(), folly::IOBuf::create(), EXPECT_CALL, fizz::client::FatalConnectionError, folly::gen::move, and socket_.

615  {
616  client_->setEarlyDataRejectionPolicy(
617  EarlyDataRejectionPolicy::FatalConnectionError);
618  completeEarlyHandshake();
619 
620  auto buf = IOBuf::create(2000);
621  std::memset(buf->writableData(), 'a', 2000);
622  buf->append(2000);
623  client_->writeChain(nullptr, std::move(buf));
624  client_->writeChain(&writeCallback_, IOBuf::copyBuffer("write"));
625 
626  EXPECT_CALL(writeCallback_, writeErr_(0, _));
627  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
628  fullHandshakeSuccess(false);
629 }
GTEST_API_ Cardinality AtLeast(int n)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncServerSocket::UniquePtr socket_
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectSeparatePskIdentity   
)

Definition at line 616 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Connect::sni.

616  {
618  connect.context = context_;
619  connect.sni = "www.hostname.com";
620  auto psk = getCachedPsk();
621  connect.cachedPsk = psk;
622  auto actions = detail::processEvent(state_, std::move(connect));
623  expectActions<MutateState, WriteToSocket>(actions);
624  processStateMutations(actions);
625  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
626  EXPECT_EQ(state_.attemptedPsk()->psk, psk.psk);
627 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskIdentityWithoutSni   
)

Definition at line 629 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, and fizz::client::detail::processEvent().

629  {
631  connect.context = context_;
632  auto psk = getCachedPsk();
633  connect.cachedPsk = psk;
634  auto actions = detail::processEvent(state_, std::move(connect));
635  expectActions<MutateState, WriteToSocket>(actions);
636  processStateMutations(actions);
637  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
638  EXPECT_EQ(state_.attemptedPsk()->psk, psk.psk);
639  EXPECT_FALSE(state_.sni().hasValue());
640 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedPendingWriteError   
)

Definition at line 631 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::client::FatalConnectionError, folly::AsyncSocketException::getType(), testing::Invoke(), and socket_.

631  {
632  client_->setEarlyDataRejectionPolicy(
633  EarlyDataRejectionPolicy::FatalConnectionError);
634  completeEarlyHandshake();
635  client_->setReplaySafetyCallback(&mockReplayCallback_);
636  client_->setReadCB(&readCallback_);
637  EXPECT_CALL(readCallback_, readErr_(_))
638  .WillOnce(Invoke([](const AsyncSocketException& ex) {
639  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
640  }));
641  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
642  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
643  fullHandshakeSuccess(false);
644 }
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectNoSni   
)

Definition at line 642 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), chlo, folly::netops::connect(), fizz::Connect::context, fizz::encodeHandshake(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), fizz::server_name, fizz::Connect::verifier, and verifier_.

642  {
644  connect.context = context_;
645  connect.verifier = verifier_;
646  auto actions = detail::processEvent(state_, std::move(connect));
647  expectActions<MutateState, WriteToSocket>(actions);
648  processStateMutations(actions);
649  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
650  auto chlo = getDefaultClientHello();
651  TestMessages::removeExtension(chlo, ExtensionType::server_name);
653  *state_.encodedClientHello(), encodeHandshake(std::move(chlo))));
654  EXPECT_EQ(state_.verifier(), verifier_);
655  EXPECT_FALSE(state_.sni().hasValue());
656 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
static const std::string chlo
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedAutoResendNoData   
)

Definition at line 646 of file AsyncFizzClientTest.cpp.

References fizz::client::AutomaticResend, and EXPECT_CALL.

646  {
647  client_->setEarlyDataRejectionPolicy(
648  EarlyDataRejectionPolicy::AutomaticResend);
649  completeEarlyHandshake();
650  client_->setReplaySafetyCallback(&mockReplayCallback_);
651  EXPECT_CALL(mockReplayCallback_, onReplaySafe_());
652  fullHandshakeSuccess(false);
653 }
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedAutoResend   
)

Definition at line 655 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::client::AutomaticResend, folly::IOBuf::copyBuffer(), fizz::EarlyAppWrite::data, fizz::AppWrite::data, EXPECT_CALL, EXPECT_TRUE, testing::Invoke(), and fizz::detail::write().

655  {
656  client_->setEarlyDataRejectionPolicy(
657  EarlyDataRejectionPolicy::AutomaticResend);
658  completeEarlyHandshake();
659 
660  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
661  .WillOnce(Invoke([](const State&, EarlyAppWrite& write) {
662  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaa")));
663  return detail::actions();
664  }));
665  client_->writeChain(nullptr, IOBuf::copyBuffer("aaaa"));
666  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
667  .WillOnce(Invoke([](const State&, EarlyAppWrite& write) {
668  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("bbbb")));
669  return detail::actions();
670  }));
671  client_->writeChain(nullptr, IOBuf::copyBuffer("bbbb"));
672 
673  EXPECT_CALL(*machine_, _processAppWrite(_, _))
674  .WillOnce(Invoke([](const State&, AppWrite& write) {
675  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaabbbb")));
676  return detail::actions();
677  }));
678  fullHandshakeSuccess(false);
679 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectNoAlpn   
)

Definition at line 658 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_layer_protocol_negotiation, chlo, folly::netops::connect(), fizz::Connect::context, fizz::encodeHandshake(), EXPECT_EQ, EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), and fizz::Connect::sni.

658  {
659  context_->setSupportedAlpns({});
661  connect.context = context_;
662  connect.sni = "www.hostname.com";
663  auto actions = detail::processEvent(state_, std::move(connect));
664  expectActions<MutateState, WriteToSocket>(actions);
665  processStateMutations(actions);
666  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
667  auto chlo = getDefaultClientHello();
668  TestMessages::removeExtension(
669  chlo, ExtensionType::application_layer_protocol_negotiation);
671  *state_.encodedClientHello(), encodeHandshake(std::move(chlo))));
672 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
static const std::string chlo
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectExtension   
)

Definition at line 674 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), chlo, folly::netops::connect(), fizz::Connect::context, folly::IOBuf::copyBuffer(), fizz::encodeHandshake(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::Extension::extension_data, fizz::Extension::extension_type, fizz::Connect::extensions, testing::InvokeWithoutArgs(), folly::gen::move, fizz::client::detail::processEvent(), fizz::Connect::sni, fizz::token_binding, fizz::Connect::verifier, and verifier_.

674  {
676  connect.context = context_;
677  connect.verifier = verifier_;
678  connect.sni = "www.hostname.com";
679  auto extensions = std::make_shared<MockClientExtensions>();
680  connect.extensions = extensions;
681  EXPECT_CALL(*extensions, getClientHelloExtensions())
682  .WillOnce(InvokeWithoutArgs([]() {
683  Extension ext;
684  ext.extension_type = ExtensionType::token_binding;
685  ext.extension_data = folly::IOBuf::copyBuffer("some extension");
686  std::vector<Extension> exts;
687  exts.push_back(std::move(ext));
688  return exts;
689  }));
690  auto actions = detail::processEvent(state_, std::move(connect));
691  expectActions<MutateState, WriteToSocket>(actions);
692  processStateMutations(actions);
693  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
694  auto chlo = getDefaultClientHello();
695  Extension ext;
696  ext.extension_type = ExtensionType::token_binding;
697  ext.extension_data = folly::IOBuf::copyBuffer("some extension");
698  chlo.extensions.push_back(std::move(ext));
700  *state_.encodedClientHello(), encodeHandshake(std::move(chlo))));
701 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
static const std::string chlo
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedAutoResendOrder   
)

Definition at line 681 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::client::AutomaticResend, folly::IOBuf::copyBuffer(), folly::IOBuf::create(), fizz::EarlyAppWrite::data, fizz::AppWrite::data, EXPECT_CALL, EXPECT_TRUE, testing::Invoke(), s, and fizz::detail::write().

681  {
682  client_->setEarlyDataRejectionPolicy(
683  EarlyDataRejectionPolicy::AutomaticResend);
684  completeEarlyHandshake();
685  client_->setReplaySafetyCallback(&mockReplayCallback_);
686 
687  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
688  .WillOnce(Invoke([](const State&, EarlyAppWrite& write) {
689  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaa")));
690  return detail::actions();
691  }));
692  client_->writeChain(nullptr, IOBuf::copyBuffer("aaaa"));
693  auto buf = IOBuf::create(2000);
694  std::memset(buf->writableData(), 'b', 2000);
695  buf->append(2000);
696  client_->writeChain(nullptr, buf->clone());
697 
698  Sequence s;
699  EXPECT_CALL(*machine_, _processAppWrite(_, _))
700  .InSequence(s)
701  .WillOnce(Invoke([](const State&, AppWrite& write) {
702  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaa")));
703  return detail::actions();
704  }));
705  EXPECT_CALL(*machine_, _processAppWrite(_, _))
706  .InSequence(s)
707  .WillOnce(Invoke([&buf](const State&, AppWrite& write) {
708  EXPECT_TRUE(IOBufEqualTo()(write.data, buf));
709  return detail::actions();
710  }));
711  EXPECT_CALL(*machine_, _processAppWrite(_, _))
712  .InSequence(s)
713  .WillOnce(Invoke([](const State&, AppWrite& write) {
714  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("cccc")));
715  return detail::actions();
716  }));
717 
718  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).WillOnce(Invoke([this]() {
719  client_->writeChain(nullptr, IOBuf::copyBuffer("cccc"));
720  }));
721  fullHandshakeSuccess(false);
722 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectMultipleShares   
)

Definition at line 703 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::netops::connect(), fizz::Connect::context, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, testing::InvokeWithoutArgs(), folly::gen::move, fizz::client::detail::processEvent(), fizz::secp256r1, fizz::Connect::sni, and fizz::x25519.

703  {
704  MockKeyExchange* mockKex1;
705  MockKeyExchange* mockKex2;
706  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::x25519))
707  .WillOnce(InvokeWithoutArgs([&mockKex1]() {
708  auto ret = std::make_unique<MockKeyExchange>();
709  EXPECT_CALL(*ret, generateKeyPair());
710  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
711  return IOBuf::copyBuffer("x25519share");
712  }));
713  mockKex1 = ret.get();
714  return ret;
715  }));
716  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::secp256r1))
717  .WillOnce(InvokeWithoutArgs([&mockKex2]() {
718  auto ret = std::make_unique<MockKeyExchange>();
719  EXPECT_CALL(*ret, generateKeyPair());
720  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
721  return IOBuf::copyBuffer("p256share");
722  }));
723  mockKex2 = ret.get();
724  return ret;
725  }));
726 
727  context_->setDefaultShares({NamedGroup::x25519, NamedGroup::secp256r1});
729  connect.context = context_;
730  connect.sni = "www.hostname.com";
731  auto actions = detail::processEvent(state_, std::move(connect));
732  expectActions<MutateState, WriteToSocket>(actions);
733  processStateMutations(actions);
734  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
735  EXPECT_EQ(state_.keyExchangers()->size(), 2);
736  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::x25519).get(), mockKex1);
737  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::secp256r1).get(), mockKex2);
738 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyHandshakeRejectedAutoResendDeletedBuffer   
)

Definition at line 724 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::client::AutomaticResend, folly::IOBuf::copyBuffer(), fizz::EarlyAppWrite::data, fizz::AppWrite::data, EXPECT_CALL, EXPECT_TRUE, testing::Invoke(), and fizz::detail::write().

724  {
725  client_->setEarlyDataRejectionPolicy(
726  EarlyDataRejectionPolicy::AutomaticResend);
727  completeEarlyHandshake();
728 
729  auto buf = IOBuf::copyBuffer("aaaa");
730  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
731  .WillOnce(Invoke([&buf](const State&, EarlyAppWrite& write) {
732  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaa")));
733  buf.reset();
734  return detail::actions();
735  }));
736  client_->write(nullptr, buf->data(), buf->length());
737 
738  EXPECT_CALL(*machine_, _processAppWrite(_, _))
739  .WillOnce(Invoke([](const State&, AppWrite& write) {
740  EXPECT_TRUE(IOBufEqualTo()(write.data, IOBuf::copyBuffer("aaaa")));
741  return detail::actions();
742  }));
743  fullHandshakeSuccess(false);
744 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectCachedGroup   
)

Definition at line 740 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, testing::InvokeWithoutArgs(), folly::gen::move, fizz::client::detail::processEvent(), fizz::secp256r1, and fizz::x25519.

740  {
741  context_->setDefaultShares({NamedGroup::x25519});
742  MockKeyExchange* mockKex;
743  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::secp256r1))
744  .WillOnce(InvokeWithoutArgs([&mockKex]() {
745  auto ret = std::make_unique<MockKeyExchange>();
746  EXPECT_CALL(*ret, generateKeyPair());
747  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
748  return IOBuf::copyBuffer("p256share");
749  }));
750  mockKex = ret.get();
751  return ret;
752  }));
753 
754  auto psk = getCachedPsk();
755  psk.group = NamedGroup::secp256r1;
756 
758  connect.context = context_;
759  connect.cachedPsk = psk;
760  auto actions = detail::processEvent(state_, std::move(connect));
761  expectActions<MutateState, WriteToSocket>(actions);
762  processStateMutations(actions);
763  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
764  EXPECT_EQ(state_.keyExchangers()->size(), 1);
765  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::secp256r1).get(), mockKex);
766 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectResendDifferentAlpn   
)

Definition at line 746 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, folly::AsyncSocketException::getType(), testing::Invoke(), and socket_.

746  {
747  client_->setEarlyDataRejectionPolicy(
748  EarlyDataRejectionPolicy::AutomaticResend);
749  completeEarlyHandshake();
750  client_->setReplaySafetyCallback(&mockReplayCallback_);
751  client_->setReadCB(&readCallback_);
752  EXPECT_CALL(readCallback_, readErr_(_))
753  .WillOnce(Invoke([](const AsyncSocketException& ex) {
754  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
755  }));
756  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
757  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
758  fullHandshakeSuccess(false, "h3");
759 }
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectResendDifferentNoAlpn   
)

Definition at line 761 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, folly::AsyncSocketException::getType(), testing::Invoke(), and socket_.

761  {
762  client_->setEarlyDataRejectionPolicy(
763  EarlyDataRejectionPolicy::AutomaticResend);
764  completeEarlyHandshake();
765  client_->setReplaySafetyCallback(&mockReplayCallback_);
766  client_->setReadCB(&readCallback_);
767  EXPECT_CALL(readCallback_, readErr_(_))
768  .WillOnce(Invoke([](const AsyncSocketException& ex) {
769  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
770  }));
771  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
772  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
773  fullHandshakeSuccess(false, "h3");
774 }
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectNoShares   
)

Definition at line 768 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Connect::sni.

768  {
769  context_->setDefaultShares({});
771  connect.context = context_;
772  connect.sni = "www.hostname.com";
773  auto actions = detail::processEvent(state_, std::move(connect));
774  expectActions<MutateState, WriteToSocket>(actions);
775  processStateMutations(actions);
776  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
777  EXPECT_EQ(state_.keyExchangers()->size(), 0);
778 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectResendDifferentVersion   
)

Definition at line 776 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, socket_, and fizz::tls_1_2.

776  {
777  client_->setEarlyDataRejectionPolicy(
778  EarlyDataRejectionPolicy::AutomaticResend);
779  auto params = getEarlyDataParams();
780  params.version = ProtocolVersion::tls_1_2;
781  completeEarlyHandshake(std::move(params));
782  client_->setReplaySafetyCallback(&mockReplayCallback_);
783  client_->setReadCB(&readCallback_);
784  EXPECT_CALL(readCallback_, readErr_(_))
785  .WillOnce(Invoke([](const AsyncSocketException& ex) {
786  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
787  }));
788  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
789  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
790  fullHandshakeSuccess(false);
791 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskEarly   
)

Definition at line 780 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_TRUE, folly::gen::move, and fizz::client::detail::processEvent().

780  {
782  connect.context = context_;
783  auto psk = getCachedPsk();
784  psk.maxEarlyDataSize = 1000;
785  connect.cachedPsk = psk;
786  auto actions = detail::processEvent(state_, std::move(connect));
787  expectActions<MutateState, WriteToSocket, ReportEarlyHandshakeSuccess>(
788  actions);
789  processStateMutations(actions);
790  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
791  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Attempted);
792  EXPECT_TRUE(state_.earlyDataParams().hasValue());
793 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectResendDifferentCipher   
)

Definition at line 793 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, socket_, and fizz::TLS_AES_256_GCM_SHA384.

793  {
794  client_->setEarlyDataRejectionPolicy(
795  EarlyDataRejectionPolicy::AutomaticResend);
796  auto params = getEarlyDataParams();
797  params.cipher = CipherSuite::TLS_AES_256_GCM_SHA384;
798  completeEarlyHandshake(std::move(params));
799  client_->setReplaySafetyCallback(&mockReplayCallback_);
800  client_->setReadCB(&readCallback_);
801  EXPECT_CALL(readCallback_, readErr_(_))
802  .WillOnce(Invoke([](const AsyncSocketException& ex) {
803  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
804  }));
805  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
806  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
807  fullHandshakeSuccess(false);
808 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskEarlyNoAlpn   
)

Definition at line 795 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_TRUE, folly::gen::move, folly::none, and fizz::client::detail::processEvent().

795  {
797  connect.context = context_;
798  auto psk = getCachedPsk();
799  psk.maxEarlyDataSize = 1000;
800  psk.alpn = folly::none;
801  connect.cachedPsk = psk;
802  auto actions = detail::processEvent(state_, std::move(connect));
803  expectActions<MutateState, WriteToSocket, ReportEarlyHandshakeSuccess>(
804  actions);
805  processStateMutations(actions);
806  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
807  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Attempted);
808  EXPECT_TRUE(state_.earlyDataParams().hasValue());
809  EXPECT_EQ(state_.earlyDataParams()->alpn, folly::none);
810 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectNoClientCert   
)

Definition at line 810 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, and socket_.

810  {
811  client_->setEarlyDataRejectionPolicy(
812  EarlyDataRejectionPolicy::AutomaticResend);
813  auto params = getEarlyDataParams();
814  params.clientCert = std::make_shared<MockCert>();
815  completeEarlyHandshake(std::move(params));
816  client_->setReplaySafetyCallback(&mockReplayCallback_);
817  client_->setReadCB(&readCallback_);
818  EXPECT_CALL(readCallback_, readErr_(_))
819  .WillOnce(Invoke([](const AsyncSocketException& ex) {
820  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
821  }));
822  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
823  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
824  fullHandshakeSuccess(false);
825 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskEarlyDisabled   
)

Definition at line 812 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::NotAttempted, and fizz::client::detail::processEvent().

812  {
813  context_->setSendEarlyData(false);
815  connect.context = context_;
816  auto psk = getCachedPsk();
817  psk.maxEarlyDataSize = 1000;
818  connect.cachedPsk = psk;
819  auto actions = detail::processEvent(state_, std::move(connect));
820  expectActions<MutateState, WriteToSocket>(actions);
821  processStateMutations(actions);
822  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
823  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::NotAttempted);
824  EXPECT_FALSE(state_.earlyDataParams().hasValue());
825 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskEarlyAlpnMismatch   
)

Definition at line 827 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::NotAttempted, and fizz::client::detail::processEvent().

827  {
829  connect.context = context_;
830  auto psk = getCachedPsk();
831  psk.maxEarlyDataSize = 1000;
832  psk.alpn = "gopher";
833  connect.cachedPsk = psk;
834  auto actions = detail::processEvent(state_, std::move(connect));
835  expectActions<MutateState, WriteToSocket>(actions);
836  processStateMutations(actions);
837  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
838  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::NotAttempted);
839  EXPECT_FALSE(state_.earlyDataParams().hasValue());
840 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectNoServerCert   
)

Definition at line 827 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, and socket_.

827  {
828  client_->setEarlyDataRejectionPolicy(
829  EarlyDataRejectionPolicy::AutomaticResend);
830  auto params = getEarlyDataParams();
831  params.clientCert = std::make_shared<MockCert>();
832  completeEarlyHandshake(std::move(params));
833  client_->setReplaySafetyCallback(&mockReplayCallback_);
834  client_->setReadCB(&readCallback_);
835  EXPECT_CALL(readCallback_, readErr_(_))
836  .WillOnce(Invoke([](const AsyncSocketException& ex) {
837  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
838  }));
839  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
840  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
841  fullHandshakeSuccess(false);
842 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectCompat   
)

Definition at line 842 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Connect::sni.

842  {
843  context_->setCompatibilityMode(true);
845  connect.context = context_;
846  connect.sni = "www.hostname.com";
847  auto actions = detail::processEvent(state_, std::move(connect));
848  expectActions<MutateState, WriteToSocket>(actions);
849  processStateMutations(actions);
850  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
851  EXPECT_FALSE(state_.sentCCS());
852  EXPECT_FALSE(state_.legacySessionId().value()->empty());
853 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectDifferentServerIdentity   
)

Definition at line 844 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, testing::Return(), and socket_.

844  {
845  client_->setEarlyDataRejectionPolicy(
846  EarlyDataRejectionPolicy::AutomaticResend);
847  auto cert1 = std::make_shared<MockCert>();
848  auto cert2 = std::make_shared<MockCert>();
849  auto params = getEarlyDataParams();
850  params.serverCert = cert1;
851  completeEarlyHandshake(std::move(params));
852  client_->setReplaySafetyCallback(&mockReplayCallback_);
853  client_->setReadCB(&readCallback_);
854  EXPECT_CALL(readCallback_, readErr_(_))
855  .WillOnce(Invoke([](const AsyncSocketException& ex) {
856  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
857  }));
858  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
859  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
860  EXPECT_CALL(*cert1, getIdentity()).WillOnce(Return("id1"));
861  EXPECT_CALL(*cert2, getIdentity()).WillOnce(Return("id2"));
862  fullHandshakeSuccess(false, "h2", nullptr, cert2);
863 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectCompatEarly   
)

Definition at line 855 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::gen::move, and fizz::client::detail::processEvent().

855  {
856  context_->setCompatibilityMode(true);
858  connect.context = context_;
859  auto psk = getCachedPsk();
860  psk.maxEarlyDataSize = 1000;
861  connect.cachedPsk = psk;
862  auto actions = detail::processEvent(state_, std::move(connect));
863  expectActions<MutateState, WriteToSocket, ReportEarlyHandshakeSuccess>(
864  actions);
865  processStateMutations(actions);
866  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
867  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Attempted);
868  EXPECT_TRUE(state_.earlyDataParams().hasValue());
869  EXPECT_FALSE(state_.sentCCS());
870  EXPECT_FALSE(state_.legacySessionId().value()->empty());
871 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectSameServerIdentity   
)

Definition at line 865 of file AsyncFizzClientTest.cpp.

References fizz::client::AutomaticResend, EXPECT_CALL, fizz::sm::getEarlyDataParams(), folly::gen::move, params, and testing::Return().

865  {
866  client_->setEarlyDataRejectionPolicy(
867  EarlyDataRejectionPolicy::AutomaticResend);
868  auto cert1 = std::make_shared<MockCert>();
869  auto cert2 = std::make_shared<MockCert>();
870  auto params = getEarlyDataParams();
871  params.serverCert = cert1;
872  completeEarlyHandshake(std::move(params));
873  client_->setReplaySafetyCallback(&mockReplayCallback_);
874  EXPECT_CALL(mockReplayCallback_, onReplaySafe_());
875  EXPECT_CALL(*cert1, getIdentity()).WillOnce(Return("id"));
876  EXPECT_CALL(*cert2, getIdentity()).WillOnce(Return("id"));
877  fullHandshakeSuccess(false, "h2", nullptr, cert2);
878 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
#define EXPECT_CALL(obj, call)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloFlow   
)

Definition at line 873 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::ClientHandshakeTraffic, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::Handshake, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::NotAttempted, fizz::OneRtt, fizz::client::detail::processEvent(), fizz::ServerHandshakeTraffic, fizz::test::TestMessages::serverHello(), fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

873  {
874  setupExpectingServerHello();
875  mockKeyScheduler_ = new MockKeyScheduler();
876  mockHandshakeContext_ = new MockHandshakeContext();
877  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
878  .WillOnce(InvokeWithoutArgs(
879  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
880  EXPECT_CALL(
881  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
882  .WillOnce(InvokeWithoutArgs([=]() {
883  return std::unique_ptr<HandshakeContext>(mockHandshakeContext_);
884  }));
885  Sequence contextSeq;
886  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(BufMatches("chlo")))
887  .InSequence(contextSeq);
888  EXPECT_CALL(
889  *mockHandshakeContext_, appendToTranscript(BufMatches("shloencoding")))
890  .InSequence(contextSeq);
891  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
892  .InSequence(contextSeq)
893  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo_shlo"); }));
894  EXPECT_CALL(*mockKex_, generateSharedSecret(RangeMatches("servershare")))
895  .WillOnce(InvokeWithoutArgs(
896  []() { return IOBuf::copyBuffer("sharedsecret"); }));
897  EXPECT_CALL(
898  *mockKeyScheduler_, deriveHandshakeSecret(RangeMatches("sharedsecret")));
899  EXPECT_CALL(
900  *mockKeyScheduler_,
901  getSecret(
902  HandshakeSecrets::ServerHandshakeTraffic, RangeMatches("chlo_shlo")))
903  .WillOnce(InvokeWithoutArgs([]() {
904  return std::vector<uint8_t>({'s', 'h', 't'});
905  }));
906  EXPECT_CALL(
907  *mockKeyScheduler_,
908  getSecret(
909  HandshakeSecrets::ClientHandshakeTraffic, RangeMatches("chlo_shlo")))
910  .WillOnce(InvokeWithoutArgs([]() {
911  return std::vector<uint8_t>({'c', 'h', 't'});
912  }));
913  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sht"), _, _))
914  .WillOnce(InvokeWithoutArgs([]() {
915  return TrafficKey{IOBuf::copyBuffer("serverkey"),
916  IOBuf::copyBuffer("serveriv")};
917  }));
918  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cht"), _, _))
919  .WillOnce(InvokeWithoutArgs([]() {
920  return TrafficKey{IOBuf::copyBuffer("clientkey"),
921  IOBuf::copyBuffer("clientiv")};
922  }));
923  MockAead* raead;
924  MockAead* waead;
925  MockEncryptedReadRecordLayer* rrl;
926  MockEncryptedWriteRecordLayer* wrl;
927  expectAeadCreation(&waead, &raead);
928  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sht"));
929  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cht"));
930 
931  auto actions = detail::processEvent(state_, TestMessages::serverHello());
932  expectActions<MutateState>(actions);
933  processStateMutations(actions);
934  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
935  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
936  EXPECT_EQ(
937  state_.readRecordLayer()->getEncryptionLevel(),
938  EncryptionLevel::Handshake);
939  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
940  EXPECT_EQ(
941  state_.writeRecordLayer()->getEncryptionLevel(),
942  EncryptionLevel::Handshake);
943  EXPECT_EQ(state_.handshakeContext().get(), mockHandshakeContext_);
944  EXPECT_EQ(state_.keyScheduler().get(), mockKeyScheduler_);
945  EXPECT_EQ(state_.version(), TestProtocolVersion);
946  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
947  EXPECT_EQ(state_.group(), NamedGroup::x25519);
949  *state_.clientHandshakeSecret(), IOBuf::copyBuffer("cht")));
951  *state_.serverHandshakeSecret(), IOBuf::copyBuffer("sht")));
952  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::OneRtt);
953  EXPECT_EQ(state_.pskType(), PskType::NotAttempted);
954  EXPECT_EQ(state_.serverCert(), nullptr);
955 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectDifferentClientIdentity   
)

Definition at line 880 of file AsyncFizzClientTest.cpp.

References testing::_, testing::AtLeast(), fizz::client::AutomaticResend, folly::AsyncSocketException::EARLY_DATA_REJECTED, EXPECT_CALL, EXPECT_EQ, fizz::sm::getEarlyDataParams(), folly::AsyncSocketException::getType(), testing::Invoke(), folly::gen::move, params, testing::Return(), and socket_.

880  {
881  client_->setEarlyDataRejectionPolicy(
882  EarlyDataRejectionPolicy::AutomaticResend);
883  auto cert1 = std::make_shared<MockCert>();
884  auto cert2 = std::make_shared<MockCert>();
885  auto params = getEarlyDataParams();
886  params.clientCert = cert1;
887  completeEarlyHandshake(std::move(params));
888  client_->setReplaySafetyCallback(&mockReplayCallback_);
889  client_->setReadCB(&readCallback_);
890  EXPECT_CALL(readCallback_, readErr_(_))
891  .WillOnce(Invoke([](const AsyncSocketException& ex) {
892  EXPECT_EQ(ex.getType(), AsyncSocketException::EARLY_DATA_REJECTED);
893  }));
894  EXPECT_CALL(*socket_, closeNow()).Times(AtLeast(1));
895  EXPECT_CALL(mockReplayCallback_, onReplaySafe_()).Times(0);
896  EXPECT_CALL(*cert1, getIdentity()).WillOnce(Return("id1"));
897  EXPECT_CALL(*cert2, getIdentity()).WillOnce(Return("id2"));
898  fullHandshakeSuccess(false, "h2", cert2, nullptr);
899 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
AsyncServerSocket::UniquePtr socket_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
AsyncSocketExceptionType getType() const noexcept
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectSameClientIdentity   
)

Definition at line 901 of file AsyncFizzClientTest.cpp.

References fizz::client::AutomaticResend, EXPECT_CALL, fizz::sm::getEarlyDataParams(), folly::gen::move, params, and testing::Return().

901  {
902  client_->setEarlyDataRejectionPolicy(
903  EarlyDataRejectionPolicy::AutomaticResend);
904  auto cert1 = std::make_shared<MockCert>();
905  auto cert2 = std::make_shared<MockCert>();
906  auto params = getEarlyDataParams();
907  params.clientCert = cert1;
908  completeEarlyHandshake(std::move(params));
909  client_->setReplaySafetyCallback(&mockReplayCallback_);
910  EXPECT_CALL(mockReplayCallback_, onReplaySafe_());
911  EXPECT_CALL(*cert1, getIdentity()).WillOnce(Return("id"));
912  EXPECT_CALL(*cert2, getIdentity()).WillOnce(Return("id"));
913  fullHandshakeSuccess(false, "h2", cert2, nullptr);
914 }
static Optional< EarlyDataParams > getEarlyDataParams(const FizzClientContext &context, const Optional< CachedPsk > &psk)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Params params[]
#define EXPECT_CALL(obj, call)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyRejectRemovePsk   
)

Definition at line 916 of file AsyncFizzClientTest.cpp.

References EXPECT_CALL.

916  {
917  EXPECT_CALL(*mockPskCache_, removePsk(*pskIdentity_));
918  completeEarlyHandshake();
919  fullHandshakeSuccess(false);
920 }
#define EXPECT_CALL(obj, call)
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyWriteRejected   
)

Definition at line 922 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, failed, testing::Invoke(), folly::gen::move, fizz::client::ReportEarlyWriteFailed::write, and fizz::detail::write().

922  {
923  completeEarlyHandshake();
924  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
925  .WillOnce(Invoke([](const State&, EarlyAppWrite& write) {
926  ReportEarlyWriteFailed failed;
927  failed.write = std::move(write);
928  return detail::actions(std::move(failed));
929  }));
930  EXPECT_CALL(writeCallback_, writeSuccess_());
931  client_->writeChain(&writeCallback_, IOBuf::copyBuffer("HTTP GET"));
932 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static bool failed
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestEarlyWriteRejectedNullCallback   
)

Definition at line 934 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, failed, testing::Invoke(), folly::gen::move, fizz::client::ReportEarlyWriteFailed::write, and fizz::detail::write().

934  {
935  completeEarlyHandshake();
936  EXPECT_CALL(*machine_, _processEarlyAppWrite(_, _))
937  .WillOnce(Invoke([](const State&, EarlyAppWrite& write) {
938  ReportEarlyWriteFailed failed;
939  failed.write = std::move(write);
940  return detail::actions(std::move(failed));
941  }));
942  client_->writeChain(nullptr, IOBuf::copyBuffer("HTTP GET"));
943 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static bool failed
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestErrorStopsActions   
)

Definition at line 945 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_FALSE, EXPECT_TRUE, and testing::InvokeWithoutArgs().

945  {
946  completeHandshake();
947  client_->setReadCB(&readCallback_);
948  EXPECT_CALL(*machine_, _processSocketData(_, _))
949  .WillOnce(InvokeWithoutArgs(
950  []() { return detail::actions(ReportError("unit test")); }));
951  EXPECT_FALSE(client_->error());
952  socketReadCallback_->readBufferAvailable(IOBuf::copyBuffer("Data"));
953  EXPECT_TRUE(client_->error());
954 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestNewCachedPskActions   
)

Definition at line 956 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, and testing::InvokeWithoutArgs().

956  {
957  completeHandshake();
958  client_->setReadCB(&readCallback_);
959  EXPECT_CALL(*machine_, _processSocketData(_, _))
960  .WillOnce(InvokeWithoutArgs(
961  []() { return detail::actions(NewCachedPsk(), WaitForData()); }));
962  EXPECT_CALL(*mockPskCache_, putPsk(*pskIdentity_, _));
963  socketReadCallback_->readBufferAvailable(
964  IOBuf::copyBuffer("NewSessionTicket"));
965 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloAfterHrrFlow   
)

Definition at line 957 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::ClientHandshakeTraffic, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::Handshake, fizz::HelloRetryRequest, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::NotAttempted, fizz::client::detail::processEvent(), fizz::ServerHandshakeTraffic, fizz::test::TestMessages::serverHello(), fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

957  {
958  setupExpectingServerHelloAfterHrr();
959  mockKeyScheduler_ = new MockKeyScheduler();
960  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
961  .WillOnce(InvokeWithoutArgs(
962  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
963  Sequence contextSeq;
964  EXPECT_CALL(
965  *mockHandshakeContext_, appendToTranscript(BufMatches("shloencoding")))
966  .InSequence(contextSeq);
967  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
968  .InSequence(contextSeq)
969  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo_shlo"); }));
970  EXPECT_CALL(*mockKex_, generateSharedSecret(RangeMatches("servershare")))
971  .WillOnce(InvokeWithoutArgs(
972  []() { return IOBuf::copyBuffer("sharedsecret"); }));
973  EXPECT_CALL(
974  *mockKeyScheduler_, deriveHandshakeSecret(RangeMatches("sharedsecret")));
975  EXPECT_CALL(
976  *mockKeyScheduler_,
977  getSecret(
978  HandshakeSecrets::ServerHandshakeTraffic, RangeMatches("chlo_shlo")))
979  .WillOnce(InvokeWithoutArgs([]() {
980  return std::vector<uint8_t>({'s', 'h', 't'});
981  }));
982  EXPECT_CALL(
983  *mockKeyScheduler_,
984  getSecret(
985  HandshakeSecrets::ClientHandshakeTraffic, RangeMatches("chlo_shlo")))
986  .WillOnce(InvokeWithoutArgs([]() {
987  return std::vector<uint8_t>({'c', 'h', 't'});
988  }));
989  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sht"), _, _))
990  .WillOnce(InvokeWithoutArgs([]() {
991  return TrafficKey{IOBuf::copyBuffer("serverkey"),
992  IOBuf::copyBuffer("serveriv")};
993  }));
994  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cht"), _, _))
995  .WillOnce(InvokeWithoutArgs([]() {
996  return TrafficKey{IOBuf::copyBuffer("clientkey"),
997  IOBuf::copyBuffer("clientiv")};
998  }));
999  MockAead* raead;
1000  MockAead* waead;
1001  MockEncryptedReadRecordLayer* rrl;
1002  MockEncryptedWriteRecordLayer* wrl;
1003  expectAeadCreation(&waead, &raead);
1004  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sht"));
1005  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cht"));
1006 
1007  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1008  expectActions<MutateState>(actions);
1009  processStateMutations(actions);
1010  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1011  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
1012  EXPECT_EQ(
1013  state_.readRecordLayer()->getEncryptionLevel(),
1014  EncryptionLevel::Handshake);
1015  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
1016  EXPECT_EQ(
1017  state_.writeRecordLayer()->getEncryptionLevel(),
1018  EncryptionLevel::Handshake);
1019  EXPECT_EQ(state_.handshakeContext().get(), mockHandshakeContext_);
1020  EXPECT_EQ(state_.keyScheduler().get(), mockKeyScheduler_);
1021  EXPECT_EQ(state_.version(), TestProtocolVersion);
1022  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1023  EXPECT_EQ(state_.group(), NamedGroup::x25519);
1025  *state_.clientHandshakeSecret(), IOBuf::copyBuffer("cht")));
1027  *state_.serverHandshakeSecret(), IOBuf::copyBuffer("sht")));
1028  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::HelloRetryRequest);
1029  EXPECT_EQ(state_.pskType(), PskType::NotAttempted);
1030  EXPECT_EQ(state_.serverCert(), nullptr);
1031 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( AsyncFizzClientTest  ,
TestNewCachedPskActionsWithEmptyPskIdentity   
)

Definition at line 967 of file AsyncFizzClientTest.cpp.

References testing::_, fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, testing::InvokeWithoutArgs(), and folly::none.

967  {
968  pskIdentity_ = folly::none;
969  completeHandshake();
970  client_->setReadCB(&readCallback_);
971  EXPECT_CALL(*machine_, _processSocketData(_, _))
972  .WillOnce(InvokeWithoutArgs(
973  []() { return detail::actions(NewCachedPsk(), WaitForData()); }));
974  EXPECT_CALL(*mockPskCache_, putPsk(_, _)).Times(0);
975  socketReadCallback_->readBufferAvailable(
976  IOBuf::copyBuffer("NewSessionTicket"));
977 }
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskFlow   
)

Definition at line 1033 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::ClientHandshakeTraffic, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::Handshake, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::OneRtt, fizz::client::detail::processEvent(), fizz::Resumption, fizz::ServerHandshakeTraffic, fizz::test::TestMessages::serverHelloPsk(), fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

1033  {
1034  setupExpectingServerHello();
1035  state_.attemptedPsk() = getCachedPsk();
1036  mockKeyScheduler_ = new MockKeyScheduler();
1037  mockHandshakeContext_ = new MockHandshakeContext();
1038  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
1039  .WillOnce(InvokeWithoutArgs(
1040  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
1041  EXPECT_CALL(
1042  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1043  .WillOnce(InvokeWithoutArgs([=]() {
1044  return std::unique_ptr<HandshakeContext>(mockHandshakeContext_);
1045  }));
1046  Sequence contextSeq;
1047  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(BufMatches("chlo")))
1048  .InSequence(contextSeq);
1049  EXPECT_CALL(
1050  *mockHandshakeContext_, appendToTranscript(BufMatches("shloencoding")))
1051  .InSequence(contextSeq);
1052  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
1053  .InSequence(contextSeq)
1054  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo_shlo"); }));
1055  EXPECT_CALL(*mockKex_, generateSharedSecret(RangeMatches("servershare")))
1056  .WillOnce(InvokeWithoutArgs(
1057  []() { return IOBuf::copyBuffer("sharedsecret"); }));
1058  EXPECT_CALL(
1059  *mockKeyScheduler_, deriveEarlySecret(RangeMatches("resumptionsecret")));
1060  EXPECT_CALL(
1061  *mockKeyScheduler_, deriveHandshakeSecret(RangeMatches("sharedsecret")));
1062  EXPECT_CALL(
1063  *mockKeyScheduler_,
1064  getSecret(
1065  HandshakeSecrets::ServerHandshakeTraffic, RangeMatches("chlo_shlo")))
1066  .WillOnce(InvokeWithoutArgs([]() {
1067  return std::vector<uint8_t>({'s', 'h', 't'});
1068  }));
1069  EXPECT_CALL(
1070  *mockKeyScheduler_,
1071  getSecret(
1072  HandshakeSecrets::ClientHandshakeTraffic, RangeMatches("chlo_shlo")))
1073  .WillOnce(InvokeWithoutArgs([]() {
1074  return std::vector<uint8_t>({'c', 'h', 't'});
1075  }));
1076  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sht"), _, _))
1077  .WillOnce(InvokeWithoutArgs([]() {
1078  return TrafficKey{IOBuf::copyBuffer("serverkey"),
1079  IOBuf::copyBuffer("serveriv")};
1080  }));
1081  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cht"), _, _))
1082  .WillOnce(InvokeWithoutArgs([]() {
1083  return TrafficKey{IOBuf::copyBuffer("clientkey"),
1084  IOBuf::copyBuffer("clientiv")};
1085  }));
1086  MockAead* raead;
1087  MockAead* waead;
1088  MockEncryptedReadRecordLayer* rrl;
1089  MockEncryptedWriteRecordLayer* wrl;
1090  expectAeadCreation(&waead, &raead);
1091  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sht"));
1092  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cht"));
1093 
1094  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1095  expectActions<MutateState>(actions);
1096  processStateMutations(actions);
1097  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1098  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
1099  EXPECT_EQ(
1100  state_.readRecordLayer()->getEncryptionLevel(),
1101  EncryptionLevel::Handshake);
1102  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
1103  EXPECT_EQ(
1104  state_.writeRecordLayer()->getEncryptionLevel(),
1105  EncryptionLevel::Handshake);
1106  EXPECT_EQ(state_.handshakeContext().get(), mockHandshakeContext_);
1107  EXPECT_EQ(state_.keyScheduler().get(), mockKeyScheduler_);
1108  EXPECT_EQ(state_.version(), TestProtocolVersion);
1109  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1110  EXPECT_EQ(state_.group(), NamedGroup::x25519);
1112  *state_.clientHandshakeSecret(), IOBuf::copyBuffer("cht")));
1114  *state_.serverHandshakeSecret(), IOBuf::copyBuffer("sht")));
1115  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::OneRtt);
1116  EXPECT_EQ(state_.pskType(), PskType::Resumption);
1117  EXPECT_EQ(state_.serverCert(), mockLeaf_);
1118  EXPECT_EQ(state_.clientCert(), mockClientCert_);
1119 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskNoDhFlow   
)

Definition at line 1121 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::ClientHandshakeTraffic, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, fizz::Handshake, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::key_share, folly::gen::move, fizz::None, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), fizz::Resumption, fizz::ServerHandshakeTraffic, fizz::test::TestMessages::serverHelloPsk(), fizz::test::TestProtocolVersion, and fizz::TLS_AES_128_GCM_SHA256.

1121  {
1122  setupExpectingServerHello();
1123  state_.attemptedPsk() = getCachedPsk();
1124  mockKeyScheduler_ = new MockKeyScheduler();
1125  mockHandshakeContext_ = new MockHandshakeContext();
1126  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
1127  .WillOnce(InvokeWithoutArgs(
1128  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
1129  EXPECT_CALL(
1130  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1131  .WillOnce(InvokeWithoutArgs([=]() {
1132  return std::unique_ptr<HandshakeContext>(mockHandshakeContext_);
1133  }));
1134  Sequence contextSeq;
1135  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(BufMatches("chlo")))
1136  .InSequence(contextSeq);
1137  EXPECT_CALL(
1138  *mockHandshakeContext_, appendToTranscript(BufMatches("shloencoding")))
1139  .InSequence(contextSeq);
1140  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
1141  .InSequence(contextSeq)
1142  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo_shlo"); }));
1143  EXPECT_CALL(
1144  *mockKeyScheduler_, deriveEarlySecret(RangeMatches("resumptionsecret")));
1145  EXPECT_CALL(*mockKeyScheduler_, deriveHandshakeSecret());
1146  EXPECT_CALL(
1147  *mockKeyScheduler_,
1148  getSecret(
1149  HandshakeSecrets::ServerHandshakeTraffic, RangeMatches("chlo_shlo")))
1150  .WillOnce(InvokeWithoutArgs([]() {
1151  return std::vector<uint8_t>({'s', 'h', 't'});
1152  }));
1153  EXPECT_CALL(
1154  *mockKeyScheduler_,
1155  getSecret(
1156  HandshakeSecrets::ClientHandshakeTraffic, RangeMatches("chlo_shlo")))
1157  .WillOnce(InvokeWithoutArgs([]() {
1158  return std::vector<uint8_t>({'c', 'h', 't'});
1159  }));
1160  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sht"), _, _))
1161  .WillOnce(InvokeWithoutArgs([]() {
1162  return TrafficKey{IOBuf::copyBuffer("serverkey"),
1163  IOBuf::copyBuffer("serveriv")};
1164  }));
1165  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cht"), _, _))
1166  .WillOnce(InvokeWithoutArgs([]() {
1167  return TrafficKey{IOBuf::copyBuffer("clientkey"),
1168  IOBuf::copyBuffer("clientiv")};
1169  }));
1170  MockAead* raead;
1171  MockAead* waead;
1172  MockEncryptedReadRecordLayer* rrl;
1173  MockEncryptedWriteRecordLayer* wrl;
1174  expectAeadCreation(&waead, &raead);
1175  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sht"));
1176  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cht"));
1177 
1178  auto shlo = TestMessages::serverHelloPsk();
1179  TestMessages::removeExtension(shlo, ExtensionType::key_share);
1180  auto actions = detail::processEvent(state_, std::move(shlo));
1181  expectActions<MutateState>(actions);
1182  processStateMutations(actions);
1183  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1184  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
1185  EXPECT_EQ(
1186  state_.readRecordLayer()->getEncryptionLevel(),
1187  EncryptionLevel::Handshake);
1188  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
1189  EXPECT_EQ(
1190  state_.writeRecordLayer()->getEncryptionLevel(),
1191  EncryptionLevel::Handshake);
1192  EXPECT_EQ(state_.handshakeContext().get(), mockHandshakeContext_);
1193  EXPECT_EQ(state_.keyScheduler().get(), mockKeyScheduler_);
1194  EXPECT_EQ(state_.version(), TestProtocolVersion);
1195  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1196  EXPECT_FALSE(state_.group().hasValue());
1198  *state_.clientHandshakeSecret(), IOBuf::copyBuffer("cht")));
1200  *state_.serverHandshakeSecret(), IOBuf::copyBuffer("sht")));
1201  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::None);
1202  EXPECT_EQ(state_.pskType(), PskType::Resumption);
1203  EXPECT_EQ(state_.serverCert(), mockLeaf_);
1204 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskAfterHrrFlow   
)

Definition at line 1206 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::ClientHandshakeTraffic, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::Handshake, fizz::HelloRetryRequest, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::client::detail::processEvent(), fizz::Resumption, fizz::ServerHandshakeTraffic, fizz::test::TestMessages::serverHelloPsk(), fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

1206  {
1207  setupExpectingServerHelloAfterHrr();
1208  state_.attemptedPsk() = getCachedPsk();
1209  mockKeyScheduler_ = new MockKeyScheduler();
1210  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
1211  .WillOnce(InvokeWithoutArgs(
1212  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
1213  Sequence contextSeq;
1214  EXPECT_CALL(
1215  *mockHandshakeContext_, appendToTranscript(BufMatches("shloencoding")))
1216  .InSequence(contextSeq);
1217  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
1218  .InSequence(contextSeq)
1219  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo_shlo"); }));
1220  EXPECT_CALL(*mockKex_, generateSharedSecret(RangeMatches("servershare")))
1221  .WillOnce(InvokeWithoutArgs(
1222  []() { return IOBuf::copyBuffer("sharedsecret"); }));
1223  EXPECT_CALL(
1224  *mockKeyScheduler_, deriveHandshakeSecret(RangeMatches("sharedsecret")));
1225  EXPECT_CALL(
1226  *mockKeyScheduler_,
1227  getSecret(
1228  HandshakeSecrets::ServerHandshakeTraffic, RangeMatches("chlo_shlo")))
1229  .WillOnce(InvokeWithoutArgs([]() {
1230  return std::vector<uint8_t>({'s', 'h', 't'});
1231  }));
1232  EXPECT_CALL(
1233  *mockKeyScheduler_,
1234  getSecret(
1235  HandshakeSecrets::ClientHandshakeTraffic, RangeMatches("chlo_shlo")))
1236  .WillOnce(InvokeWithoutArgs([]() {
1237  return std::vector<uint8_t>({'c', 'h', 't'});
1238  }));
1239  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sht"), _, _))
1240  .WillOnce(InvokeWithoutArgs([]() {
1241  return TrafficKey{IOBuf::copyBuffer("serverkey"),
1242  IOBuf::copyBuffer("serveriv")};
1243  }));
1244  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cht"), _, _))
1245  .WillOnce(InvokeWithoutArgs([]() {
1246  return TrafficKey{IOBuf::copyBuffer("clientkey"),
1247  IOBuf::copyBuffer("clientiv")};
1248  }));
1249  MockAead* raead;
1250  MockAead* waead;
1251  MockEncryptedReadRecordLayer* rrl;
1252  MockEncryptedWriteRecordLayer* wrl;
1253  expectAeadCreation(&waead, &raead);
1254  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sht"));
1255  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cht"));
1256 
1257  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1258  expectActions<MutateState>(actions);
1259  processStateMutations(actions);
1260  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1261  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
1262  EXPECT_EQ(
1263  state_.readRecordLayer()->getEncryptionLevel(),
1264  EncryptionLevel::Handshake);
1265  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
1266  EXPECT_EQ(
1267  state_.writeRecordLayer()->getEncryptionLevel(),
1268  EncryptionLevel::Handshake);
1269  EXPECT_EQ(state_.handshakeContext().get(), mockHandshakeContext_);
1270  EXPECT_EQ(state_.keyScheduler().get(), mockKeyScheduler_);
1271  EXPECT_EQ(state_.version(), TestProtocolVersion);
1272  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1273  EXPECT_EQ(state_.group(), NamedGroup::x25519);
1275  *state_.clientHandshakeSecret(), IOBuf::copyBuffer("cht")));
1277  *state_.serverHandshakeSecret(), IOBuf::copyBuffer("sht")));
1278  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::HelloRetryRequest);
1279  EXPECT_EQ(state_.pskType(), PskType::Resumption);
1280  EXPECT_EQ(state_.serverCert(), mockLeaf_);
1281 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHello   
)

Definition at line 1283 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::client::detail::processEvent(), and fizz::test::TestMessages::serverHello().

1283  {
1284  setupExpectingServerHello();
1285  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1286  expectActions<MutateState>(actions);
1287  processStateMutations(actions);
1288  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1289 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPsk   
)

Definition at line 1291 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::client::detail::processEvent(), fizz::Resumption, and fizz::test::TestMessages::serverHelloPsk().

1291  {
1292  setupExpectingServerHello();
1293  state_.attemptedPsk() = getCachedPsk();
1294  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1295  expectActions<MutateState>(actions);
1296  processStateMutations(actions);
1297  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1298  EXPECT_EQ(state_.pskType(), PskType::Resumption);
1299 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskRejected   
)

Definition at line 1301 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::client::detail::processEvent(), fizz::Rejected, and fizz::test::TestMessages::serverHello().

1301  {
1302  setupExpectingServerHello();
1303  state_.attemptedPsk() = getCachedPsk();
1304  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1305  expectActions<MutateState>(actions);
1306  processStateMutations(actions);
1307  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1308  EXPECT_EQ(state_.pskType(), PskType::Rejected);
1309 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloExtraData   
)

Definition at line 1311 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_CALL, fizz::client::detail::processEvent(), testing::Return(), fizz::test::TestMessages::serverHello(), and fizz::unexpected_message.

1311  {
1312  setupExpectingServerHello();
1313  EXPECT_CALL(*mockRead_, hasUnparsedHandshakeData())
1314  .WillRepeatedly(Return(true));
1315  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1316  expectError<FizzException>(
1317  actions, AlertDescription::unexpected_message, "data after server hello");
1318 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloBadVersion   
)

Definition at line 1320 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), folly::gen::move, fizz::client::detail::processEvent(), fizz::protocol_version, fizz::test::TestMessages::removeExtension(), fizz::ServerSupportedVersions::selected_version, fizz::test::TestMessages::serverHello(), fizz::supported_versions, and fizz::tls_1_1.

1320  {
1321  setupExpectingServerHello();
1322  auto shlo = TestMessages::serverHello();
1323  TestMessages::removeExtension(shlo, ExtensionType::supported_versions);
1324  ServerSupportedVersions supportedVersions;
1325  supportedVersions.selected_version = ProtocolVersion::tls_1_1;
1326  shlo.extensions.push_back(encodeExtension(std::move(supportedVersions)));
1327  auto actions = detail::processEvent(state_, std::move(shlo));
1328  expectError<FizzException>(
1329  actions,
1330  AlertDescription::protocol_version,
1331  "unsupported server version");
1332 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloBadCipher   
)

Definition at line 1334 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, folly::gen::move, fizz::client::detail::processEvent(), and fizz::test::TestMessages::serverHello().

1334  {
1335  setupExpectingServerHello();
1336  auto shlo = TestMessages::serverHello();
1337  shlo.cipher_suite = static_cast<CipherSuite>(0x03ff);
1338  auto actions = detail::processEvent(state_, std::move(shlo));
1339  expectError<FizzException>(
1340  actions, AlertDescription::handshake_failure, "unsupported cipher");
1341 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CipherSuite
Definition: Types.h:153
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloBadGroup   
)

Definition at line 1343 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::encodeExtension(), fizz::KeyShareEntry::group, fizz::handshake_failure, fizz::KeyShareEntry::key_exchange, fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), fizz::secp256r1, fizz::ServerKeyShare::server_share, fizz::test::TestMessages::serverHello(), and fizz::x25519.

1343  {
1344  context_->setSupportedGroups({NamedGroup::x25519});
1345  setupExpectingServerHello();
1346  auto shlo = TestMessages::serverHello();
1347  TestMessages::removeExtension(shlo, ExtensionType::key_share);
1348  ServerKeyShare serverKeyShare;
1349  serverKeyShare.server_share.group = NamedGroup::secp256r1;
1350  serverKeyShare.server_share.key_exchange =
1351  folly::IOBuf::copyBuffer("servershare");
1352  shlo.extensions.push_back(encodeExtension(std::move(serverKeyShare)));
1353  auto actions = detail::processEvent(state_, std::move(shlo));
1354  expectError<FizzException>(
1355  actions, AlertDescription::handshake_failure, "unsupported group");
1356 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloNoKeyShare   
)

Definition at line 1358 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), and fizz::test::TestMessages::serverHello().

1358  {
1359  setupExpectingServerHello();
1360  auto shlo = TestMessages::serverHello();
1361  TestMessages::removeExtension(shlo, ExtensionType::key_share);
1362  auto actions = detail::processEvent(state_, std::move(shlo));
1363  expectError<FizzException>(
1364  actions, AlertDescription::handshake_failure, "did not send share");
1365 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloHrrBadVersion   
)

Definition at line 1367 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::client::detail::processEvent(), fizz::test::TestMessages::serverHello(), and fizz::tls_1_2.

1367  {
1368  setupExpectingServerHelloAfterHrr();
1369  state_.version() = ProtocolVersion::tls_1_2;
1370  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1371  expectError<FizzException>(
1372  actions, AlertDescription::handshake_failure, "version does not match");
1373 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloHrrBadCipher   
)

Definition at line 1375 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::client::detail::processEvent(), fizz::test::TestMessages::serverHello(), and fizz::TLS_AES_256_GCM_SHA384.

1375  {
1376  setupExpectingServerHelloAfterHrr();
1377  state_.cipher() = CipherSuite::TLS_AES_256_GCM_SHA384;
1378  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1379  expectError<FizzException>(
1380  actions, AlertDescription::handshake_failure, "cipher does not match");
1381 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloHrrBadGroup   
)

Definition at line 1383 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, folly::gen::move, fizz::client::detail::processEvent(), fizz::secp256r1, and fizz::test::TestMessages::serverHello().

1383  {
1384  setupExpectingServerHelloAfterHrr();
1385  auto mockKex = std::make_unique<MockKeyExchange>();
1386  mockKex->setDefaults();
1387  std::map<NamedGroup, std::unique_ptr<KeyExchange>> kexs;
1388  kexs.emplace(NamedGroup::secp256r1, std::move(mockKex));
1389  state_.keyExchangers() = std::move(kexs);
1390 
1391  auto actions = detail::processEvent(state_, TestMessages::serverHello());
1392  expectError<FizzException>(
1393  actions, AlertDescription::handshake_failure, "group");
1394 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskAcceptedNotSent   
)

Definition at line 1396 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_layer_protocol_negotiation, fizz::illegal_parameter, fizz::key_share, fizz::key_share_old, fizz::client::detail::processEvent(), fizz::server_name, fizz::test::TestMessages::serverHelloPsk(), and fizz::supported_versions.

1396  {
1397  setupExpectingServerHello();
1398  state_.requestedExtensions() = std::vector<ExtensionType>(
1399  {ExtensionType::supported_versions,
1400  ExtensionType::key_share,
1401  ExtensionType::key_share_old,
1402  ExtensionType::server_name,
1403  ExtensionType::application_layer_protocol_negotiation});
1404  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1405  expectError<FizzException>(
1406  actions,
1407  AlertDescription::illegal_parameter,
1408  "unexpected extension in shlo: pre_shared_key");
1409 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloOtherPskAccepted   
)

Definition at line 1411 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::illegal_parameter, folly::gen::move, fizz::client::detail::processEvent(), fizz::ServerPresharedKey::selected_identity, and fizz::test::TestMessages::serverHello().

1411  {
1412  setupExpectingServerHello();
1413  state_.attemptedPsk() = getCachedPsk();
1414  auto shlo = TestMessages::serverHello();
1415  ServerPresharedKey pskExt;
1416  pskExt.selected_identity = 1;
1417  shlo.extensions.push_back(encodeExtension(std::move(pskExt)));
1418  auto actions = detail::processEvent(state_, std::move(shlo));
1419  expectError<FizzException>(
1420  actions, AlertDescription::illegal_parameter, "non-0 psk");
1421 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskDifferentHash   
)

Definition at line 1423 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::client::detail::processEvent(), fizz::test::TestMessages::serverHelloPsk(), and fizz::TLS_AES_256_GCM_SHA384.

1423  {
1424  setupExpectingServerHello();
1425  state_.attemptedPsk() = getCachedPsk();
1426  state_.attemptedPsk()->cipher = CipherSuite::TLS_AES_256_GCM_SHA384;
1427  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1428  expectError<FizzException>(
1429  actions,
1430  AlertDescription::handshake_failure,
1431  "incompatible cipher in psk");
1432 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskDifferentCompatibleCipher   
)

Definition at line 1434 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::client::detail::processEvent(), fizz::test::TestMessages::serverHelloPsk(), fizz::TLS_AES_128_GCM_SHA256, and fizz::TLS_CHACHA20_POLY1305_SHA256.

1434  {
1435  setupExpectingServerHello();
1436  state_.attemptedPsk() = getCachedPsk();
1437  state_.attemptedPsk()->cipher = CipherSuite::TLS_CHACHA20_POLY1305_SHA256;
1438  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1439  expectActions<MutateState>(actions);
1440  processStateMutations(actions);
1441  EXPECT_EQ(state_.state(), StateEnum::ExpectingEncryptedExtensions);
1442  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1443 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskDheNotSupported   
)

Definition at line 1445 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::client::detail::processEvent(), fizz::psk_ke, and fizz::test::TestMessages::serverHelloPsk().

1445  {
1446  context_->setSupportedPskModes({PskKeyExchangeMode::psk_ke});
1447  setupExpectingServerHello();
1448  state_.attemptedPsk() = getCachedPsk();
1449  auto actions = detail::processEvent(state_, TestMessages::serverHelloPsk());
1450  expectError<FizzException>(
1451  actions, AlertDescription::handshake_failure, "unsupported psk mode");
1452 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloExtensions   
)

Definition at line 1454 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_CALL, and fizz::client::detail::processEvent().

1454  {
1455  setupExpectingEncryptedExtensions();
1456  auto ext = std::make_shared<MockClientExtensions>();
1457  state_.extensions() = ext;
1458  EXPECT_CALL(*ext, onEncryptedExtensions(_));
1459  auto actions = detail::processEvent(state_, TestMessages::encryptedExt());
1460  expectActions<MutateState>(actions);
1461  processStateMutations(actions);
1462 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloPskKeNotSupported   
)

Definition at line 1464 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::psk_dhe_ke, fizz::test::TestMessages::removeExtension(), and fizz::test::TestMessages::serverHelloPsk().

1464  {
1465  context_->setSupportedPskModes({PskKeyExchangeMode::psk_dhe_ke});
1466  setupExpectingServerHello();
1467  state_.attemptedPsk() = getCachedPsk();
1468  auto shlo = TestMessages::serverHelloPsk();
1469  TestMessages::removeExtension(shlo, ExtensionType::key_share);
1470  auto actions = detail::processEvent(state_, std::move(shlo));
1471  expectError<FizzException>(
1472  actions, AlertDescription::handshake_failure, "unsupported psk mode");
1473 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestServerHelloBadSessionId   
)

Definition at line 1475 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::illegal_parameter, folly::gen::move, fizz::client::detail::processEvent(), and fizz::test::TestMessages::serverHello().

1475  {
1476  setupExpectingServerHello();
1477  auto shlo = TestMessages::serverHello();
1478  shlo.legacy_session_id_echo = IOBuf::copyBuffer("hi!!");
1479  auto actions = detail::processEvent(state_, std::move(shlo));
1480  expectError<FizzException>(
1481  actions, AlertDescription::illegal_parameter, "session id");
1482 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestConnectPskKeNoShares   
)

Definition at line 1484 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Connect::cachedPsk, folly::netops::connect(), fizz::Connect::context, EXPECT_EQ, EXPECT_TRUE, folly::gen::move, folly::none, and fizz::client::detail::processEvent().

1484  {
1485  Connect connect;
1486  connect.context = context_;
1487  auto psk = getCachedPsk();
1488  psk.group = folly::none;
1489  connect.cachedPsk = psk;
1490  auto actions = detail::processEvent(state_, std::move(connect));
1491  expectActions<MutateState, WriteToSocket>(actions);
1492  processStateMutations(actions);
1493  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1494 
1495  auto& encodedHello = *state_.encodedClientHello();
1496 
1497  // Get rid of handshake header (type + version)
1498  encodedHello->trimStart(4);
1499  auto decodedHello = decode<ClientHello>(std::move(encodedHello));
1500  auto keyShare = getExtension<ClientKeyShare>(decodedHello.extensions);
1501  EXPECT_TRUE(keyShare->client_shares.empty());
1502  EXPECT_TRUE(state_.keyExchangers()->empty());
1503 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestFlow   
)

Definition at line 1505 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), chlo, fizz::ClientKeyShare::client_shares, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::encodeExtension(), fizz::encodeHandshake(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, fizz::findExtension(), fizz::TLSMessage::fragment, fizz::KeyShareEntry::group, fizz::handshake, fizz::HelloRetryRequest, fizz::test::TestMessages::helloRetryRequest(), testing::Invoke(), testing::InvokeWithoutArgs(), fizz::KeyShareEntry::key_exchange, fizz::key_share, folly::gen::move, fizz::NotAttempted, fizz::Plaintext, fizz::client::detail::processEvent(), random(), fizz::secp256r1, fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, fizz::TLSMessage::type, verifier_, and fizz::detail::write().

1505  {
1506  setupExpectingServerHello();
1507  state_.clientRandom()->fill(0x66);
1508  auto mockHandshakeContext1 = new MockHandshakeContext();
1509  auto mockHandshakeContext2 = new MockHandshakeContext();
1510  Sequence contextSeq;
1511  EXPECT_CALL(
1512  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1513  .InSequence(contextSeq)
1514  .WillOnce(InvokeWithoutArgs([=]() {
1515  return std::unique_ptr<HandshakeContext>(mockHandshakeContext1);
1516  }));
1517  EXPECT_CALL(*mockHandshakeContext1, appendToTranscript(BufMatches("chlo")))
1518  .InSequence(contextSeq);
1519  EXPECT_CALL(*mockHandshakeContext1, getHandshakeContext())
1520  .InSequence(contextSeq)
1521  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo1"); }));
1522  EXPECT_CALL(
1523  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1524  .InSequence(contextSeq)
1525  .WillOnce(InvokeWithoutArgs([=]() {
1526  return std::unique_ptr<HandshakeContext>(mockHandshakeContext2);
1527  }));
1528  EXPECT_CALL(*mockHandshakeContext2, appendToTranscript(_))
1529  .InSequence(contextSeq);
1530  EXPECT_CALL(
1531  *mockHandshakeContext2, appendToTranscript(BufMatches("hrrencoding")))
1532  .InSequence(contextSeq);
1533  EXPECT_CALL(*mockHandshakeContext2, appendToTranscript(_))
1534  .InSequence(contextSeq);
1535  MockKeyExchange* mockKex;
1536  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::secp256r1))
1537  .WillOnce(InvokeWithoutArgs([&mockKex]() {
1538  auto ret = std::make_unique<MockKeyExchange>();
1539  EXPECT_CALL(*ret, generateKeyPair());
1540  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
1541  return IOBuf::copyBuffer("keyshare");
1542  }));
1543  mockKex = ret.get();
1544  return ret;
1545  }));
1546  auto chlo = getDefaultClientHello();
1547  chlo.random.fill(0x66);
1548  ClientKeyShare keyShare;
1549  KeyShareEntry entry;
1550  entry.group = NamedGroup::secp256r1;
1551  entry.key_exchange = folly::IOBuf::copyBuffer("keyshare");
1552  keyShare.client_shares.push_back(std::move(entry));
1553  auto it = chlo.extensions.erase(
1554  findExtension(chlo.extensions, ExtensionType::key_share));
1555  chlo.extensions.insert(it, encodeExtension(std::move(keyShare)));
1556  auto encodedExpectedChlo = encodeHandshake(std::move(chlo));
1557  EXPECT_CALL(*mockWrite_, _write(_)).WillOnce(Invoke([&](TLSMessage& msg) {
1558  TLSContent content;
1559  content.contentType = msg.type;
1560  content.encryptionLevel = mockWrite_->getEncryptionLevel();
1561  EXPECT_EQ(msg.type, ContentType::handshake);
1562  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, encodedExpectedChlo));
1563  content.data = IOBuf::copyBuffer("writtenchlo");
1564  return content;
1565  }));
1566 
1567  auto actions =
1568  detail::processEvent(state_, TestMessages::helloRetryRequest());
1569  expectActions<MutateState, WriteToSocket>(actions);
1570  auto write = expectAction<WriteToSocket>(actions);
1571  EXPECT_TRUE(
1572  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("writtenchlo")));
1573  processStateMutations(actions);
1574  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1575  EXPECT_EQ(state_.readRecordLayer().get(), mockRead_);
1576  EXPECT_EQ(
1577  state_.readRecordLayer()->getEncryptionLevel(),
1578  EncryptionLevel::Plaintext);
1579  EXPECT_EQ(state_.writeRecordLayer().get(), mockWrite_);
1580  EXPECT_EQ(
1581  state_.writeRecordLayer()->getEncryptionLevel(),
1582  EncryptionLevel::Plaintext);
1583  EXPECT_TRUE(
1584  IOBufEqualTo()(*state_.encodedClientHello(), encodedExpectedChlo));
1585  EXPECT_EQ(
1586  StringPiece((*state_.encodedClientHello())->coalesce()),
1587  StringPiece(encodedExpectedChlo->coalesce()));
1588  EXPECT_EQ(state_.keyExchangers()->size(), 1);
1589  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::secp256r1).get(), mockKex);
1590  EXPECT_EQ(state_.verifier(), verifier_);
1591  EXPECT_EQ(*state_.sni(), "www.hostname.com");
1592  Random random;
1593  random.fill(0x66);
1594  EXPECT_EQ(*state_.clientRandom(), random);
1595  EXPECT_FALSE(state_.sentCCS());
1596  EXPECT_EQ(state_.version(), TestProtocolVersion);
1597  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1598  EXPECT_FALSE(state_.group().hasValue());
1599  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::HelloRetryRequest);
1600  EXPECT_EQ(state_.earlyDataType(), EarlyDataType::NotAttempted);
1601 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
Integral2 random(Integral1 low, Integral2 up)
std::vector< Extension >::const_iterator findExtension(const std::vector< Extension > &extensions, ExtensionType type)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
static const std::string chlo
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestPskFlow   
)

Definition at line 1603 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, fizz::detail::getFinishedData(), fizz::handshake, fizz::HelloRetryRequest, fizz::test::TestMessages::helloRetryRequest(), testing::Invoke(), testing::InvokeWithoutArgs(), fizz::NotAttempted, fizz::Plaintext, fizz::client::detail::processEvent(), random(), fizz::ResumptionPskBinder, fizz::secp256r1, fizz::test::TestProtocolVersion, fizz::TLS_AES_128_GCM_SHA256, fizz::TLSMessage::type, verifier_, and fizz::detail::write().

1603  {
1604  auto psk = getCachedPsk();
1605  setupExpectingServerHello();
1606  state_.attemptedPsk() = psk;
1607  state_.clientRandom()->fill(0x66);
1608  auto mockHandshakeContext1 = new MockHandshakeContext();
1609  auto mockHandshakeContext2 = new MockHandshakeContext();
1610  mockKeyScheduler_ = new MockKeyScheduler();
1611  EXPECT_CALL(*factory_, makeKeyScheduler(CipherSuite::TLS_AES_128_GCM_SHA256))
1612  .WillOnce(InvokeWithoutArgs(
1613  [=]() { return std::unique_ptr<KeyScheduler>(mockKeyScheduler_); }));
1614  EXPECT_CALL(
1615  *mockKeyScheduler_, deriveEarlySecret(RangeMatches("resumptionsecret")));
1616  EXPECT_CALL(
1617  *mockKeyScheduler_, getSecret(EarlySecrets::ResumptionPskBinder, _))
1618  .WillOnce(InvokeWithoutArgs([]() {
1619  return std::vector<uint8_t>({'b', 'k'});
1620  }));
1621  Sequence contextSeq;
1622  EXPECT_CALL(
1623  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1624  .InSequence(contextSeq)
1625  .WillOnce(InvokeWithoutArgs([=]() {
1626  return std::unique_ptr<HandshakeContext>(mockHandshakeContext1);
1627  }));
1628  EXPECT_CALL(*mockHandshakeContext1, appendToTranscript(BufMatches("chlo")))
1629  .InSequence(contextSeq);
1630  EXPECT_CALL(*mockHandshakeContext1, getHandshakeContext())
1631  .InSequence(contextSeq)
1632  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("chlo1"); }));
1633  EXPECT_CALL(
1634  *factory_, makeHandshakeContext(CipherSuite::TLS_AES_128_GCM_SHA256))
1635  .InSequence(contextSeq)
1636  .WillOnce(InvokeWithoutArgs([=]() {
1637  return std::unique_ptr<HandshakeContext>(mockHandshakeContext2);
1638  }));
1639  EXPECT_CALL(*mockHandshakeContext2, appendToTranscript(_))
1640  .InSequence(contextSeq);
1641  EXPECT_CALL(
1642  *mockHandshakeContext2, appendToTranscript(BufMatches("hrrencoding")))
1643  .InSequence(contextSeq);
1644  EXPECT_CALL(*mockHandshakeContext2, appendToTranscript(_))
1645  .InSequence(contextSeq);
1646  EXPECT_CALL(*mockHandshakeContext2, getFinishedData(RangeMatches("bk")))
1647  .InSequence(contextSeq)
1648  .WillOnce(
1649  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("binder"); }));
1650  EXPECT_CALL(*mockHandshakeContext2, appendToTranscript(_))
1651  .InSequence(contextSeq);
1652  MockKeyExchange* mockKex;
1653  EXPECT_CALL(*factory_, makeKeyExchange(NamedGroup::secp256r1))
1654  .WillOnce(InvokeWithoutArgs([&mockKex]() {
1655  auto ret = std::make_unique<MockKeyExchange>();
1656  EXPECT_CALL(*ret, generateKeyPair());
1657  EXPECT_CALL(*ret, getKeyShare()).WillOnce(InvokeWithoutArgs([]() {
1658  return IOBuf::copyBuffer("keyshare");
1659  }));
1660  mockKex = ret.get();
1661  return ret;
1662  }));
1663  EXPECT_CALL(*mockWrite_, _write(_)).WillOnce(Invoke([&](TLSMessage& msg) {
1664  TLSContent content;
1665  content.contentType = msg.type;
1666  content.encryptionLevel = mockWrite_->getEncryptionLevel();
1667  EXPECT_EQ(msg.type, ContentType::handshake);
1668  content.data = IOBuf::copyBuffer("writtenchlo");
1669  return content;
1670  }));
1671 
1672  auto actions =
1673  detail::processEvent(state_, TestMessages::helloRetryRequest());
1674  expectActions<MutateState, WriteToSocket>(actions);
1675  auto write = expectAction<WriteToSocket>(actions);
1676  EXPECT_EQ(write.contents[0].contentType, ContentType::handshake);
1677  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::Plaintext);
1678  processStateMutations(actions);
1679  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1680  EXPECT_EQ(state_.readRecordLayer().get(), mockRead_);
1681  EXPECT_EQ(
1682  state_.readRecordLayer()->getEncryptionLevel(),
1683  EncryptionLevel::Plaintext);
1684  EXPECT_EQ(state_.writeRecordLayer().get(), mockWrite_);
1685  EXPECT_EQ(
1686  state_.writeRecordLayer()->getEncryptionLevel(),
1687  EncryptionLevel::Plaintext);
1688  EXPECT_EQ(state_.keyExchangers()->size(), 1);
1689  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::secp256r1).get(), mockKex);
1690  EXPECT_EQ(state_.verifier(), verifier_);
1691  EXPECT_EQ(*state_.sni(), "www.hostname.com");
1692  Random random;
1693  random.fill(0x66);
1694  EXPECT_EQ(*state_.clientRandom(), random);
1695  EXPECT_FALSE(state_.sentCCS());
1696  EXPECT_EQ(state_.version(), TestProtocolVersion);
1697  EXPECT_EQ(state_.cipher(), CipherSuite::TLS_AES_128_GCM_SHA256);
1698  EXPECT_FALSE(state_.group().hasValue());
1699  EXPECT_EQ(state_.keyExchangeType(), KeyExchangeType::HelloRetryRequest);
1700  EXPECT_EQ(state_.attemptedPsk()->psk, psk.psk);
1701  EXPECT_EQ(state_.earlyDataType(), EarlyDataType::NotAttempted);
1702 }
Integral2 random(Integral1 low, Integral2 up)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Buf getFinishedData(std::unique_ptr< KeyDerivation > &deriver, Buf &finishedMacKey, const Buf &finishedTranscript)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequest   
)

Definition at line 1704 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::test::TestMessages::helloRetryRequest(), and fizz::client::detail::processEvent().

1704  {
1705  setupExpectingServerHello();
1706  auto actions =
1707  detail::processEvent(state_, TestMessages::helloRetryRequest());
1708  expectActions<MutateState, WriteToSocket>(actions);
1709  processStateMutations(actions);
1710  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1711 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestPskDifferentHash   
)

Definition at line 1713 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, EXPECT_FALSE, fizz::test::TestMessages::helloRetryRequest(), fizz::client::detail::processEvent(), and fizz::TLS_AES_256_GCM_SHA384.

1713  {
1714  setupExpectingServerHello();
1715  state_.attemptedPsk() = getCachedPsk();
1716  state_.attemptedPsk()->cipher = CipherSuite::TLS_AES_256_GCM_SHA384;
1717  auto actions =
1718  detail::processEvent(state_, TestMessages::helloRetryRequest());
1719  expectActions<MutateState, WriteToSocket>(actions);
1720  processStateMutations(actions);
1721  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1722  EXPECT_FALSE(state_.attemptedPsk().hasValue());
1723 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestDoubleHelloRetryRequest   
)

Definition at line 1725 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::HelloRetryRequest, fizz::test::TestMessages::helloRetryRequest(), fizz::client::detail::processEvent(), and fizz::unexpected_message.

1725  {
1726  setupExpectingServerHello();
1727  state_.keyExchangeType() = KeyExchangeType::HelloRetryRequest;
1728  auto actions =
1729  detail::processEvent(state_, TestMessages::helloRetryRequest());
1730  expectError<FizzException>(
1731  actions, AlertDescription::unexpected_message, "two HRRs");
1732 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestBadVersion   
)

Definition at line 1734 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::helloRetryRequest(), folly::gen::move, fizz::client::detail::processEvent(), fizz::protocol_version, fizz::test::TestMessages::removeExtension(), fizz::ServerSupportedVersions::selected_version, fizz::supported_versions, and fizz::tls_1_1.

1734  {
1735  setupExpectingServerHello();
1736  auto hrr = TestMessages::helloRetryRequest();
1737  TestMessages::removeExtension(hrr, ExtensionType::supported_versions);
1738  ServerSupportedVersions supportedVersions;
1739  supportedVersions.selected_version = ProtocolVersion::tls_1_1;
1740  hrr.extensions.push_back(encodeExtension(std::move(supportedVersions)));
1741  auto actions = detail::processEvent(state_, std::move(hrr));
1742  expectError<FizzException>(
1743  actions,
1744  AlertDescription::protocol_version,
1745  "unsupported server version");
1746 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestBadCipher   
)

Definition at line 1748 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::handshake_failure, fizz::test::TestMessages::helloRetryRequest(), folly::gen::move, and fizz::client::detail::processEvent().

1748  {
1749  setupExpectingServerHello();
1750  auto hrr = TestMessages::helloRetryRequest();
1751  hrr.cipher_suite = static_cast<CipherSuite>(0x03ff);
1752  auto actions = detail::processEvent(state_, std::move(hrr));
1753  expectError<FizzException>(
1754  actions, AlertDescription::handshake_failure, "unsupported cipher");
1755 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CipherSuite
Definition: Types.h:153
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestBadGroup   
)

Definition at line 1757 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::handshake_failure, fizz::test::TestMessages::helloRetryRequest(), fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), and fizz::HelloRetryRequestKeyShare::selected_group.

1757  {
1758  setupExpectingServerHello();
1759  auto hrr = TestMessages::helloRetryRequest();
1760  TestMessages::removeExtension(hrr, ExtensionType::key_share);
1761  HelloRetryRequestKeyShare keyShare;
1762  keyShare.selected_group = static_cast<NamedGroup>(0x8923);
1763  hrr.extensions.push_back(encodeExtension(std::move(keyShare)));
1764  auto actions = detail::processEvent(state_, std::move(hrr));
1765  expectError<FizzException>(
1766  actions, AlertDescription::handshake_failure, "unsupported group");
1767 }
NamedGroup
Definition: Types.h:302
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestGroupAlreadySent   
)

Definition at line 1769 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::alert, fizz::encodeExtension(), EXPECT_EQ, fizz::test::TestMessages::helloRetryRequest(), fizz::illegal_parameter, fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), fizz::HelloRetryRequestKeyShare::selected_group, fizz::detail::write(), and fizz::x25519.

1769  {
1770  setupExpectingServerHello();
1771  auto hrr = TestMessages::helloRetryRequest();
1772  TestMessages::removeExtension(hrr, ExtensionType::key_share);
1773  HelloRetryRequestKeyShare keyShare;
1774  keyShare.selected_group = NamedGroup::x25519;
1775  hrr.extensions.push_back(encodeExtension(std::move(keyShare)));
1776  auto encryptionLevel = state_.writeRecordLayer()->getEncryptionLevel();
1777  auto actions = detail::processEvent(state_, std::move(hrr));
1778  expectError<FizzException>(
1779  actions, AlertDescription::illegal_parameter, "already-sent group");
1780  auto write = expectAction<WriteToSocket>(actions);
1781  EXPECT_EQ(write.contents[0].encryptionLevel, encryptionLevel);
1782  EXPECT_EQ(write.contents[0].contentType, ContentType::alert);
1783 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestNoKeyShare   
)

Definition at line 1785 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, EXPECT_FALSE, fizz::test::TestMessages::helloRetryRequest(), fizz::key_share, folly::gen::move, fizz::client::detail::processEvent(), fizz::test::TestMessages::removeExtension(), fizz::secp256r1, and fizz::x25519.

1785  {
1786  setupExpectingServerHello();
1787  auto kex = state_.keyExchangers()->at(NamedGroup::x25519).get();
1788  auto mockKex = std::make_unique<MockKeyExchange>();
1789  mockKex->setDefaults();
1790  state_.keyExchangers()->emplace(NamedGroup::secp256r1, std::move(mockKex));
1791  auto hrr = TestMessages::helloRetryRequest();
1792  TestMessages::removeExtension(hrr, ExtensionType::key_share);
1793  auto actions = detail::processEvent(state_, std::move(hrr));
1794  expectActions<MutateState, WriteToSocket>(actions);
1795  processStateMutations(actions);
1796  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1797  EXPECT_FALSE(state_.group().hasValue());
1798  EXPECT_EQ(state_.keyExchangers()->size(), 2);
1799  EXPECT_EQ(state_.keyExchangers()->at(NamedGroup::x25519).get(), kex);
1800 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestCookie   
)

Definition at line 1802 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), cookie, fizz::Cookie::cookie, folly::IOBuf::copyBuffer(), fizz::encodeExtension(), EXPECT_EQ, EXPECT_THAT, testing::HasSubstr(), fizz::test::TestMessages::helloRetryRequest(), folly::gen::move, fizz::client::detail::processEvent(), folly::gen::range(), and string.

1802  {
1803  setupExpectingServerHello();
1804  auto hrr = TestMessages::helloRetryRequest();
1805  Cookie cookie;
1806  cookie.cookie = folly::IOBuf::copyBuffer("cookie!!");
1807  hrr.extensions.push_back(encodeExtension(std::move(cookie)));
1808  auto actions = detail::processEvent(state_, std::move(hrr));
1809  expectActions<MutateState, WriteToSocket>(actions);
1810  processStateMutations(actions);
1811  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1812  auto range = (*state_.encodedClientHello())->coalesce();
1813  EXPECT_THAT(std::string(range.begin(), range.end()), HasSubstr("cookie!!"));
1814 }
StringPiece cookie
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Gen range(Value begin, Value end)
Definition: Base.h:467
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_THAT(value, matcher)
const char * string
Definition: Conv.cpp:212
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestAttemptedEarly   
)

Definition at line 1816 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, EXPECT_EQ, fizz::test::TestMessages::helloRetryRequest(), fizz::client::detail::processEvent(), and fizz::Rejected.

1816  {
1817  setupExpectingServerHello();
1818  state_.earlyDataType() = EarlyDataType::Attempted;
1819  auto actions =
1820  detail::processEvent(state_, TestMessages::helloRetryRequest());
1821  expectActions<MutateState, WriteToSocket>(actions);
1822  processStateMutations(actions);
1823  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1824  EXPECT_EQ(state_.earlyDataType(), EarlyDataType::Rejected);
1825  EXPECT_EQ(state_.earlyWriteRecordLayer(), nullptr);
1826 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestHelloRetryRequestCompat   
)

Definition at line 1828 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::change_cipher_spec, EXPECT_EQ, EXPECT_TRUE, fizz::handshake, fizz::test::TestMessages::helloRetryRequest(), fizz::Plaintext, fizz::client::detail::processEvent(), and fizz::detail::write().

1828  {
1829  context_->setCompatibilityMode(true);
1830  setupExpectingServerHello();
1831  auto actions =
1832  detail::processEvent(state_, TestMessages::helloRetryRequest());
1833  expectActions<MutateState, WriteToSocket>(actions);
1834  processStateMutations(actions);
1835  auto write = expectAction<WriteToSocket>(actions);
1836  EXPECT_EQ(write.contents.size(), 2);
1837  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::Plaintext);
1838  EXPECT_EQ(write.contents[0].contentType, ContentType::change_cipher_spec);
1839  EXPECT_EQ(write.contents[1].encryptionLevel, EncryptionLevel::Plaintext);
1840  EXPECT_EQ(write.contents[1].contentType, ContentType::handshake);
1841  EXPECT_EQ(state_.state(), StateEnum::ExpectingServerHello);
1842  EXPECT_TRUE(state_.sentCCS());
1843 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsFlow   
)

Definition at line 1845 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_CALL, EXPECT_EQ, and fizz::client::detail::processEvent().

1845  {
1846  context_->setSupportedAlpns({"h2"});
1847  setupExpectingEncryptedExtensions();
1848  EXPECT_CALL(
1849  *mockHandshakeContext_, appendToTranscript(BufMatches("eeencoding")));
1850 
1851  auto actions = detail::processEvent(state_, TestMessages::encryptedExt());
1852  expectActions<MutateState>(actions);
1853  processStateMutations(actions);
1854  EXPECT_EQ(*state_.alpn(), "h2");
1855  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1856 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsPsk   
)

Definition at line 1858 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_CALL, EXPECT_EQ, and fizz::client::detail::processEvent().

1858  {
1859  context_->setSupportedAlpns({"h2"});
1860  setupExpectingEncryptedExtensions();
1861  state_.serverCert() = mockLeaf_;
1862  EXPECT_CALL(
1863  *mockHandshakeContext_, appendToTranscript(BufMatches("eeencoding")));
1864 
1865  auto actions = detail::processEvent(state_, TestMessages::encryptedExt());
1866  expectActions<MutateState>(actions);
1867  processStateMutations(actions);
1868  EXPECT_EQ(*state_.alpn(), "h2");
1869  EXPECT_EQ(state_.state(), StateEnum::ExpectingFinished);
1870  EXPECT_EQ(state_.serverCert(), mockLeaf_);
1871 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsAlpn   
)

Definition at line 1873 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_EQ, and fizz::client::detail::processEvent().

1873  {
1874  context_->setSupportedAlpns({"h2"});
1875  setupExpectingEncryptedExtensions();
1876  auto actions = detail::processEvent(state_, TestMessages::encryptedExt());
1877  expectActions<MutateState>(actions);
1878  processStateMutations(actions);
1879  EXPECT_EQ(*state_.alpn(), "h2");
1880  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1881 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEmptyAlpn   
)

Definition at line 1883 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_layer_protocol_negotiation, fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, folly::gen::move, fizz::client::detail::processEvent(), and fizz::test::TestMessages::removeExtension().

1883  {
1884  context_->setSupportedAlpns({"h2"});
1885  setupExpectingEncryptedExtensions();
1886  auto ee = TestMessages::encryptedExt();
1887  TestMessages::removeExtension(
1888  ee, ExtensionType::application_layer_protocol_negotiation);
1889  ee.extensions.push_back(encodeExtension(ProtocolNameList()));
1890  auto actions = detail::processEvent(state_, std::move(ee));
1891  expectError<FizzException>(
1892  actions, AlertDescription::illegal_parameter, "alpn list");
1893 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsAlpnMismatch   
)

Definition at line 1895 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, and fizz::client::detail::processEvent().

1895  {
1896  context_->setSupportedAlpns({"h3", "h1"});
1897  setupExpectingEncryptedExtensions();
1898  auto actions = detail::processEvent(state_, TestMessages::encryptedExt());
1899  expectError<FizzException>(
1900  actions, AlertDescription::illegal_parameter, "alpn mismatch");
1901 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsNoAlpn   
)

Definition at line 1903 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_layer_protocol_negotiation, fizz::test::TestMessages::encryptedExt(), EXPECT_EQ, EXPECT_FALSE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::test::TestMessages::removeExtension().

1903  {
1904  context_->setSupportedAlpns({"h2"});
1905  setupExpectingEncryptedExtensions();
1906  auto ee = TestMessages::encryptedExt();
1907  TestMessages::removeExtension(
1908  ee, ExtensionType::application_layer_protocol_negotiation);
1909  auto actions = detail::processEvent(state_, std::move(ee));
1910  expectActions<MutateState>(actions);
1911  processStateMutations(actions);
1912  EXPECT_FALSE(state_.alpn().hasValue());
1913  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1914 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsDisallowedExtension   
)

Definition at line 1916 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, folly::gen::move, and fizz::client::detail::processEvent().

1916  {
1917  setupExpectingEncryptedExtensions();
1918  auto ee = TestMessages::encryptedExt();
1919  ee.extensions.push_back(encodeExtension(ClientPresharedKey()));
1920  auto actions = detail::processEvent(state_, std::move(ee));
1921  expectError<FizzException>(
1922  actions,
1923  AlertDescription::illegal_parameter,
1924  "unexpected extension in ee: pre_shared_key");
1925 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsUnrequestedExtension   
)

Definition at line 1927 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_layer_protocol_negotiation, fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, fizz::key_share, folly::gen::move, fizz::pre_shared_key, and fizz::client::detail::processEvent().

1927  {
1928  setupExpectingEncryptedExtensions();
1929  state_.requestedExtensions() = std::vector<ExtensionType>(
1930  {ExtensionType::key_share,
1931  ExtensionType::application_layer_protocol_negotiation,
1932  ExtensionType::pre_shared_key});
1933  auto ee = TestMessages::encryptedExt();
1934  ee.extensions.push_back(encodeExtension(ServerNameList()));
1935  auto actions = detail::processEvent(state_, std::move(ee));
1936  expectError<FizzException>(
1937  actions,
1938  AlertDescription::illegal_parameter,
1939  "unexpected extension in ee: server_name");
1940 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyAccepted   
)

Definition at line 1942 of file ClientProtocolTest.cpp.

References fizz::Accepted, fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), EXPECT_EQ, folly::gen::move, and fizz::client::detail::processEvent().

1942  {
1943  setupExpectingEncryptedExtensionsEarlySent();
1944  auto ee = TestMessages::encryptedExt();
1945  ee.extensions.push_back(encodeExtension(ServerEarlyData()));
1946  auto actions = detail::processEvent(state_, std::move(ee));
1947  expectActions<MutateState>(actions);
1948  processStateMutations(actions);
1949  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1950  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Accepted);
1951 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyRejected   
)

Definition at line 1953 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

1953  {
1954  setupExpectingEncryptedExtensionsEarlySent();
1955  auto ee = TestMessages::encryptedExt();
1956  auto actions = detail::processEvent(state_, std::move(ee));
1957  expectActions<MutateState>(actions);
1958  processStateMutations(actions);
1959  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1960  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Rejected);
1961 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyAlreadyRejected   
)

Definition at line 1963 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::encryptedExt(), EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

1963  {
1964  setupExpectingEncryptedExtensionsEarlySent();
1965  state_.earlyDataType() = EarlyDataType::Rejected;
1966  auto ee = TestMessages::encryptedExt();
1967  auto actions = detail::processEvent(state_, std::move(ee));
1968  expectActions<MutateState>(actions);
1969  processStateMutations(actions);
1970  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificate);
1971  EXPECT_EQ(*state_.earlyDataType(), EarlyDataType::Rejected);
1972 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyAcceptedHrr   
)

Definition at line 1974 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

1974  {
1975  setupExpectingEncryptedExtensionsEarlySent();
1976  state_.earlyDataType() = EarlyDataType::Rejected;
1977  auto ee = TestMessages::encryptedExt();
1978  ee.extensions.push_back(encodeExtension(ServerEarlyData()));
1979  auto actions = detail::processEvent(state_, std::move(ee));
1980  expectError<FizzException>(
1981  actions,
1982  AlertDescription::illegal_parameter,
1983  "unexpected accepted early data");
1984 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyCipherMismatch   
)

Definition at line 1986 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, folly::gen::move, fizz::client::detail::processEvent(), and fizz::TLS_CHACHA20_POLY1305_SHA256.

1986  {
1987  setupExpectingEncryptedExtensionsEarlySent();
1988  state_.cipher() = CipherSuite::TLS_CHACHA20_POLY1305_SHA256;
1989  auto ee = TestMessages::encryptedExt();
1990  ee.extensions.push_back(encodeExtension(ServerEarlyData()));
1991  auto actions = detail::processEvent(state_, std::move(ee));
1992  expectError<FizzException>(
1993  actions, AlertDescription::illegal_parameter, "different cipher");
1994 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEncryptedExtensionsEarlyAlpnMismatch   
)

Definition at line 1996 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::encodeExtension(), fizz::test::TestMessages::encryptedExt(), fizz::illegal_parameter, folly::gen::move, and fizz::client::detail::processEvent().

1996  {
1997  setupExpectingEncryptedExtensionsEarlySent();
1998  state_.earlyDataParams()->alpn = "h3";
1999  state_.attemptedPsk()->alpn = "h3";
2000  auto ee = TestMessages::encryptedExt();
2001  ee.extensions.push_back(encodeExtension(ServerEarlyData()));
2002  auto actions = detail::processEvent(state_, std::move(ee));
2003  expectError<FizzException>(
2004  actions, AlertDescription::illegal_parameter, "different alpn");
2005 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateFlow   
)

Definition at line 2007 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), and testing::Return().

2007  {
2008  setupExpectingCertificate();
2009  EXPECT_CALL(
2010  *mockHandshakeContext_, appendToTranscript(BufMatches("certencoding")));
2011  mockLeaf_ = std::make_shared<MockPeerCert>();
2012  mockIntermediate_ = std::make_shared<MockPeerCert>();
2013  EXPECT_CALL(*factory_, _makePeerCert(BufMatches("cert1")))
2014  .WillOnce(Return(mockLeaf_));
2015  EXPECT_CALL(*factory_, _makePeerCert(BufMatches("cert2")))
2016  .WillOnce(Return(mockIntermediate_));
2017 
2018  auto certificate = TestMessages::certificate();
2019  CertificateEntry entry1;
2020  entry1.cert_data = folly::IOBuf::copyBuffer("cert1");
2021  certificate.certificate_list.push_back(std::move(entry1));
2022  CertificateEntry entry2;
2023  entry2.cert_data = folly::IOBuf::copyBuffer("cert2");
2024  certificate.certificate_list.push_back(std::move(entry2));
2025  auto actions = detail::processEvent(state_, std::move(certificate));
2026 
2027  expectActions<MutateState>(actions);
2028  processStateMutations(actions);
2029  EXPECT_EQ(state_.unverifiedCertChain()->size(), 2);
2030  EXPECT_EQ(state_.unverifiedCertChain()->at(0), mockLeaf_);
2031  EXPECT_EQ(state_.unverifiedCertChain()->at(1), mockIntermediate_);
2032  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificateVerify);
2033 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificate   
)

Definition at line 2035 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), folly::IOBuf::copyBuffer(), EXPECT_EQ, folly::gen::move, and fizz::client::detail::processEvent().

2035  {
2036  setupExpectingCertificate();
2037  auto certificate = TestMessages::certificate();
2038  CertificateEntry entry;
2039  entry.cert_data = folly::IOBuf::copyBuffer("cert");
2040  certificate.certificate_list.push_back(std::move(entry));
2041  auto actions = detail::processEvent(state_, std::move(certificate));
2042  expectActions<MutateState>(actions);
2043  processStateMutations(actions);
2044  EXPECT_EQ(state_.unverifiedCertChain()->size(), 1);
2045  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificateVerify);
2046 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateWithRequestContext   
)

Definition at line 2048 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), folly::IOBuf::copyBuffer(), fizz::illegal_parameter, folly::gen::move, and fizz::client::detail::processEvent().

2048  {
2049  setupExpectingCertificate();
2050  auto certificate = TestMessages::certificate();
2051  certificate.certificate_request_context = IOBuf::copyBuffer("something");
2052  CertificateEntry entry;
2053  entry.cert_data = folly::IOBuf::copyBuffer("cert");
2054  certificate.certificate_list.push_back(std::move(entry));
2055  auto actions = detail::processEvent(state_, std::move(certificate));
2056  expectError<FizzException>(
2057  actions, AlertDescription::illegal_parameter, "context must be empty");
2058 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateEmpty   
)

Definition at line 2060 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::certificate, fizz::test::TestMessages::certificate(), fizz::illegal_parameter, folly::gen::move, and fizz::client::detail::processEvent().

2060  {
2061  setupExpectingCertificate();
2062  auto certificate = TestMessages::certificate();
2063  auto actions = detail::processEvent(state_, std::move(certificate));
2064  expectError<FizzException>(
2065  actions, AlertDescription::illegal_parameter, "no cert");
2066 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificateFlow   
)

Definition at line 2068 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::CompressedCertificate::algorithm, cc, fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), fizz::CompressedCertificate::compressed_certificate_message, fizz::test::TestMessages::compressedCertificate(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), testing::Return(), fizz::CompressedCertificate::uncompressed_length, and fizz::zlib.

2068  {
2069  setupExpectingCertificate();
2070  EXPECT_CALL(
2071  *mockHandshakeContext_,
2072  appendToTranscript(BufMatches("compcertencoding")));
2073  mockLeaf_ = std::make_shared<MockPeerCert>();
2074  mockIntermediate_ = std::make_shared<MockPeerCert>();
2075  EXPECT_CALL(*factory_, _makePeerCert(BufMatches("cert1")))
2076  .WillOnce(Return(mockLeaf_));
2077  EXPECT_CALL(*factory_, _makePeerCert(BufMatches("cert2")))
2078  .WillOnce(Return(mockIntermediate_));
2079 
2080  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2081  decompressor->setDefaults();
2082  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2083  decompressionMgr->setDecompressors(
2084  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2085  context_->setCertDecompressionManager(std::move(decompressionMgr));
2086  EXPECT_CALL(*decompressor, decompress(_))
2087  .WillOnce(Invoke([](const CompressedCertificate& cc) {
2089  cc.compressed_certificate_message,
2090  folly::IOBuf::copyBuffer("compressedcerts")));
2091  EXPECT_EQ(cc.algorithm, CertificateCompressionAlgorithm::zlib);
2092  EXPECT_EQ(cc.uncompressed_length, 0x111111);
2093  auto certificate = TestMessages::certificate();
2094  CertificateEntry entry1;
2095  entry1.cert_data = folly::IOBuf::copyBuffer("cert1");
2096  certificate.certificate_list.push_back(std::move(entry1));
2097  CertificateEntry entry2;
2098  entry2.cert_data = folly::IOBuf::copyBuffer("cert2");
2099  certificate.certificate_list.push_back(std::move(entry2));
2100  return certificate;
2101  }));
2102 
2103  auto compressedCert = TestMessages::compressedCertificate();
2104  auto actions = detail::processEvent(state_, std::move(compressedCert));
2105 
2106  expectActions<MutateState>(actions);
2107  processStateMutations(actions);
2108  EXPECT_EQ(state_.unverifiedCertChain()->size(), 2);
2109  EXPECT_EQ(state_.unverifiedCertChain()->at(0), mockLeaf_);
2110  EXPECT_EQ(state_.unverifiedCertChain()->at(1), mockIntermediate_);
2111  EXPECT_EQ(state_.serverCertCompAlgo(), CertificateCompressionAlgorithm::zlib);
2112  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificateVerify);
2113 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
The non test part of the code is expected to have failures gtest_output_test_ cc
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificate   
)

Definition at line 2115 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), cc, fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), fizz::test::TestMessages::compressedCertificate(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), and fizz::zlib.

2115  {
2116  setupExpectingCertificate();
2117  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2118  decompressor->setDefaults();
2119  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2120  decompressionMgr->setDecompressors(
2121  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2122  context_->setCertDecompressionManager(std::move(decompressionMgr));
2123  EXPECT_CALL(*decompressor, decompress(_))
2124  .WillOnce(Invoke([](const CompressedCertificate& cc) {
2125  auto certificate = TestMessages::certificate();
2126  CertificateEntry entry;
2127  entry.cert_data = folly::IOBuf::copyBuffer("cert");
2128  certificate.certificate_list.push_back(std::move(entry));
2129  return certificate;
2130  }));
2131 
2132  auto compressedCert = TestMessages::compressedCertificate();
2133  auto actions = detail::processEvent(state_, std::move(compressedCert));
2134  expectActions<MutateState>(actions);
2135  processStateMutations(actions);
2136  EXPECT_EQ(state_.unverifiedCertChain()->size(), 1);
2137  EXPECT_EQ(state_.serverCertCompAlgo(), CertificateCompressionAlgorithm::zlib);
2138  EXPECT_EQ(state_.state(), StateEnum::ExpectingCertificateVerify);
2139 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
The non test part of the code is expected to have failures gtest_output_test_ cc
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificateUnknownAlgo   
)

Definition at line 2141 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::bad_certificate, fizz::test::TestMessages::compressedCertificate(), folly::gen::move, and fizz::client::detail::processEvent().

2141  {
2142  setupExpectingCertificate();
2143  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2144  decompressor->setDefaults();
2145  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2146  decompressionMgr->setDecompressors(
2147  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2148  context_->setCertDecompressionManager(std::move(decompressionMgr));
2149 
2150  auto compressedCert = TestMessages::compressedCertificate();
2151  compressedCert.algorithm = static_cast<CertificateCompressionAlgorithm>(0xff);
2152  auto actions = detail::processEvent(state_, std::move(compressedCert));
2153  expectError<FizzException>(
2154  actions, AlertDescription::bad_certificate, "unsupported algorithm");
2155 }
CertificateCompressionAlgorithm
Definition: Types.h:167
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificateDecompressionFailed   
)

Definition at line 2157 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::bad_certificate, cc, fizz::test::TestMessages::compressedCertificate(), EXPECT_CALL, testing::Invoke(), folly::gen::move, and fizz::client::detail::processEvent().

2157  {
2158  setupExpectingCertificate();
2159  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2160  decompressor->setDefaults();
2161  EXPECT_CALL(*decompressor, decompress(_))
2162  .WillOnce(Invoke([](const CompressedCertificate& cc) -> CertificateMsg {
2163  throw std::runtime_error("foo");
2164  }));
2165  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2166  decompressionMgr->setDecompressors(
2167  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2168  context_->setCertDecompressionManager(std::move(decompressionMgr));
2169  auto compressedCert = TestMessages::compressedCertificate();
2170  auto actions = detail::processEvent(state_, std::move(compressedCert));
2171  expectError<FizzException>(
2172  actions, AlertDescription::bad_certificate, "decompression failed: foo");
2173 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
The non test part of the code is expected to have failures gtest_output_test_ cc
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificateWithRequestContext   
)

Definition at line 2175 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), cc, fizz::CertificateEntry::cert_data, fizz::certificate, fizz::test::TestMessages::certificate(), fizz::test::TestMessages::compressedCertificate(), folly::IOBuf::copyBuffer(), EXPECT_CALL, fizz::illegal_parameter, testing::Invoke(), folly::gen::move, and fizz::client::detail::processEvent().

2175  {
2176  setupExpectingCertificate();
2177  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2178  decompressor->setDefaults();
2179  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2180  decompressionMgr->setDecompressors(
2181  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2182  context_->setCertDecompressionManager(std::move(decompressionMgr));
2183  EXPECT_CALL(*decompressor, decompress(_))
2184  .WillOnce(Invoke([](const CompressedCertificate& cc) {
2185  auto certificate = TestMessages::certificate();
2186  certificate.certificate_request_context =
2187  IOBuf::copyBuffer("something");
2188  CertificateEntry entry;
2189  entry.cert_data = folly::IOBuf::copyBuffer("cert");
2190  certificate.certificate_list.push_back(std::move(entry));
2191  return certificate;
2192  }));
2193 
2194  auto compressedCert = TestMessages::compressedCertificate();
2195  auto actions = detail::processEvent(state_, std::move(compressedCert));
2196  expectError<FizzException>(
2197  actions, AlertDescription::illegal_parameter, "context must be empty");
2198 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
The non test part of the code is expected to have failures gtest_output_test_ cc
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCompressedCertificateEmpty   
)

Definition at line 2200 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), cc, fizz::test::TestMessages::certificate(), fizz::test::TestMessages::compressedCertificate(), EXPECT_CALL, fizz::illegal_parameter, testing::Invoke(), folly::gen::move, and fizz::client::detail::processEvent().

2200  {
2201  setupExpectingCertificate();
2202  auto decompressor = std::make_shared<MockCertificateDecompressor>();
2203  decompressor->setDefaults();
2204  EXPECT_CALL(*decompressor, decompress(_))
2205  .WillOnce(Invoke([](const CompressedCertificate& cc) {
2206  return TestMessages::certificate();
2207  }));
2208  auto decompressionMgr = std::make_shared<CertDecompressionManager>();
2209  decompressionMgr->setDecompressors(
2210  {std::static_pointer_cast<CertificateDecompressor>(decompressor)});
2211  context_->setCertDecompressionManager(std::move(decompressionMgr));
2212  auto compressedCert = TestMessages::compressedCertificate();
2213  auto actions = detail::processEvent(state_, std::move(compressedCert));
2214  expectError<FizzException>(
2215  actions, AlertDescription::illegal_parameter, "no cert");
2216 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
The non test part of the code is expected to have failures gtest_output_test_ cc
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestUnexpectedCompressedCertificate   
)

Definition at line 2218 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::compressedCertificate(), folly::gen::move, fizz::client::detail::processEvent(), and fizz::unexpected_message.

2218  {
2219  setupExpectingCertificate();
2220  auto compressedCert = TestMessages::compressedCertificate();
2221  auto actions = detail::processEvent(state_, std::move(compressedCert));
2222  expectError<FizzException>(
2223  actions, AlertDescription::unexpected_message, "received unexpectedly");
2224 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyFlow   
)

Definition at line 2226 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::test::TestMessages::certificateVerify(), folly::IOBuf::copyBuffer(), fizz::ecdsa_secp256r1_sha256, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, testing::Invoke(), fizz::client::detail::processEvent(), fizz::Server, verifier_, and verify().

2226  {
2227  setupExpectingCertificateVerify();
2228  Sequence contextSeq;
2229  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
2230  .InSequence(contextSeq)
2231  .WillRepeatedly(
2232  Invoke([]() { return IOBuf::copyBuffer("certcontext"); }));
2233  EXPECT_CALL(
2234  *mockHandshakeContext_,
2235  appendToTranscript(BufMatches("certverifyencoding")))
2236  .InSequence(contextSeq);
2237  EXPECT_CALL(
2238  *mockLeaf_,
2239  verify(
2240  SignatureScheme::ecdsa_secp256r1_sha256,
2241  CertificateVerifyContext::Server,
2242  RangeMatches("certcontext"),
2243  RangeMatches("signature")));
2245  .WillOnce(Invoke(
2246  [this](const std::vector<std::shared_ptr<const PeerCert>>& certs) {
2247  EXPECT_EQ(certs.size(), 2);
2248  EXPECT_EQ(certs[0], mockLeaf_);
2249  EXPECT_EQ(certs[1], mockIntermediate_);
2250  }));
2251 
2252  auto actions =
2253  detail::processEvent(state_, TestMessages::certificateVerify());
2254  expectActions<MutateState>(actions);
2255  processStateMutations(actions);
2256  EXPECT_EQ(state_.sigScheme(), SignatureScheme::ecdsa_secp256r1_sha256);
2257  EXPECT_EQ(state_.serverCert(), mockLeaf_);
2258  EXPECT_FALSE(state_.unverifiedCertChain().hasValue());
2259  EXPECT_EQ(state_.state(), StateEnum::ExpectingFinished);
2260 }
void verify(int extras)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerify   
)

Definition at line 2262 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateVerify(), EXPECT_EQ, and fizz::client::detail::processEvent().

2262  {
2263  setupExpectingCertificateVerify();
2264  auto actions =
2265  detail::processEvent(state_, TestMessages::certificateVerify());
2266  expectActions<MutateState>(actions);
2267  processStateMutations(actions);
2268  EXPECT_EQ(state_.state(), StateEnum::ExpectingFinished);
2269 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyNoVerifier   
)

Definition at line 2271 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateVerify(), EXPECT_EQ, and fizz::client::detail::processEvent().

2271  {
2272  setupExpectingCertificateVerify();
2273  state_.verifier() = nullptr;
2274  auto actions =
2275  detail::processEvent(state_, TestMessages::certificateVerify());
2276  expectActions<MutateState>(actions);
2277  processStateMutations(actions);
2278  EXPECT_EQ(state_.state(), StateEnum::ExpectingFinished);
2279 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyUnsupportedAlgorithm   
)

Definition at line 2281 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateVerify(), fizz::illegal_parameter, fizz::client::detail::processEvent(), and fizz::rsa_pss_sha256.

2281  {
2282  context_->setSupportedSigSchemes({SignatureScheme::rsa_pss_sha256});
2283  setupExpectingCertificateVerify();
2284  auto actions =
2285  detail::processEvent(state_, TestMessages::certificateVerify());
2286  expectError<FizzException>(
2287  actions, AlertDescription::illegal_parameter, "unsupported sig scheme");
2288 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyFailure   
)

Definition at line 2290 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::bad_record_mac, fizz::test::TestMessages::certificateVerify(), fizz::ecdsa_secp256r1_sha256, EXPECT_CALL, fizz::client::detail::processEvent(), fizz::Server, and verify().

2290  {
2291  setupExpectingCertificateVerify();
2292  EXPECT_CALL(
2293  *mockLeaf_,
2294  verify(
2295  SignatureScheme::ecdsa_secp256r1_sha256,
2296  CertificateVerifyContext::Server,
2297  RangeMatches("context"),
2298  RangeMatches("signature")))
2299  .WillOnce(Throw(
2300  FizzException("verify failed", AlertDescription::bad_record_mac)));
2301  auto actions =
2302  detail::processEvent(state_, TestMessages::certificateVerify());
2303  expectError<FizzException>(
2304  actions, AlertDescription::bad_record_mac, "verify failed");
2305 }
void verify(int extras)
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyVerifierFailure   
)

Definition at line 2307 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::bad_record_mac, fizz::test::TestMessages::certificateVerify(), EXPECT_CALL, fizz::client::detail::processEvent(), verifier_, and verify().

2307  {
2308  setupExpectingCertificateVerify();
2310  .WillOnce(Throw(FizzVerificationException(
2311  "verify failed", AlertDescription::bad_record_mac)));
2312  auto actions =
2313  detail::processEvent(state_, TestMessages::certificateVerify());
2314  expectError<FizzVerificationException>(
2315  actions, AlertDescription::bad_record_mac, "verify failed");
2316 }
void verify(int extras)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateVerifyVerifierFailureOtherException   
)

Definition at line 2318 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::bad_certificate, fizz::test::TestMessages::certificateVerify(), EXPECT_CALL, fizz::client::detail::processEvent(), verifier_, and verify().

2318  {
2319  setupExpectingCertificateVerify();
2321  .WillOnce(Throw(std::runtime_error("no good")));
2322  auto actions =
2323  detail::processEvent(state_, TestMessages::certificateVerify());
2324  expectError<FizzException>(
2325  actions, AlertDescription::bad_certificate, "verifier failure: no good");
2326 }
void verify(int extras)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::shared_ptr< const CertificateVerifier > verifier_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestNoCert   
)

Definition at line 2328 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), EXPECT_EQ, folly::gen::move, folly::none, and fizz::client::detail::processEvent().

2328  {
2329  setupExpectingCertificate();
2330  auto certificateRequest = TestMessages::certificateRequest();
2331  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2332  expectActions<MutateState>(actions);
2333  processStateMutations(actions);
2334  EXPECT_EQ(state_.clientAuthRequested(), ClientAuthType::RequestedNoMatch);
2335  EXPECT_EQ(state_.selectedClientCert(), nullptr);
2336  EXPECT_EQ(state_.clientAuthSigScheme(), folly::none);
2337 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestDuplicated   
)

Definition at line 2339 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), folly::gen::move, fizz::client::detail::processEvent(), and fizz::unexpected_message.

2339  {
2340  setupExpectingCertificate();
2341  auto certificateRequest = TestMessages::certificateRequest();
2342  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2343  expectActions<MutateState>(actions);
2344  processStateMutations(actions);
2345  certificateRequest = TestMessages::certificateRequest();
2346  actions = detail::processEvent(state_, std::move(certificateRequest));
2347  expectError<FizzException>(
2348  actions,
2349  AlertDescription::unexpected_message,
2350  "duplicate certificate request message");
2351 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestAlgosMismatch   
)

Definition at line 2353 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), fizz::ecdsa_secp256r1_sha256, fizz::encodeExtension(), EXPECT_CALL, EXPECT_EQ, folly::gen::move, folly::none, fizz::client::detail::processEvent(), testing::Return(), fizz::rsa_pss_sha256, and fizz::SignatureAlgorithms::supported_signature_algorithms.

2353  {
2354  setupExpectingCertificateRequest();
2355  auto certificateRequest = TestMessages::certificateRequest();
2356 
2357  SignatureAlgorithms sigAlgs;
2358  sigAlgs.supported_signature_algorithms = {
2359  SignatureScheme::ecdsa_secp256r1_sha256};
2360  certificateRequest.extensions.clear();
2361  certificateRequest.extensions.emplace_back(
2362  encodeExtension(std::move(sigAlgs)));
2363 
2364  EXPECT_CALL(*mockClientCert_, getSigSchemes())
2365  .WillOnce(Return(
2366  std::vector<SignatureScheme>(1, SignatureScheme::rsa_pss_sha256)));
2367 
2368  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2369  expectActions<MutateState>(actions);
2370  processStateMutations(actions);
2371  EXPECT_EQ(state_.clientAuthRequested(), ClientAuthType::RequestedNoMatch);
2372  EXPECT_EQ(state_.selectedClientCert(), nullptr);
2373  EXPECT_EQ(state_.clientAuthSigScheme(), folly::none);
2374 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestContextAlgosUnsupported   
)

Definition at line 2376 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), fizz::ecdsa_secp256r1_sha256, fizz::encodeExtension(), EXPECT_CALL, EXPECT_EQ, folly::gen::move, folly::none, fizz::client::detail::processEvent(), testing::Return(), fizz::rsa_pss_sha256, fizz::rsa_pss_sha512, and fizz::SignatureAlgorithms::supported_signature_algorithms.

2376  {
2377  setupExpectingCertificateRequest();
2378  context_->setSupportedSigSchemes({SignatureScheme::rsa_pss_sha512});
2379  auto certificateRequest = TestMessages::certificateRequest();
2380 
2381  SignatureAlgorithms sigAlgs;
2382  sigAlgs.supported_signature_algorithms = {
2383  SignatureScheme::ecdsa_secp256r1_sha256, SignatureScheme::rsa_pss_sha256};
2384  certificateRequest.extensions.clear();
2385  certificateRequest.extensions.emplace_back(
2386  encodeExtension(std::move(sigAlgs)));
2387 
2388  EXPECT_CALL(*mockClientCert_, getSigSchemes())
2389  .WillOnce(Return(
2390  std::vector<SignatureScheme>(1, SignatureScheme::rsa_pss_sha256)));
2391 
2392  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2393  expectActions<MutateState>(actions);
2394  processStateMutations(actions);
2395  EXPECT_EQ(state_.clientAuthRequested(), ClientAuthType::RequestedNoMatch);
2396  EXPECT_EQ(state_.selectedClientCert(), nullptr);
2397  EXPECT_EQ(state_.clientAuthSigScheme(), folly::none);
2398 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestPrefersContextOrder   
)

Definition at line 2400 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), fizz::ecdsa_secp521r1_sha512, fizz::ed25519, fizz::encodeExtension(), EXPECT_CALL, EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), testing::Return(), fizz::rsa_pss_sha512, and fizz::SignatureAlgorithms::supported_signature_algorithms.

2400  {
2401  setupExpectingCertificateRequest();
2402  context_->setSupportedSigSchemes({SignatureScheme::rsa_pss_sha512,
2403  SignatureScheme::ecdsa_secp521r1_sha512,
2404  SignatureScheme::ed25519});
2405  auto certificateRequest = TestMessages::certificateRequest();
2406  SignatureAlgorithms requestAlgos;
2407  requestAlgos.supported_signature_algorithms = {
2408  SignatureScheme::ecdsa_secp521r1_sha512,
2409  SignatureScheme::ed25519,
2410  SignatureScheme::rsa_pss_sha512};
2411  certificateRequest.extensions.clear();
2412  certificateRequest.extensions.emplace_back(
2413  encodeExtension(std::move(requestAlgos)));
2414 
2415  EXPECT_CALL(*mockClientCert_, getSigSchemes())
2416  .WillOnce(Return(
2417  std::vector<SignatureScheme>({SignatureScheme::ed25519,
2418  SignatureScheme::ecdsa_secp521r1_sha512,
2419  SignatureScheme::rsa_pss_sha512})));
2420 
2421  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2422  expectActions<MutateState>(actions);
2423  processStateMutations(actions);
2424  EXPECT_EQ(state_.clientAuthRequested(), ClientAuthType::Sent);
2425  EXPECT_EQ(state_.selectedClientCert(), mockClientCert_);
2426  EXPECT_EQ(state_.clientAuthSigScheme(), SignatureScheme::rsa_pss_sha512);
2427 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestCertificateRequestMatch   
)

Definition at line 2429 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::certificateRequest(), EXPECT_CALL, EXPECT_EQ, folly::gen::move, fizz::client::detail::processEvent(), testing::Return(), and fizz::rsa_pss_sha256.

2429  {
2430  setupExpectingCertificateRequest();
2431  auto certificateRequest = TestMessages::certificateRequest();
2432 
2433  EXPECT_CALL(*mockClientCert_, getSigSchemes())
2434  .WillOnce(Return(
2435  std::vector<SignatureScheme>(1, SignatureScheme::rsa_pss_sha256)));
2436 
2437  auto actions = detail::processEvent(state_, std::move(certificateRequest));
2438  expectActions<MutateState>(actions);
2439  processStateMutations(actions);
2440  EXPECT_EQ(state_.clientAuthRequested(), ClientAuthType::Sent);
2441  EXPECT_EQ(state_.selectedClientCert(), mockClientCert_);
2442  EXPECT_EQ(state_.clientAuthSigScheme(), SignatureScheme::rsa_pss_sha256);
2443 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedFlow   
)

Definition at line 2445 of file ClientProtocolTest.cpp.

2445  {
2446  setupExpectingFinished();
2447  doFinishedFlow(ClientAuthType::NotRequested);
2448 }
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedCertNoMatchFlow   
)

Definition at line 2450 of file ClientProtocolTest.cpp.

References EXPECT_EQ.

2450  {
2451  setupExpectingFinished();
2452  state_.clientAuthRequested() = ClientAuthType::RequestedNoMatch;
2453  doFinishedFlow(ClientAuthType::RequestedNoMatch);
2454  EXPECT_EQ(state_.clientCert(), nullptr);
2455 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedCertSentFlow   
)

Definition at line 2457 of file ClientProtocolTest.cpp.

References fizz::ecdsa_secp256r1_sha256, and EXPECT_EQ.

2457  {
2458  setupExpectingFinished();
2459  state_.clientAuthRequested() = ClientAuthType::Sent;
2460  state_.clientAuthSigScheme() = SignatureScheme::ecdsa_secp256r1_sha256;
2461  state_.selectedClientCert() = mockClientCert_;
2462  doFinishedFlow(ClientAuthType::Sent);
2463  EXPECT_EQ(state_.clientCert(), mockClientCert_);
2464 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedEarlyFlow   
)

Definition at line 2466 of file ClientProtocolTest.cpp.

References testing::_, fizz::Accepted, fizz::client::detail::actions(), fizz::AppTraffic, fizz::ClientAppTraffic, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::EarlyData, fizz::encodeHandshake(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::ExporterMaster, fizz::test::TestMessages::finished(), fizz::TLSMessage::fragment, fizz::detail::getFinishedData(), fizz::Handshake, fizz::handshake, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::client::detail::processEvent(), fizz::ResumptionMaster, fizz::ServerAppTraffic, fizz::TLSMessage::type, and fizz::detail::write().

2466  {
2467  setupExpectingFinished();
2468  state_.earlyDataType() = EarlyDataType::Accepted;
2469  setMockEarlyRecord();
2470 
2471  Sequence contextSeq;
2472  EXPECT_CALL(*mockHandshakeContext_, getFinishedData(RangeMatches("sht")))
2473  .InSequence(contextSeq)
2474  .WillOnce(
2475  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("verifydata"); }));
2476  EXPECT_CALL(
2477  *mockHandshakeContext_,
2478  appendToTranscript(BufMatches("finishedencoding")))
2479  .InSequence(contextSeq);
2480  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
2481  .InSequence(contextSeq)
2482  .WillRepeatedly(
2483  Invoke([]() { return IOBuf::copyBuffer("sfincontext"); }));
2484  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
2485  .InSequence(contextSeq);
2486  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
2487  .InSequence(contextSeq)
2488  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("sfin_eoed"); }));
2489  EXPECT_CALL(*mockHandshakeContext_, getFinishedData(RangeMatches("cht")))
2490  .InSequence(contextSeq)
2491  .WillRepeatedly(
2492  InvokeWithoutArgs([]() { return IOBuf::copyBuffer("verifydata"); }));
2493  EXPECT_CALL(*mockHandshakeContext_, appendToTranscript(_))
2494  .InSequence(contextSeq);
2495  EXPECT_CALL(*mockHandshakeContext_, getHandshakeContext())
2496  .InSequence(contextSeq)
2497  .WillRepeatedly(Invoke([]() { return IOBuf::copyBuffer("fincontext"); }));
2498  EXPECT_CALL(*mockHandshakeWrite_, _write(_))
2499  .WillOnce(Invoke([&](TLSMessage& msg) {
2500  TLSContent content;
2501  content.contentType = msg.type;
2502  content.encryptionLevel = mockHandshakeWrite_->getEncryptionLevel();
2503  EXPECT_EQ(msg.type, ContentType::handshake);
2505  msg.fragment, encodeHandshake(TestMessages::finished())));
2506  content.data = folly::IOBuf::copyBuffer("finwrite");
2507  return content;
2508  }));
2509  EXPECT_CALL(*mockEarlyWrite_, _write(_))
2510  .WillOnce(Invoke([&](TLSMessage& msg) {
2511  TLSContent content;
2512  content.contentType = msg.type;
2513  content.encryptionLevel = mockEarlyWrite_->getEncryptionLevel();
2514  EXPECT_EQ(msg.type, ContentType::handshake);
2515  EXPECT_TRUE(
2516  IOBufEqualTo()(msg.fragment, encodeHandshake(EndOfEarlyData())));
2517  content.data = folly::IOBuf::copyBuffer("eoed");
2518  return content;
2519  }));
2520  EXPECT_CALL(*mockKeyScheduler_, deriveMasterSecret());
2521  EXPECT_CALL(
2522  *mockKeyScheduler_,
2523  getSecret(MasterSecrets::ExporterMaster, RangeMatches("sfincontext")));
2524  EXPECT_CALL(
2525  *mockKeyScheduler_,
2526  getSecret(MasterSecrets::ResumptionMaster, RangeMatches("fincontext")))
2527  .WillOnce(InvokeWithoutArgs([]() {
2528  return std::vector<uint8_t>({'r', 'e', 's'});
2529  }));
2530  EXPECT_CALL(
2531  *mockKeyScheduler_, deriveAppTrafficSecrets(RangeMatches("sfincontext")));
2532  EXPECT_CALL(
2533  *mockKeyScheduler_, getSecret(AppTrafficSecrets::ServerAppTraffic))
2534  .WillOnce(InvokeWithoutArgs([]() {
2535  return std::vector<uint8_t>({'s', 'a', 't'});
2536  }));
2537  EXPECT_CALL(
2538  *mockKeyScheduler_, getSecret(AppTrafficSecrets::ClientAppTraffic))
2539  .WillOnce(InvokeWithoutArgs([]() {
2540  return std::vector<uint8_t>({'c', 'a', 't'});
2541  }));
2542  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sat"), _, _))
2543  .WillOnce(InvokeWithoutArgs([]() {
2544  return TrafficKey{IOBuf::copyBuffer("serverkey"),
2545  IOBuf::copyBuffer("serveriv")};
2546  }));
2547  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cat"), _, _))
2548  .WillOnce(InvokeWithoutArgs([]() {
2549  return TrafficKey{IOBuf::copyBuffer("clientkey"),
2550  IOBuf::copyBuffer("clientiv")};
2551  }));
2552  MockAead* raead;
2553  MockAead* waead;
2554  MockEncryptedReadRecordLayer* rrl;
2555  MockEncryptedWriteRecordLayer* wrl;
2556  expectAeadCreation(&waead, &raead);
2557  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sat"));
2558  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cat"));
2559  EXPECT_CALL(*mockKeyScheduler_, clearMasterSecret());
2560 
2561  auto actions = detail::processEvent(state_, TestMessages::finished());
2562  expectActions<MutateState, ReportHandshakeSuccess, WriteToSocket>(actions);
2563  auto write = expectAction<WriteToSocket>(actions);
2564  EXPECT_EQ(write.contents.size(), 2);
2565  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::EarlyData);
2566  EXPECT_EQ(write.contents[0].contentType, ContentType::handshake);
2567  EXPECT_TRUE(
2568  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("eoed")));
2569 
2570  EXPECT_EQ(write.contents[1].encryptionLevel, EncryptionLevel::Handshake);
2571  EXPECT_EQ(write.contents[1].contentType, ContentType::handshake);
2572  EXPECT_TRUE(
2573  IOBufEqualTo()(write.contents[1].data, IOBuf::copyBuffer("finwrite")));
2574  auto reportSuccess = expectAction<ReportHandshakeSuccess>(actions);
2575  EXPECT_EQ(reportSuccess.earlyDataAccepted, true);
2576  processStateMutations(actions);
2577  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
2578  EXPECT_EQ(
2579  state_.readRecordLayer()->getEncryptionLevel(),
2580  EncryptionLevel::AppTraffic);
2581  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
2582  EXPECT_EQ(
2583  state_.writeRecordLayer()->getEncryptionLevel(),
2584  EncryptionLevel::AppTraffic);
2585  EXPECT_EQ(state_.earlyWriteRecordLayer().get(), nullptr);
2586  EXPECT_EQ(state_.state(), StateEnum::Established);
2587  EXPECT_TRUE(
2588  IOBufEqualTo()(*state_.resumptionSecret(), IOBuf::copyBuffer("res")));
2589 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Buf getFinishedData(std::unique_ptr< KeyDerivation > &deriver, Buf &finishedMacKey, const Buf &finishedTranscript)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinished   
)

Definition at line 2752 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::test::TestMessages::finished(), and fizz::client::detail::processEvent().

2752  {
2753  setupExpectingFinished();
2754  auto actions = detail::processEvent(state_, TestMessages::finished());
2755  expectActions<MutateState, ReportHandshakeSuccess, WriteToSocket>(actions);
2756  processStateMutations(actions);
2757  EXPECT_EQ(state_.state(), StateEnum::Established);
2758 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedExtraData   
)

Definition at line 2760 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_CALL, fizz::test::TestMessages::finished(), fizz::client::detail::processEvent(), testing::Return(), and fizz::unexpected_message.

2760  {
2761  setupExpectingFinished();
2762  EXPECT_CALL(*mockHandshakeRead_, hasUnparsedHandshakeData())
2763  .WillRepeatedly(Return(true));
2764  auto actions = detail::processEvent(state_, TestMessages::finished());
2765  expectError<FizzException>(
2766  actions, AlertDescription::unexpected_message, "data after finished");
2767 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedMismatch   
)

Definition at line 2769 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::bad_record_mac, folly::IOBuf::copyBuffer(), fizz::finished, fizz::test::TestMessages::finished(), folly::gen::move, and fizz::client::detail::processEvent().

2769  {
2770  setupExpectingFinished();
2771  auto finished = TestMessages::finished();
2772  finished.verify_data = IOBuf::copyBuffer("ver1fydata");
2773  auto actions = detail::processEvent(state_, std::move(finished));
2774  expectError<FizzException>(
2775  actions, AlertDescription::bad_record_mac, "finished verify failure");
2776 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedRejectedEarly   
)

Definition at line 2778 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::test::TestMessages::finished(), fizz::client::detail::processEvent(), and fizz::Rejected.

2778  {
2779  setupExpectingFinished();
2780  state_.earlyDataType() = EarlyDataType::Rejected;
2781  auto actions = detail::processEvent(state_, TestMessages::finished());
2782  expectActions<MutateState, ReportHandshakeSuccess, WriteToSocket>(actions);
2783  auto reportSuccess = expectAction<ReportHandshakeSuccess>(actions);
2784  EXPECT_EQ(reportSuccess.earlyDataAccepted, false);
2785  processStateMutations(actions);
2786  EXPECT_EQ(state_.state(), StateEnum::Established);
2787 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestFinishedCompat   
)

Definition at line 2789 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::change_cipher_spec, EXPECT_EQ, EXPECT_TRUE, fizz::test::TestMessages::finished(), fizz::Handshake, fizz::handshake, fizz::Plaintext, fizz::client::detail::processEvent(), and fizz::detail::write().

2789  {
2790  context_->setCompatibilityMode(true);
2791  setupExpectingFinished();
2792  auto actions = detail::processEvent(state_, TestMessages::finished());
2793  expectActions<MutateState, ReportHandshakeSuccess, WriteToSocket>(actions);
2794  auto write = expectAction<WriteToSocket>(actions);
2795  EXPECT_EQ(write.contents.size(), 2);
2796  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::Plaintext);
2797  EXPECT_EQ(write.contents[0].contentType, ContentType::change_cipher_spec);
2798  EXPECT_EQ(write.contents[1].encryptionLevel, EncryptionLevel::Handshake);
2799  EXPECT_EQ(write.contents[1].contentType, ContentType::handshake);
2800  processStateMutations(actions);
2801  EXPECT_EQ(state_.state(), StateEnum::Established);
2802  EXPECT_TRUE(state_.sentCCS());
2803 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestNewSessionTicket   
)

Definition at line 2805 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_EQ, testing::InvokeWithoutArgs(), folly::gen::move, fizz::test::TestMessages::newSessionTicket(), fizz::client::detail::processEvent(), fizz::Resumption, fizz::tls_1_3, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

2805  {
2806  setupAcceptingData();
2807 
2808  EXPECT_CALL(
2809  *mockKeyScheduler_,
2810  getResumptionSecret(RangeMatches("resumptionsecret"), RangeMatches("")))
2811  .WillOnce(InvokeWithoutArgs(
2812  []() { return IOBuf::copyBuffer("derivedsecret"); }));
2813  state_.clientCert() = mockClientCert_;
2814 
2815  auto actions = detail::processEvent(state_, TestMessages::newSessionTicket());
2816  auto newCachedPsk = expectSingleAction<NewCachedPsk>(std::move(actions));
2817  auto psk = newCachedPsk.psk;
2818  EXPECT_EQ(psk.psk, "ticket");
2819  EXPECT_EQ(psk.secret, "derivedsecret");
2820  EXPECT_EQ(psk.type, PskType::Resumption);
2821  EXPECT_EQ(psk.version, ProtocolVersion::tls_1_3);
2822  EXPECT_EQ(psk.cipher, CipherSuite::TLS_AES_128_GCM_SHA256);
2823  EXPECT_EQ(psk.group, NamedGroup::x25519);
2824  EXPECT_EQ(psk.serverCert, mockLeaf_);
2825  EXPECT_EQ(psk.clientCert, mockClientCert_);
2826  EXPECT_EQ(psk.maxEarlyDataSize, 0);
2827  EXPECT_EQ(psk.ticketAgeAdd, 0x44444444);
2828 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestNewSessionTicketNonce   
)

Definition at line 2830 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), EXPECT_CALL, testing::InvokeWithoutArgs(), folly::gen::move, fizz::test::TestMessages::newSessionTicket(), nst, and fizz::client::detail::processEvent().

2830  {
2831  setupAcceptingData();
2832 
2833  EXPECT_CALL(
2834  *mockKeyScheduler_,
2835  getResumptionSecret(
2836  RangeMatches("resumptionsecret"), RangeMatches("nonce")))
2837  .WillOnce(InvokeWithoutArgs(
2838  []() { return IOBuf::copyBuffer("derivedsecret"); }));
2839 
2840  auto nst = TestMessages::newSessionTicket();
2841  nst.ticket_nonce = IOBuf::copyBuffer("nonce");
2842  auto actions = detail::processEvent(state_, std::move(nst));
2843  expectSingleAction<NewCachedPsk>(std::move(actions));
2844 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
static const std::string nst
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestNewSessionTicketEarlyData   
)

Definition at line 2846 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::encodeExtension(), EXPECT_CALL, EXPECT_EQ, testing::InvokeWithoutArgs(), fizz::TicketEarlyData::max_early_data_size, folly::gen::move, fizz::test::TestMessages::newSessionTicket(), nst, fizz::client::detail::processEvent(), fizz::Resumption, fizz::tls_1_3, fizz::TLS_AES_128_GCM_SHA256, and fizz::x25519.

2846  {
2847  setupAcceptingData();
2848 
2849  EXPECT_CALL(
2850  *mockKeyScheduler_,
2851  getResumptionSecret(RangeMatches("resumptionsecret"), RangeMatches("")))
2852  .WillOnce(InvokeWithoutArgs(
2853  []() { return IOBuf::copyBuffer("derivedsecret"); }));
2854 
2855  auto nst = TestMessages::newSessionTicket();
2856  TicketEarlyData early;
2857  early.max_early_data_size = 2000;
2858  nst.extensions.push_back(encodeExtension(std::move(early)));
2859  auto actions = detail::processEvent(state_, std::move(nst));
2860  auto newCachedPsk = expectSingleAction<NewCachedPsk>(std::move(actions));
2861  auto psk = newCachedPsk.psk;
2862  EXPECT_EQ(psk.psk, "ticket");
2863  EXPECT_EQ(psk.secret, "derivedsecret");
2864  EXPECT_EQ(psk.type, PskType::Resumption);
2865  EXPECT_EQ(psk.version, ProtocolVersion::tls_1_3);
2866  EXPECT_EQ(psk.cipher, CipherSuite::TLS_AES_128_GCM_SHA256);
2867  EXPECT_EQ(psk.group, NamedGroup::x25519);
2868  EXPECT_EQ(psk.serverCert, mockLeaf_);
2869  EXPECT_EQ(psk.maxEarlyDataSize, 2000);
2870  EXPECT_EQ(psk.ticketAgeAdd, 0x44444444);
2871 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
static const std::string nst
#define EXPECT_CALL(obj, call)
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestAppData   
)

Definition at line 2873 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::appData(), folly::gen::move, and fizz::client::detail::processEvent().

2873  {
2874  setupAcceptingData();
2875 
2876  auto actions = detail::processEvent(state_, TestMessages::appData());
2877 
2878  expectSingleAction<DeliverAppData>(std::move(actions));
2879 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestAppWrite   
)

Definition at line 2881 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::application_data, fizz::test::TestMessages::appWrite(), fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), fizz::TLSMessage::type, and fizz::detail::write().

2881  {
2882  setupAcceptingData();
2883  EXPECT_CALL(*mockWrite_, _write(_)).WillOnce(Invoke([&](TLSMessage& msg) {
2884  TLSContent content;
2885  content.contentType = msg.type;
2886  content.encryptionLevel = mockWrite_->getEncryptionLevel();
2887  EXPECT_EQ(msg.type, ContentType::application_data);
2888  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, IOBuf::copyBuffer("appdata")));
2889  content.data = IOBuf::copyBuffer("writtenappdata");
2890  return content;
2891  }));
2892 
2894  auto write = expectSingleAction<WriteToSocket>(std::move(actions));
2896  write.contents[0].data, IOBuf::copyBuffer("writtenappdata")));
2897  EXPECT_EQ(
2898  write.contents[0].encryptionLevel,
2899  state_.writeRecordLayer()->getEncryptionLevel());
2900  EXPECT_EQ(write.contents[0].contentType, ContentType::application_data);
2901 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static AppWrite appWrite(const std::string &str)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestKeyUpdateNotRequested   
)

Definition at line 2903 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_EQ, fizz::test::TestMessages::keyUpdate(), and fizz::client::detail::processEvent().

2903  {
2904  setupAcceptingData();
2905  auto actions = detail::processEvent(state_, TestMessages::keyUpdate(false));
2906  expectActions<MutateState>(actions);
2907  EXPECT_EQ(getNumActions<WriteToSocket>(actions, false), 0);
2908 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestKeyUpdateExtraData   
)

Definition at line 2910 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), EXPECT_CALL, fizz::test::TestMessages::keyUpdate(), fizz::client::detail::processEvent(), testing::Return(), and fizz::unexpected_message.

2910  {
2911  setupAcceptingData();
2912  EXPECT_CALL(*mockRead_, hasUnparsedHandshakeData())
2913  .WillRepeatedly(Return(true));
2914  auto actions = detail::processEvent(state_, TestMessages::keyUpdate(false));
2915  expectError<FizzException>(
2916  actions, AlertDescription::unexpected_message, "data after key_update");
2917 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_CALL(obj, call)
Actions processEvent(const State &state, Param param)
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestKeyUpdateRequestFlow   
)

Definition at line 2919 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::AppTraffic, fizz::ClientAppTraffic, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::encodeHandshake(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, fizz::handshake, testing::Invoke(), testing::InvokeWithoutArgs(), fizz::test::TestMessages::keyUpdate(), fizz::client::detail::processEvent(), testing::Return(), fizz::ServerAppTraffic, fizz::TLSMessage::type, and fizz::detail::write().

2919  {
2920  setupAcceptingData();
2921  EXPECT_CALL(*mockKeyScheduler_, serverKeyUpdate());
2922  EXPECT_CALL(*mockRead_, hasUnparsedHandshakeData()).WillOnce(Return(false));
2923 
2924  EXPECT_CALL(
2925  *mockKeyScheduler_, getSecret(AppTrafficSecrets::ServerAppTraffic))
2926  .WillOnce(InvokeWithoutArgs([]() {
2927  return std::vector<uint8_t>({'s', 'a', 't'});
2928  }));
2929 
2930  EXPECT_CALL(*mockWrite_, _write(_)).WillOnce(Invoke([&](TLSMessage& msg) {
2931  TLSContent content;
2932  content.contentType = msg.type;
2933  content.encryptionLevel = mockWrite_->getEncryptionLevel();
2934  EXPECT_EQ(msg.type, ContentType::handshake);
2936  msg.fragment, encodeHandshake(TestMessages::keyUpdate(false))));
2937  content.data = folly::IOBuf::copyBuffer("keyupdated");
2938  return content;
2939  }));
2940 
2941  EXPECT_CALL(*mockKeyScheduler_, clientKeyUpdate());
2942  EXPECT_CALL(
2943  *mockKeyScheduler_, getSecret(AppTrafficSecrets::ClientAppTraffic))
2944  .WillOnce(InvokeWithoutArgs([]() {
2945  return std::vector<uint8_t>({'c', 'a', 't'});
2946  }));
2947 
2948  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("sat"), _, _))
2949  .WillOnce(InvokeWithoutArgs([]() {
2950  return TrafficKey{IOBuf::copyBuffer("serverkey"),
2951  IOBuf::copyBuffer("serveriv")};
2952  }));
2953  EXPECT_CALL(*mockKeyScheduler_, getTrafficKey(RangeMatches("cat"), _, _))
2954  .WillOnce(InvokeWithoutArgs([]() {
2955  return TrafficKey{IOBuf::copyBuffer("clientkey"),
2956  IOBuf::copyBuffer("clientiv")};
2957  }));
2958 
2959  MockAead* raead;
2960  MockAead* waead;
2961  MockEncryptedReadRecordLayer* rrl;
2962  MockEncryptedWriteRecordLayer* wrl;
2963 
2964  expectAeadCreation(&waead, &raead);
2965  expectEncryptedReadRecordLayerCreation(&rrl, &raead, StringPiece("sat"));
2966  expectEncryptedWriteRecordLayerCreation(&wrl, &waead, StringPiece("cat"));
2967 
2968  auto actions = detail::processEvent(state_, TestMessages::keyUpdate(true));
2969  expectActions<MutateState, WriteToSocket>(actions);
2970  auto write = expectAction<WriteToSocket>(actions);
2971  EXPECT_TRUE(
2972  IOBufEqualTo()(write.contents[0].data, IOBuf::copyBuffer("keyupdated")));
2973  EXPECT_EQ(
2974  write.contents[0].encryptionLevel,
2975  state_.writeRecordLayer()->getEncryptionLevel());
2976  EXPECT_EQ(write.contents[0].contentType, ContentType::handshake);
2977  processStateMutations(actions);
2978  EXPECT_EQ(state_.readRecordLayer().get(), rrl);
2979  EXPECT_EQ(
2980  state_.readRecordLayer()->getEncryptionLevel(),
2981  EncryptionLevel::AppTraffic);
2982  EXPECT_EQ(state_.writeRecordLayer().get(), wrl);
2983  EXPECT_EQ(
2984  state_.writeRecordLayer()->getEncryptionLevel(),
2985  EncryptionLevel::AppTraffic);
2986  EXPECT_EQ(state_.state(), StateEnum::Established);
2987 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Range< const char * > StringPiece
Actions processEvent(const State &state, Param param)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
internal::ReturnAction< R > Return(R value)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestInvalidEarlyWrite   
)

Definition at line 2989 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::test::TestMessages::earlyAppWrite(), folly::none, and fizz::client::detail::processEvent().

2989  {
2990  setupExpectingServerHello();
2991 
2992  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
2993  expectError<FizzException>(actions, folly::none, "invalid early write");
2994 }
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
constexpr None none
Definition: Optional.h:87
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingSHEarlyWrite   
)

Definition at line 2996 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::application_data, fizz::Attempted, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::test::TestMessages::earlyAppWrite(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), fizz::TLSMessage::type, and fizz::detail::write().

2996  {
2997  setupExpectingServerHello();
2998  setMockEarlyRecord();
2999  state_.earlyDataType() = EarlyDataType::Attempted;
3000  EXPECT_CALL(*mockEarlyWrite_, _write(_))
3001  .WillOnce(Invoke([&](TLSMessage& msg) {
3002  TLSContent content;
3003  content.contentType = msg.type;
3004  content.encryptionLevel = mockEarlyWrite_->getEncryptionLevel();
3005  EXPECT_EQ(msg.type, ContentType::application_data);
3006  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, IOBuf::copyBuffer("appdata")));
3007  content.data = IOBuf::copyBuffer("writtenappdata");
3008  return content;
3009  }));
3010 
3011  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3012 
3013  auto write = expectSingleAction<WriteToSocket>(std::move(actions));
3015  write.contents[0].data, IOBuf::copyBuffer("writtenappdata")));
3016 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEarlyEncryptionLevelRecvSHLO   
)

Definition at line 3018 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::EarlyData, EXPECT_EQ, fizz::Handshake, fizz::client::detail::processEvent(), and fizz::test::TestMessages::serverHello().

3018  {
3019  setupExpectingServerHello();
3020  setMockEarlyRecord();
3021  state_.earlyDataType() = EarlyDataType::Attempted;
3022 
3023  auto actions = detail::processEvent(state_, TestMessages::serverHello());
3024  processStateMutations(actions);
3025  EXPECT_EQ(
3026  state_.writeRecordLayer()->getEncryptionLevel(),
3027  EncryptionLevel::Handshake);
3028  EXPECT_EQ(
3029  state_.earlyWriteRecordLayer()->getEncryptionLevel(),
3030  EncryptionLevel::EarlyData);
3031 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEarlyEncryptionLevelRecvFinished   
)

Definition at line 3033 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::EarlyData, EXPECT_EQ, fizz::Handshake, fizz::client::detail::processEvent(), and fizz::test::TestMessages::serverHello().

3033  {
3034  setupExpectingServerHello();
3035  setMockEarlyRecord();
3036  state_.earlyDataType() = EarlyDataType::Attempted;
3037 
3038  auto actions = detail::processEvent(state_, TestMessages::serverHello());
3039  processStateMutations(actions);
3040  EXPECT_EQ(
3041  state_.writeRecordLayer()->getEncryptionLevel(),
3042  EncryptionLevel::Handshake);
3043  EXPECT_EQ(
3044  state_.earlyWriteRecordLayer()->getEncryptionLevel(),
3045  EncryptionLevel::EarlyData);
3046 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEarlyWriteCompat   
)

Definition at line 3048 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::application_data, fizz::Attempted, fizz::change_cipher_spec, fizz::test::TestMessages::earlyAppWrite(), fizz::EarlyData, EXPECT_EQ, EXPECT_TRUE, fizz::Plaintext, fizz::client::detail::processEvent(), and fizz::detail::write().

3048  {
3049  setupExpectingServerHello();
3050  setMockEarlyRecord();
3051  state_.earlyDataType() = EarlyDataType::Attempted;
3052  context_->setCompatibilityMode(true);
3053 
3054  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3055  expectActions<MutateState, WriteToSocket>(actions);
3056  auto write = expectAction<WriteToSocket>(actions);
3057  EXPECT_EQ(write.contents.size(), 2);
3058  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::Plaintext);
3059  EXPECT_EQ(write.contents[0].contentType, ContentType::change_cipher_spec);
3060  EXPECT_EQ(write.contents[1].encryptionLevel, EncryptionLevel::EarlyData);
3061  EXPECT_EQ(write.contents[1].contentType, ContentType::application_data);
3062  processStateMutations(actions);
3063  EXPECT_TRUE(state_.sentCCS());
3064 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEarlyWriteCompatCCSAlreadySent   
)

Definition at line 3066 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), fizz::Attempted, fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, and fizz::client::detail::processEvent().

3066  {
3067  setupExpectingServerHello();
3068  setMockEarlyRecord();
3069  state_.earlyDataType() = EarlyDataType::Attempted;
3070  state_.sentCCS() = true;
3071  context_->setCompatibilityMode(true);
3072 
3073  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3074 
3075  expectActions<WriteToSocket>(actions);
3076  EXPECT_TRUE(state_.sentCCS());
3077 }
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEarlyAcceptedCompatNoEarlyData   
)

Definition at line 3079 of file ClientProtocolTest.cpp.

References fizz::Accepted, fizz::client::detail::actions(), ASSERT_EQ, fizz::change_cipher_spec, fizz::EarlyData, EXPECT_EQ, EXPECT_TRUE, fizz::test::TestMessages::finished(), fizz::Handshake, fizz::handshake, fizz::Plaintext, fizz::client::detail::processEvent(), and fizz::detail::write().

3079  {
3080  setupExpectingFinished();
3081  setMockEarlyRecord();
3082  state_.earlyDataType() = EarlyDataType::Accepted;
3083  context_->setCompatibilityMode(true);
3084 
3085  auto actions = detail::processEvent(state_, TestMessages::finished());
3086 
3087  expectActions<MutateState, WriteToSocket, ReportHandshakeSuccess>(actions);
3088  auto write = expectAction<WriteToSocket>(actions);
3089  ASSERT_EQ(write.contents.size(), 3);
3090  EXPECT_EQ(write.contents[0].contentType, ContentType::change_cipher_spec);
3091  EXPECT_EQ(write.contents[0].encryptionLevel, EncryptionLevel::Plaintext);
3092 
3093  EXPECT_EQ(write.contents[1].contentType, ContentType::handshake);
3094  EXPECT_EQ(write.contents[1].encryptionLevel, EncryptionLevel::EarlyData);
3095 
3096  EXPECT_EQ(write.contents[2].contentType, ContentType::handshake);
3097  EXPECT_EQ(write.contents[2].encryptionLevel, EncryptionLevel::Handshake);
3098 
3099  processStateMutations(actions);
3100  EXPECT_TRUE(state_.sentCCS());
3101 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingSHEarlyWriteRejected   
)

Definition at line 3103 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3103  {
3104  setupExpectingServerHello();
3105  state_.earlyDataType() = EarlyDataType::Rejected;
3106 
3107  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3108  auto failedWrite =
3109  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3110  EXPECT_TRUE(
3111  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3112 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingEEEarlyWrite   
)

Definition at line 3114 of file ClientProtocolTest.cpp.

References testing::_, fizz::client::detail::actions(), fizz::application_data, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::test::TestMessages::earlyAppWrite(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), fizz::TLSMessage::type, and fizz::detail::write().

3114  {
3115  setupExpectingEncryptedExtensionsEarlySent();
3116  EXPECT_CALL(*mockEarlyWrite_, _write(_))
3117  .WillOnce(Invoke([&](TLSMessage& msg) {
3118  TLSContent content;
3119  content.contentType = msg.type;
3120  content.encryptionLevel = mockEarlyWrite_->getEncryptionLevel();
3121  EXPECT_EQ(msg.type, ContentType::application_data);
3122  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, IOBuf::copyBuffer("appdata")));
3123  content.data = IOBuf::copyBuffer("writtenappdata");
3124  return content;
3125  }));
3126 
3127  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3128 
3129  auto write = expectSingleAction<WriteToSocket>(std::move(actions));
3131  write.contents[0].data, IOBuf::copyBuffer("writtenappdata")));
3132 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingEEEarlyWriteRejected   
)

Definition at line 3134 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3134  {
3135  setupExpectingEncryptedExtensionsEarlySent();
3136  state_.earlyDataType() = EarlyDataType::Rejected;
3137 
3138  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3139  auto failedWrite =
3140  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3141  EXPECT_TRUE(
3142  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3143 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingCertEarlyWriteRejected   
)

Definition at line 3145 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3145  {
3146  setupExpectingEncryptedExtensionsEarlySent();
3147  state_.earlyDataType() = EarlyDataType::Rejected;
3148 
3149  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3150  auto failedWrite =
3151  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3152  EXPECT_TRUE(
3153  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3154 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingCertVerifyEarlyWriteRejected   
)

Definition at line 3156 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3156  {
3157  setupExpectingEncryptedExtensionsEarlySent();
3158  state_.earlyDataType() = EarlyDataType::Rejected;
3159 
3160  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3161  auto failedWrite =
3162  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3163  EXPECT_TRUE(
3164  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3165 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingFinishedEarlyWrite   
)

Definition at line 3167 of file ClientProtocolTest.cpp.

References testing::_, fizz::Accepted, fizz::client::detail::actions(), fizz::application_data, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::test::TestMessages::earlyAppWrite(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), fizz::TLSMessage::type, and fizz::detail::write().

3167  {
3168  setupExpectingFinished();
3169  setMockEarlyRecord();
3170  state_.earlyDataType() = EarlyDataType::Accepted;
3171  EXPECT_CALL(*mockEarlyWrite_, _write(_))
3172  .WillOnce(Invoke([&](TLSMessage& msg) {
3173  TLSContent content;
3174  content.contentType = msg.type;
3175  content.encryptionLevel = mockEarlyWrite_->getEncryptionLevel();
3176  EXPECT_EQ(msg.type, ContentType::application_data);
3177  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, IOBuf::copyBuffer("appdata")));
3178  content.data = IOBuf::copyBuffer("writtenappdata");
3179  return content;
3180  }));
3181 
3182  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3183 
3184  auto write = expectSingleAction<WriteToSocket>(std::move(actions));
3186  write.contents[0].data, IOBuf::copyBuffer("writtenappdata")));
3187 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestExpectingFinishedEarlyWriteRejected   
)

Definition at line 3189 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3189  {
3190  setupExpectingFinished();
3191  state_.earlyDataType() = EarlyDataType::Rejected;
3192 
3193  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3194  auto failedWrite =
3195  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3196  EXPECT_TRUE(
3197  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3198 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEstablishedEarlyWrite   
)

Definition at line 3200 of file ClientProtocolTest.cpp.

References testing::_, fizz::Accepted, fizz::client::detail::actions(), fizz::application_data, fizz::TLSContent::contentType, folly::IOBuf::copyBuffer(), fizz::TLSContent::data, fizz::test::TestMessages::earlyAppWrite(), fizz::TLSContent::encryptionLevel, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, fizz::TLSMessage::fragment, testing::Invoke(), folly::gen::move, fizz::client::detail::processEvent(), fizz::TLSMessage::type, and fizz::detail::write().

3200  {
3201  setupAcceptingData();
3202  state_.earlyDataType() = EarlyDataType::Accepted;
3203  EXPECT_CALL(*mockWrite_, _write(_)).WillOnce(Invoke([&](TLSMessage& msg) {
3204  TLSContent content;
3205  content.contentType = msg.type;
3206  content.encryptionLevel = mockWrite_->getEncryptionLevel();
3207  EXPECT_EQ(msg.type, ContentType::application_data);
3208  EXPECT_TRUE(IOBufEqualTo()(msg.fragment, IOBuf::copyBuffer("appdata")));
3209  content.data = IOBuf::copyBuffer("writtenappdata");
3210  return content;
3211  }));
3212 
3213  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3214 
3215  auto write = expectSingleAction<WriteToSocket>(std::move(actions));
3217  write.contents[0].data, IOBuf::copyBuffer("writtenappdata")));
3218 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
Actions processEvent(const State &state, Param param)
fizz::client::test::TEST_F ( ClientProtocolTest  ,
TestEstablishedEarlyWriteRejected   
)

Definition at line 3220 of file ClientProtocolTest.cpp.

References fizz::client::detail::actions(), folly::IOBuf::copyBuffer(), fizz::test::TestMessages::earlyAppWrite(), EXPECT_TRUE, folly::gen::move, fizz::client::detail::processEvent(), and fizz::Rejected.

3220  {
3221  setupAcceptingData();
3222  state_.earlyDataType() = EarlyDataType::Rejected;
3223 
3224  auto actions = detail::processEvent(state_, TestMessages::earlyAppWrite());
3225  auto failedWrite =
3226  expectSingleAction<ReportEarlyWriteFailed>(std::move(actions));
3227  EXPECT_TRUE(
3228  IOBufEqualTo()(failedWrite.write.data, IOBuf::copyBuffer("appdata")));
3229 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Actions processEvent(const State &state, Param param)