proxygen
DualTicketCipherTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
13 #include <fizz/server/test/Mocks.h>
14 
15 namespace fizz {
16 namespace server {
17 namespace test {
18 
19 TEST(DualCipherTest, Encryption) {
20  auto cipher = std::make_unique<MockTicketCipher>();
21  auto fallbackCipher = std::make_unique<MockTicketCipher>();
22  ResumptionState resState;
23 
24  cipher->setDefaults();
25  fallbackCipher->setDefaults();
26  EXPECT_CALL(*cipher, _encrypt(_)).Times(1);
27  EXPECT_CALL(*fallbackCipher, _encrypt(_)).Times(0);
28 
29  auto dualCipher =
30  DualTicketCipher(std::move(cipher), std::move(fallbackCipher));
31  dualCipher.encrypt(std::move(resState));
32 }
33 
34 TEST(DualCipherTest, DecryptSuccess) {
35  auto cipher = std::make_unique<MockTicketCipher>();
36  auto fallbackCipher = std::make_unique<MockTicketCipher>();
37  ResumptionState resState;
38 
39  EXPECT_CALL(*cipher, _decrypt(_)).WillOnce(InvokeWithoutArgs([]() {
40  ResumptionState res;
41  return std::make_pair(PskType::Resumption, std::move(res));
42  }));
43  EXPECT_CALL(*fallbackCipher, _decrypt(_)).Times(0);
44 
45  auto dualCipher =
46  DualTicketCipher(std::move(cipher), std::move(fallbackCipher));
47  auto buf =
49  dualCipher.decrypt(std::move(buf));
50 }
51 
52 TEST(DualCipherTest, DecryptSuccessWithFallback) {
53  auto cipher = std::make_unique<MockTicketCipher>();
54  auto fallbackCipher = std::make_unique<MockTicketCipher>();
55  ResumptionState resState;
56 
57  EXPECT_CALL(*cipher, _decrypt(_)).WillOnce(InvokeWithoutArgs([]() {
58  ResumptionState res;
59  return std::make_pair(PskType::Rejected, std::move(res));
60  }));
61  EXPECT_CALL(*fallbackCipher, _decrypt(_)).WillOnce(InvokeWithoutArgs([]() {
62  ResumptionState res;
63  return std::make_pair(PskType::Resumption, std::move(res));
64  }));
65 
66  auto dualCipher =
67  DualTicketCipher(std::move(cipher), std::move(fallbackCipher));
68  auto buf =
70  EXPECT_EQ(
71  std::get<0>(dualCipher.decrypt(std::move(buf)).get()),
73 }
74 } // namespace test
75 } // namespace server
76 } // namespace fizz
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
Definition: IOBuf.cpp:353
TEST(GetStatelessHrrTest, NoGroup)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
CipherSuite cipher
Definition: Actions.h:16
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _