1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-09 20:42:44 +03:00
Files
mvfst/quic/client/test/ClientStateMachineTest.cpp
Matt Joras 36bef91503 Don't use old max packet size for 0rtt.
Summary:
This is a bug, for 0rtt, even if the can ignore flag is set, we shouldn't trust the old max packet size. If it has changed then the peer will fail to decrypt anything.

There are open questions here around the PMTU we use for the handshake/0rtt, but let's just punt on those for now.

Reviewed By: udippant, xttjsn

Differential Revision: D23641082

fbshipit-source-id: aba93713091805e9498ab2c14b24bccf18192c02
2020-09-11 08:14:56 -07:00

91 lines
3.5 KiB
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#include <quic/client/state/ClientStateMachine.h>
#include <quic/client/handshake/CachedServerTransportParameters.h>
#include <quic/client/handshake/ClientHandshake.h>
#include <quic/handshake/CryptoFactory.h>
#include <quic/handshake/TransportParameters.h>
#include "quic/client/test/Mocks.h"
using namespace ::testing;
namespace quic::test {
namespace {
// Use non-default values to test for nops
constexpr auto idleTimeout = kDefaultIdleTimeout + 1s;
constexpr auto maxRecvPacketSize = 1420;
constexpr auto initialMaxData = kDefaultConnectionWindowSize + 2;
constexpr auto initialMaxStreamDataBidiLocal = kDefaultStreamWindowSize + 3;
constexpr auto initialMaxStreamDataBidiRemote = kDefaultStreamWindowSize + 4;
constexpr auto initialMaxStreamDataUni = kDefaultStreamWindowSize + 5;
constexpr auto initialMaxStreamsBidi = kDefaultMaxStreamsBidirectional + 6;
constexpr auto initialMaxStreamsUni = kDefaultMaxStreamsUnidirectional + 7;
const CachedServerTransportParameters kParams{
std::chrono::milliseconds(idleTimeout).count(),
maxRecvPacketSize,
initialMaxData,
initialMaxStreamDataBidiLocal,
initialMaxStreamDataBidiRemote,
initialMaxStreamDataUni,
initialMaxStreamsBidi,
initialMaxStreamsUni};
} // namespace
class ClientStateMachineTest : public Test {
public:
void SetUp() override {
mockFactory_ = std::make_shared<MockClientHandshakeFactory>();
EXPECT_CALL(*mockFactory_, makeClientHandshake(_))
.WillOnce(Invoke(
[&](QuicClientConnectionState* conn)
-> std::unique_ptr<quic::ClientHandshake> {
auto handshake = std::make_unique<MockClientHandshake>(conn);
mockHandshake_ = handshake.get();
return handshake;
}));
client_ = std::make_unique<QuicClientConnectionState>(mockFactory_);
}
std::shared_ptr<MockClientHandshakeFactory> mockFactory_;
MockClientHandshake* mockHandshake_;
std::unique_ptr<QuicClientConnectionState> client_;
};
TEST_F(ClientStateMachineTest, TestUpdateTransportParamsNotIgnorePathMTU) {
updateTransportParamsFromCachedEarlyParams(*client_, kParams);
EXPECT_EQ(client_->udpSendPacketLen, kDefaultUDPSendPacketLen);
}
TEST_F(ClientStateMachineTest, TestUpdateTransportParamsFromCachedEarlyParams) {
client_->transportSettings.canIgnorePathMTU = true;
updateTransportParamsFromCachedEarlyParams(*client_, kParams);
EXPECT_EQ(client_->peerIdleTimeout, idleTimeout);
EXPECT_NE(client_->udpSendPacketLen, maxRecvPacketSize);
EXPECT_EQ(client_->flowControlState.peerAdvertisedMaxOffset, initialMaxData);
EXPECT_EQ(
client_->flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiLocal,
initialMaxStreamDataBidiLocal);
EXPECT_EQ(
client_->flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote,
initialMaxStreamDataBidiRemote);
EXPECT_EQ(
client_->flowControlState.peerAdvertisedInitialMaxStreamOffsetUni,
initialMaxStreamDataUni);
for (unsigned long i = 0; i < initialMaxStreamsBidi; i++) {
EXPECT_TRUE(
client_->streamManager->createNextBidirectionalStream().hasValue());
}
EXPECT_TRUE(
client_->streamManager->createNextBidirectionalStream().hasError());
for (unsigned long i = 0; i < initialMaxStreamsUni; i++) {
EXPECT_TRUE(
client_->streamManager->createNextUnidirectionalStream().hasValue());
}
EXPECT_TRUE(
client_->streamManager->createNextUnidirectionalStream().hasError());
}
} // namespace quic::test