Skip to content

Commit

Permalink
Move mock ECH decrypter to a common file
Browse files Browse the repository at this point in the history
Summary: Makes MockECHDecrypter available to use in other places.

Reviewed By: AjanthanAsogamoorthy

Differential Revision: D44109877

fbshipit-source-id: 86d7e1ba406e374b7e1713eaf198708efeed4106
  • Loading branch information
Abdulbaki Aydin authored and facebook-github-bot committed Mar 17, 2023
1 parent 1e7b78b commit 556c4d1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
37 changes: 37 additions & 0 deletions fizz/protocol/test/Mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <fizz/protocol/KeyScheduler.h>
#include <fizz/protocol/OpenSSLFactory.h>
#include <fizz/protocol/Types.h>
#include <fizz/protocol/ech/Decrypter.h>
#include <fizz/record/test/Mocks.h>

#include <folly/io/async/test/MockAsyncTransport.h>
Expand Down Expand Up @@ -424,5 +425,41 @@ class MockAsyncFizzBase : public AsyncFizzBase {
MOCK_METHOD(void, resumeEvents, ());
};

class MockECHDecrypter : public ech::Decrypter {
public:
MOCK_METHOD(
folly::Optional<ech::DecrypterResult>,
decryptClientHello,
(const ClientHello& chlo));

MOCK_METHOD(
ClientHello,
_decryptClientHelloHRR_Stateful,
(const ClientHello& chlo, std::unique_ptr<hpke::HpkeContext>& context));

ClientHello decryptClientHelloHRR(
const ClientHello& chlo,
std::unique_ptr<hpke::HpkeContext>& context) override {
return _decryptClientHelloHRR_Stateful(chlo, context);
}

MOCK_METHOD(
ClientHello,
_decryptClientHelloHRR_Stateless,
(const ClientHello& chlo,
const std::unique_ptr<folly::IOBuf>& encapsulatedKey));

ClientHello decryptClientHelloHRR(
const ClientHello& chlo,
const std::unique_ptr<folly::IOBuf>& encapsulatedKey) override {
return _decryptClientHelloHRR_Stateless(chlo, encapsulatedKey);
}

MOCK_METHOD(
std::vector<ech::ECHConfig>,
getRetryConfigs,
(),
(const, override));
};
} // namespace test
} // namespace fizz
61 changes: 12 additions & 49 deletions fizz/server/test/ServerProtocolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,6 @@ namespace fizz {
namespace server {
namespace test {

class MockDecrypter : public ech::Decrypter {
public:
MOCK_METHOD(
folly::Optional<ech::DecrypterResult>,
decryptClientHello,
(const ClientHello& chlo));

MOCK_METHOD(
ClientHello,
_decryptClientHelloHRR_Stateful,
(const ClientHello& chlo, std::unique_ptr<hpke::HpkeContext>& context));

ClientHello decryptClientHelloHRR(
const ClientHello& chlo,
std::unique_ptr<hpke::HpkeContext>& context) override {
return _decryptClientHelloHRR_Stateful(chlo, context);
}

MOCK_METHOD(
ClientHello,
_decryptClientHelloHRR_Stateless,
(const ClientHello& chlo,
const std::unique_ptr<folly::IOBuf>& encapsulatedKey));

ClientHello decryptClientHelloHRR(
const ClientHello& chlo,
const std::unique_ptr<folly::IOBuf>& encapsulatedKey) override {
return _decryptClientHelloHRR_Stateless(chlo, encapsulatedKey);
}

MOCK_METHOD(
std::vector<ech::ECHConfig>,
getRetryConfigs,
(),
(const, override));
};

class ServerProtocolTest : public ProtocolTest<ServerTypes, Actions> {
public:
void SetUp() override {
Expand Down Expand Up @@ -1157,7 +1120,7 @@ TEST_F(ServerProtocolTest, TestECHDecryptionSuccess) {
Sequence contextSeq;
context_->setClientAuthMode(ClientAuthMode::Required);

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
EXPECT_CALL(*decrypter, decryptClientHello(_))
.WillOnce(
InvokeWithoutArgs([=]() -> folly::Optional<ech::DecrypterResult> {
Expand Down Expand Up @@ -1481,7 +1444,7 @@ TEST_F(ServerProtocolTest, TestECHMissingInnerExtension) {
setUpExpectingClientHello();
Sequence contextSeq;

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
EXPECT_CALL(*decrypter, decryptClientHello(_))
.WillOnce(
InvokeWithoutArgs([=]() -> folly::Optional<ech::DecrypterResult> {
Expand All @@ -1504,7 +1467,7 @@ TEST_F(ServerProtocolTest, TestECHDecryptionFailure) {
Sequence contextSeq;
context_->setClientAuthMode(ClientAuthMode::Required);

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
EXPECT_CALL(*decrypter, decryptClientHello(_))
.WillOnce(InvokeWithoutArgs([=]() { return folly::none; }));
EXPECT_CALL(*decrypter, getRetryConfigs())
Expand Down Expand Up @@ -3069,7 +3032,7 @@ TEST_F(ServerProtocolTest, TestRetryClientHelloPskDheFlow) {

TEST_F(ServerProtocolTest, TestRetryClientHelloECHFlow) {
setUpExpectingClientHelloRetryECH();
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);
Sequence contextSeq;
mockKeyScheduler_ = new MockKeyScheduler();
Expand Down Expand Up @@ -3365,7 +3328,7 @@ TEST_F(ServerProtocolTest, TestRetryClientHelloECHFlow) {
TEST_F(ServerProtocolTest, TestRetryECHMissingInnerExtension) {
setUpExpectingClientHelloRetryECH();

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
EXPECT_CALL(*decrypter, _decryptClientHelloHRR_Stateful(_, _))
.WillOnce(
InvokeWithoutArgs([=]() { return TestMessages::clientHello(); }));
Expand All @@ -3381,7 +3344,7 @@ TEST_F(ServerProtocolTest, TestRetryECHMissingInnerExtension) {
TEST_F(ServerProtocolTest, TestRetryClientHelloECHRejectedFlow) {
setUpExpectingClientHelloRetry();
state_.echStatus() = ECHStatus::Rejected;
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
EXPECT_CALL(*decrypter, getRetryConfigs())
.WillOnce(InvokeWithoutArgs([]() -> std::vector<ech::ECHConfig> {
ech::ECHConfig cfg;
Expand Down Expand Up @@ -5220,7 +5183,7 @@ TEST_F(ServerProtocolTest, TestRetryClientHelloCookie) {

TEST_F(ServerProtocolTest, TestRetryClientHelloECHRequired) {
setUpExpectingClientHelloRetryECH();
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);
state_.echStatus() = ECHStatus::Accepted;
auto actions =
Expand All @@ -5231,7 +5194,7 @@ TEST_F(ServerProtocolTest, TestRetryClientHelloECHRequired) {

TEST_F(ServerProtocolTest, TestRetryClientHelloECHCipherMismatch) {
setUpExpectingClientHelloRetryECH();
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);
state_.echStatus() = ECHStatus::Accepted;
auto chlo = setupClientHelloOuterHRR();
Expand Down Expand Up @@ -5338,7 +5301,7 @@ TEST_F(ServerProtocolTest, TestClientHelloCookieECH) {
expectCookie();
setUpExpectingClientHello();

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);
EXPECT_CALL(*decrypter, _decryptClientHelloHRR_Stateless(_, _))
.WillOnce(Invoke(
Expand Down Expand Up @@ -5371,7 +5334,7 @@ TEST_F(ServerProtocolTest, TestClientHelloCookieECHMissingInner) {
expectCookie();
setUpExpectingClientHello();

auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);
EXPECT_CALL(*decrypter, _decryptClientHelloHRR_Stateless(_, _))
.WillOnce(Invoke(
Expand Down Expand Up @@ -5528,7 +5491,7 @@ TEST_F(ServerProtocolTest, TestClientHelloCookieNoGroup) {
TEST_F(ServerProtocolTest, TestClientHelloCookieRejectECHCipher) {
expectCookie();
setUpExpectingClientHello();
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);

auto chlo = setupClientHelloOuterHRR();
Expand All @@ -5555,7 +5518,7 @@ TEST_F(ServerProtocolTest, TestClientHelloCookieRejectECHCipher) {
TEST_F(ServerProtocolTest, TestClientHelloCookieRejectECHRequired) {
expectCookie();
setUpExpectingClientHello();
auto decrypter = std::make_shared<MockDecrypter>();
auto decrypter = std::make_shared<MockECHDecrypter>();
context_->setECHDecrypter(decrypter);

auto chlo = TestMessages::clientHello();
Expand Down

0 comments on commit 556c4d1

Please sign in to comment.