Skip to content

Commit

Permalink
Fix OSS forward declaration issues
Browse files Browse the repository at this point in the history
Reviewed By: frqiu

Differential Revision: D52182385

fbshipit-source-id: 5acee4d8ad95cb3815b359f81d01eeb32617d03d
  • Loading branch information
Sotirios Delimanolis authored and facebook-github-bot committed Dec 18, 2023
1 parent 3ed9aef commit cda4472
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions fizz/server/test/AeadTicketCipherTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
#include <folly/String.h>

using namespace fizz::test;
using namespace folly;
using namespace testing;

static constexpr StringPiece ticketSecret1{
static constexpr folly::StringPiece ticketSecret1{
"90a791cf38c0b5c20447ef029ae1bc4bf3eecc2e85042174497671835ceaccd9"};
// secret: 13deec41c45b2f1c4f595ad5972d13047fba09031ba53140c751380e74114cc4
// salt: 4444444444444444444444444444444444444444444444444444444444444444
// hkdf output: c951156f3dcb1ab243a3f2c8e4346bec92cb25d241ae821484081388
static constexpr StringPiece ticket1{
static constexpr folly::StringPiece ticket1{
"444444444444444444444444444444444444444444444444444444444444444400000000579bb5b10c83d7a581f6b8f7bd25acde3dabfe6f59e5147bde86681831"};
static constexpr StringPiece ticket2{
static constexpr folly::StringPiece ticket2{
"444444444444444444444444444444444444444444444444444444444444444400000001f444b4f0a0d1dd8b26d3a0afa275b4f6956cfdce4857f9ec46177d0ff9"};

static constexpr StringPiece ticketSecret2{
static constexpr folly::StringPiece ticketSecret2{
"04de0343a34c12f17f8b9696443d55e533ca1eef92bdba6634a46b604e51436d"};
// secret: d2c07e1107d3024bd08ebf34d59b9726d05bd7082da80cbb1e90b879e0770b5f
// salt: 5cef31d266ca1fe1d634de9b95668d3d8895d4837d3ba81787185ff51c056e95
// hkdf output: f7d80b07236875b5a48bdc5bd4642a775c05c231b9507285675c1e0b
static constexpr StringPiece ticket3{
static constexpr folly::StringPiece ticket3{
"5cef31d266ca1fe1d634de9b95668d3d8895d4837d3ba81787185ff51c056e95000000005d19a72a3becb5b063346fdf1ec6f9d9d4ddd82cb5f34a8ba0d19e4b69"};

// Uses context 'foobar'
static constexpr StringPiece ticket4{
static constexpr folly::StringPiece ticket4{
"5cef31d266ca1fe1d634de9b95668d3d8895d4837d3ba81787185ff51c056e95000000005b2168cc0fda4f9987b5e9d045845ba4809ac5189158c578c0e5d11b00"};

static constexpr StringPiece badTicket{
static constexpr folly::StringPiece badTicket{
"5d19a72a3becb5b061346fdf1ec6f9d9d4ddd82cb5f34a8ba0d19e4b69"};

namespace fizz {
Expand Down Expand Up @@ -114,7 +113,8 @@ class AeadTicketCipherTest : public Test {
cipher_.setPolicy(policy_);
auto s1 = toIOBuf(ticketSecret1);
auto s2 = toIOBuf(ticketSecret2);
std::vector<ByteRange> ticketSecrets{{s1->coalesce(), s2->coalesce()}};
std::vector<folly::ByteRange> ticketSecrets{
{s1->coalesce(), s2->coalesce()}};
EXPECT_TRUE(cipher_.setTicketSecrets(std::move(ticketSecrets)));
}

Expand All @@ -123,8 +123,8 @@ class AeadTicketCipherTest : public Test {
.WillOnce(Invoke([](Buf& encoded,
const Factory& /* factory */,
const CertManager& /* certManager */) {
EXPECT_TRUE(
IOBufEqualTo()(encoded, IOBuf::copyBuffer("encodedticket")));
EXPECT_TRUE(folly::IOBufEqualTo()(
encoded, folly::IOBuf::copyBuffer("encodedticket")));
return ResumptionState();
}));
}
Expand Down Expand Up @@ -160,12 +160,12 @@ TEST_F(AeadTicketCipherTest, TestEncrypt) {
updatePolicy(std::chrono::seconds(5));
rebuildCipher();
EXPECT_CALL(codec_, _encode(_)).WillOnce(InvokeWithoutArgs([]() {
return IOBuf::copyBuffer("encodedticket");
return folly::IOBuf::copyBuffer("encodedticket");
}));
ResumptionState state;
auto result = cipher_.encrypt(std::move(state)).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_TRUE(folly::IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_EQ(result->second, std::chrono::seconds(5));
}

Expand All @@ -177,7 +177,7 @@ TEST_F(AeadTicketCipherTest, TestHandshakeExpiration) {
EXPECT_CALL(*clock_, getCurrentTime()).WillOnce(Return(time));

EXPECT_CALL(codec_, _encode(_)).WillOnce(InvokeWithoutArgs([]() {
return IOBuf::copyBuffer("encodedticket");
return folly::IOBuf::copyBuffer("encodedticket");
}));
EXPECT_CALL(codec_, _decode(_, _, _))
.Times(2)
Expand All @@ -188,7 +188,7 @@ TEST_F(AeadTicketCipherTest, TestHandshakeExpiration) {
}));
auto result = cipher_.encrypt(makeState(time)).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_TRUE(folly::IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_EQ(result->second, std::chrono::seconds(2));
EXPECT_CALL(*clock_, getCurrentTime())
.WillOnce(Return(time + std::chrono::seconds(1)));
Expand All @@ -211,21 +211,21 @@ TEST_F(AeadTicketCipherTest, TestTicketLifetime) {
EXPECT_CALL(codec_, _encode(_))
.Times(2)
.WillRepeatedly(InvokeWithoutArgs(
[]() { return IOBuf::copyBuffer("encodedticket"); }));
[]() { return folly::IOBuf::copyBuffer("encodedticket"); }));

// At handshake time, expect ticket validity.
EXPECT_CALL(*clock_, getCurrentTime()).WillOnce(Return(time));
auto result = cipher_.encrypt(makeState(time)).get();
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(IOBufEqualTo()(result->first, toIOBuf(ticket1)));
EXPECT_TRUE(folly::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(makeState(time)).get();
EXPECT_TRUE(result2.has_value());
EXPECT_TRUE(IOBufEqualTo()(result2->first, toIOBuf(ticket1)));
EXPECT_TRUE(folly::IOBufEqualTo()(result2->first, toIOBuf(ticket1)));
EXPECT_EQ(result2->second, std::chrono::seconds(1));

// 5 seconds in, no longer valid. Expect none.
Expand Down Expand Up @@ -255,14 +255,14 @@ TEST_F(AeadTicketCipherTest, TestEncryptTicketFromFuture) {
EXPECT_CALL(*clock_, getCurrentTime()).WillOnce(Return(time));

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

Expand Down Expand Up @@ -337,20 +337,20 @@ TEST_F(AeadTicketCipherTest, TestDecryptFailed) {

TEST_F(AeadTicketCipherTest, TestDecryptTooShort) {
rebuildCipher();
auto result = cipher_.decrypt(IOBuf::copyBuffer("short")).get();
auto result = cipher_.decrypt(folly::IOBuf::copyBuffer("short")).get();
EXPECT_EQ(result.first, PskType::Rejected);
EXPECT_FALSE(result.second.has_value());
}

TEST_F(AeadTicketCipherTest, TestUnsetTicketSecrets) {
rebuildCipher();
EXPECT_TRUE(cipher_.setTicketSecrets(std::vector<ByteRange>()));
EXPECT_TRUE(cipher_.setTicketSecrets(std::vector<folly::ByteRange>()));
checkUnsetEncrypt();
}

TEST_F(AeadTicketCipherTest, TestSetTicketSecretsTooShort) {
StringPiece tooShort{"short"};
std::vector<ByteRange> ticketSecrets{{tooShort}};
folly::StringPiece tooShort{"short"};
std::vector<folly::ByteRange> ticketSecrets{{tooShort}};
EXPECT_FALSE(cipher_.setTicketSecrets(std::move(ticketSecrets)));
checkUnsetEncrypt();
}
Expand Down

0 comments on commit cda4472

Please sign in to comment.