proxygen
SSLSessionCallbackTest.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>
20 #include <vector>
21 #include <map>
22 
23 using namespace testing;
24 using namespace wangle;
25 
26 using folly::SSLContext;
27 
28 // One time use cache for testing that uses size_t as the cache key
30  public:
32  const std::string& key,
33  SSLSessionPtr session) noexcept override {
34  cache_.emplace(key, std::move(session));
35  }
36 
37  SSLSessionPtr getSSLSession(const std::string& key) const noexcept override {
38  auto it = cache_.find(key);
39  if (it == cache_.end()) {
40  return SSLSessionPtr(nullptr);
41  }
42  auto sess = std::move(it->second);
43  cache_.erase(it);
44  return sess;
45  }
46 
47  bool removeSSLSession(const std::string&) noexcept override {
48  return true;
49  }
50 
51  size_t size() const override {
52  return cache_.size();
53  }
54 
55  private:
56  mutable std::map<std::string, SSLSessionPtr> cache_;
57 };
58 
59 
60 TEST(SSLSessionCallbackTest, AttachMultiple) {
61  SSLContext c1;
62  SSLContext c2;
66 
69  EXPECT_EQ(cb1, cb2);
70 
73 
74  FakeSessionCallbacks unused;
77  EXPECT_EQ(&cb, cb2);
78 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SSLSessionPtr getSSLSession(const std::string &key) const noexceptoverride
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
size_t size() const override
std::map< std::string, SSLSessionPtr > cache_
SSL_CTX * getSSLCtx() const
Definition: SSLContext.h:503
TEST(GTestEnvVarTest, Dummy)
static void attachCallbacksToContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
static void detachCallbacksFromContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
const char * string
Definition: Conv.cpp:212
static SSLSessionCallbacks * getCacheFromContext(SSL_CTX *ctx)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
bool removeSSLSession(const std::string &) noexceptoverride
void setSSLSession(const std::string &key, SSLSessionPtr session) noexceptoverride