Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1354152 - Fix ShortRead test, a=bustage
--HG--
extra : transplant_source : %FD%28%CA%14%F7%CCP8S%92it%94%88H%7D%94%D6D%60
  • Loading branch information
martinthomson committed Jun 4, 2017
1 parent 52979f6 commit 3a8e0ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions gtests/ssl_gtest/ssl_loopback_unittest.cc
Expand Up @@ -198,8 +198,10 @@ TEST_P(TlsConnectGeneric, ConnectSendReceive) {
TEST_P(TlsConnectDatagram, ShortRead) {
Connect();
client_->ExpectReadWriteError();
server_->SendData(1200, 1200);
client_->WaitForErrorCode(SSL_ERROR_RX_SHORT_DTLS_READ, 2000);
server_->SendData(50, 50);
client_->ReadBytes(20);
EXPECT_EQ(0U, client_->received_bytes());
EXPECT_EQ(SSL_ERROR_RX_SHORT_DTLS_READ, PORT_GetError());

// Now send and receive another packet.
server_->ResetSentBytes(); // Reset the counter.
Expand All @@ -213,13 +215,13 @@ TEST_P(TlsConnectStream, ShortRead) {
if (version_ < SSL_LIBRARY_VERSION_TLS_1_1) return;

Connect();
server_->SendData(1200, 1200);
server_->SendData(50, 50);
// Read the first tranche.
WAIT_(client_->received_bytes() == 1024, 2000);
ASSERT_EQ(1024U, client_->received_bytes());
client_->ReadBytes(20);
ASSERT_EQ(20U, client_->received_bytes());
// The second tranche should now immediately be available.
client_->ReadBytes();
ASSERT_EQ(1200U, client_->received_bytes());
ASSERT_EQ(50U, client_->received_bytes());
}

TEST_P(TlsConnectGeneric, ConnectWithCompressionMaybe) {
Expand Down
4 changes: 2 additions & 2 deletions gtests/ssl_gtest/tls_agent.cc
Expand Up @@ -918,10 +918,10 @@ void TlsAgent::SendBuffer(const DataBuffer& buf) {
}
}

void TlsAgent::ReadBytes() {
void TlsAgent::ReadBytes(size_t max) {
uint8_t block[1024];

int32_t rv = PR_Read(ssl_fd(), block, sizeof(block));
int32_t rv = PR_Read(ssl_fd(), block, (std::min)(max, sizeof(block)));
LOGV("ReadBytes " << rv);
int32_t err;

Expand Down
2 changes: 1 addition & 1 deletion gtests/ssl_gtest/tls_agent.h
Expand Up @@ -151,7 +151,7 @@ class TlsAgent : public PollTarget {
void SendBuffer(const DataBuffer& buf);
// Send data directly to the underlying socket, skipping the TLS layer.
void SendDirect(const DataBuffer& buf);
void ReadBytes();
void ReadBytes(size_t max = 16384U);
void ResetSentBytes(); // Hack to test drops.
void EnableExtendedMasterSecret();
void CheckExtendedMasterSecret(bool expected);
Expand Down

0 comments on commit 3a8e0ca

Please sign in to comment.