Skip to content

Commit

Permalink
Fix use-after-move in AeadTicketCipherTest.
Browse files Browse the repository at this point in the history
Summary: This "worked" before since we only cared about the time_point, but was still wrong.

Reviewed By: zalecodez

Differential Revision: D51535310

fbshipit-source-id: b370352a741d0d004cd76d98474ede45d592a4b1
  • Loading branch information
Kyle Nekritz authored and facebook-github-bot committed Nov 23, 2023
1 parent 9e0d079 commit 0ee8dd9
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions fizz/server/test/AeadTicketCipherTest.cpp
Expand Up @@ -141,6 +141,13 @@ class AeadTicketCipherTest : public Test {
policy_.setHandshakeValidity(*handshakeValidity);
}
}

static ResumptionState makeState(
std::chrono::system_clock::time_point handshakeTime) {
ResumptionState state;
state.handshakeTime = handshakeTime;
return state;
}
};

TEST_F(AeadTicketCipherTest, TestEncryptNoTicketSecrets) {
Expand Down Expand Up @@ -178,9 +185,7 @@ TEST_F(AeadTicketCipherTest, TestHandshakeExpiration) {
res.handshakeTime = time;
return res;
}));
ResumptionState state;
state.handshakeTime = time;
auto result = cipher_.encrypt(std::move(state)).get();
auto result = cipher_.encrypt(makeState(time)).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_EQ(result->second, std::chrono::seconds(2));
Expand Down Expand Up @@ -209,25 +214,23 @@ TEST_F(AeadTicketCipherTest, TestTicketLifetime) {

// At handshake time, expect ticket validity.
EXPECT_CALL(*clock_, getCurrentTime()).WillOnce(Return(time));
ResumptionState state;
state.handshakeTime = time;
auto result = cipher_.encrypt(std::move(state)).get();
auto result = cipher_.encrypt(makeState(time)).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_EQ(result->second, std::chrono::seconds(2));

// At 3 seconds in, expect 1 second (remaining handshake validity)
EXPECT_CALL(*clock_, getCurrentTime())
.WillOnce(Return(time + std::chrono::seconds(3)));
auto result2 = cipher_.encrypt(std::move(state)).get();
auto result2 = cipher_.encrypt(makeState(time)).get();
EXPECT_TRUE(result2.has_value());
EXPECT_TRUE(IOBufEqualTo()(result2->first, toIOBuf(ticket1)));
EXPECT_EQ(result2->second, std::chrono::seconds(1));

// 5 seconds in, no longer valid. Expect none.
EXPECT_CALL(*clock_, getCurrentTime())
.WillOnce(Return(time + std::chrono::seconds(5)));
auto result3 = cipher_.encrypt(std::move(state)).get();
auto result3 = cipher_.encrypt(makeState(time)).get();
EXPECT_FALSE(result3.has_value());
}

Expand All @@ -238,9 +241,8 @@ TEST_F(AeadTicketCipherTest, TestEncryptExpiredHandshakeTicket) {
auto time = std::chrono::system_clock::now();
EXPECT_CALL(*clock_, getCurrentTime()).WillOnce(Return(time));

ResumptionState state;
state.handshakeTime = time - std::chrono::seconds(5);
auto result = cipher_.encrypt(std::move(state)).get();
auto result =
cipher_.encrypt(makeState(time - std::chrono::seconds(5))).get();
EXPECT_FALSE(result.has_value());
}

Expand All @@ -254,11 +256,10 @@ TEST_F(AeadTicketCipherTest, TestEncryptTicketFromFuture) {
EXPECT_CALL(codec_, _encode(_)).WillOnce(InvokeWithoutArgs([]() {
return IOBuf::copyBuffer("encodedticket");
}));
ResumptionState state;
// Ticket was created in the future. Validity period should be equal
// to maximum (as we can't be sure how old it really is)
state.handshakeTime = time + std::chrono::seconds(5);
auto result = cipher_.encrypt(std::move(state)).get();
auto result =
cipher_.encrypt(makeState(time + std::chrono::seconds(5))).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_EQ(result->second, std::chrono::seconds(2));
Expand Down

0 comments on commit 0ee8dd9

Please sign in to comment.