proxygen
TLSTicketKeyManagerTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 #include <gtest/gtest.h>
18 #include <wangle/ssl/SSLStats.h>
20 
21 using ::testing::InSequence;
22 
24  public:
26 
27  // downstream
28  void recordSSLAcceptLatency(int64_t /* unused */) noexcept override {}
29  void recordTLSTicket(bool /* unused */, bool /* unused */) noexcept override {
30  }
32  bool /* unused */,
33  bool /* unused */,
34  bool /* unused */) noexcept override {}
35  void recordSSLSessionRemove() noexcept override {}
36  void recordSSLSessionFree(uint32_t /* unused */) noexcept override {}
37  void recordSSLSessionSetError(uint32_t /* unused */) noexcept override {}
38  void recordSSLSessionGetError(uint32_t /* unused */) noexcept override {}
41 
42  // upstream
43  void recordSSLUpstreamConnection(bool /* unused */) noexcept override {}
44  void recordSSLUpstreamConnectionError(bool /* unused */) noexcept override {}
45 };
46 
47 TEST(TLSTicketKeyManager, TestSetGetTLSTicketKeySeeds) {
48  std::vector<std::string> origOld = {"67"};
49  std::vector<std::string> origCurr = {"68"};
50  std::vector<std::string> origNext = {"69"};
51 
53  wangle::TLSTicketKeyManager manager(&ctx, nullptr);
54 
55  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
56  std::vector<std::string> old;
57  std::vector<std::string> curr;
58  std::vector<std::string> next;
59  manager.getTLSTicketKeySeeds(old, curr, next);
60  ASSERT_EQ(origOld, old);
61  ASSERT_EQ(origCurr, curr);
62  ASSERT_EQ(origNext, next);
63 }
64 
65 TEST(TLSTicketKeyManager, TestValidateTicketSeedsSuccess) {
66  MockSSLStats stats;
67  EXPECT_CALL(stats, recordTLSTicketRotation(true)).Times(2);
68 
69  std::vector<std::string> origOld = {"67", "77"};
70  std::vector<std::string> origCurr = {"68", "78"};
71  std::vector<std::string> origNext = {"69", "79"};
72 
73  // The new ticket seeds are compatible
74  std::vector<std::string> newOld = {"68", "78"};
75  std::vector<std::string> newCurr = {"69", "79"};
76  std::vector<std::string> newNext = {"70", "80"};
77 
79  wangle::TLSTicketKeyManager manager(&ctx, &stats);
80 
81  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
82  manager.setTLSTicketKeySeeds(newOld, newCurr, newNext);
83 }
84 
85 TEST(TLSTicketKeyManager, TestValidateTicketSeedsIdempotent) {
86  MockSSLStats stats;
87  EXPECT_CALL(stats, recordTLSTicketRotation(true)).Times(2);
88 
89  std::vector<std::string> origOld = {"67", "77"};
90  std::vector<std::string> origCurr = {"68", "78"};
91  std::vector<std::string> origNext = {"69", "79"};
92 
94  wangle::TLSTicketKeyManager manager(&ctx, &stats);
95 
96  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
97  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
98 }
99 
100 TEST(TLSTicketKeyManager, TestValidateTicketSeedsFailure) {
101  MockSSLStats stats;
102  InSequence inSequence;
103  EXPECT_CALL(stats, recordTLSTicketRotation(true)).Times(1);
104  EXPECT_CALL(stats, recordTLSTicketRotation(false)).Times(1);
105 
106  std::vector<std::string> origOld = {"67", "77"};
107  std::vector<std::string> origCurr = {"68", "78"};
108  std::vector<std::string> origNext = {"69", "79"};
109 
110  // The new seeds are incompatible
111  std::vector<std::string> newOld = {"69", "79"};
112  std::vector<std::string> newCurr = {"70", "80"};
113  std::vector<std::string> newNext = {"71", "81"};
114 
115  folly::SSLContext ctx;
116  wangle::TLSTicketKeyManager manager(&ctx, &stats);
117 
118  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
119  manager.setTLSTicketKeySeeds(newOld, newCurr, newNext);
120 }
121 
122 TEST(TLSTicketKeyManager, TestValidateTicketSeedsSubsetPass) {
123  MockSSLStats stats;
124  InSequence inSequence;
125  EXPECT_CALL(stats, recordTLSTicketRotation(true)).Times(2);
126 
127  std::vector<std::string> origOld = {"67"};
128  std::vector<std::string> origCurr = {"68"};
129  std::vector<std::string> origNext = {"69"};
130 
131  // The new ticket seeds are compatible
132  std::vector<std::string> newOld = {"68", "78"};
133  std::vector<std::string> newCurr = {"69"};
134  std::vector<std::string> newNext = {"70", "80"};
135 
136  folly::SSLContext ctx;
137  wangle::TLSTicketKeyManager manager(&ctx, &stats);
138 
139  manager.setTLSTicketKeySeeds(origOld, origCurr, origNext);
140  manager.setTLSTicketKeySeeds(newOld, newCurr, newNext);
141 }
void recordSSLSession(bool, bool, bool) noexceptoverride
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
MOCK_QUALIFIED_METHOD1(recordTLSTicketRotation, noexcept, void(bool valid))
void recordTLSTicket(bool, bool) noexceptoverride
TEST(TLSTicketKeyManager, TestSetGetTLSTicketKeySeeds)
void recordSSLSessionSetError(uint32_t) noexceptoverride
void recordSSLSessionFree(uint32_t) noexceptoverride
requires E e noexcept(noexcept(s.error(std::move(e))))
void recordSSLClientCertificateMismatch() noexceptoverride
void recordSSLSessionGetError(uint32_t) noexceptoverride
void recordSSLUpstreamConnection(bool) noexceptoverride
void recordClientRenegotiation() noexceptoverride
void recordSSLSessionRemove() noexceptoverride
void recordSSLAcceptLatency(int64_t) noexceptoverride
#define EXPECT_CALL(obj, call)
void recordSSLUpstreamConnectionError(bool) noexceptoverride
virtual void recordTLSTicketRotation(bool valid) noexcept=0
def next(obj)
Definition: ast.py:58