proxygen
SSLContextInitializationTest.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 <functional>
18 
19 #include <folly/init/Init.h>
22 #include <folly/ssl/Init.h>
23 
24 namespace folly {
25 
26 void setupSSLLocks() {
28 #ifdef CRYPTO_LOCK_EVP_PKEY
29  {CRYPTO_LOCK_EVP_PKEY, folly::ssl::LockType::NONE},
30 #endif
31 #ifdef CRYPTO_LOCK_SSL_SESSION
32  {CRYPTO_LOCK_SSL_SESSION, folly::ssl::LockType::SPINLOCK},
33 #endif
34 #ifdef CRYPTO_LOCK_SSL_CTX
35  {CRYPTO_LOCK_SSL_CTX, folly::ssl::LockType::NONE}
36 #endif
37  });
38 }
39 
40 TEST(SSLContextInitializationTest, SSLContextInitializeThenSetLocksAndInit) {
41  EXPECT_DEATH(
42  {
45  },
46  "OpenSSL is already initialized");
47 }
48 
49 TEST(SSLContextInitializationTest, SSLContextSetLocksAndInitialize) {
50  EXPECT_DEATH(
51  {
54  },
55  "OpenSSL is already initialized");
56 }
57 
58 TEST(SSLContextInitializationTest, SSLContextLocks) {
59  EXPECT_EXIT(
60  {
61  setupSSLLocks();
63 #ifdef CRYPTO_LOCK_EVP_PKEY
64  EXPECT_TRUE(folly::ssl::isLockDisabled(CRYPTO_LOCK_EVP_PKEY));
65 #endif
66 #ifdef CRYPTO_LOCK_SSL_SESSION
67  EXPECT_FALSE(folly::ssl::isLockDisabled(CRYPTO_LOCK_SSL_SESSION));
68 #endif
69 #ifdef CRYPTO_LOCK_ERR
70  EXPECT_FALSE(folly::ssl::isLockDisabled(CRYPTO_LOCK_ERR));
71 #endif
72  if (::testing::Test::HasFailure()) {
73  exit(1);
74  }
75  LOG(INFO) << "SSLContextLocks passed";
76  exit(0);
77  },
78  ::testing::ExitedWithCode(0),
79  "SSLContextLocks passed");
80 }
81 
82 TEST(SSLContextInitializationTest, SSLContextLocksSetAfterInitIgnored) {
83  EXPECT_EXIT(
84  {
85  setupSSLLocks();
88 #ifdef CRYPTO_LOCK_EVP_PKEY
89  EXPECT_TRUE(folly::ssl::isLockDisabled(CRYPTO_LOCK_EVP_PKEY));
90 #endif
91  if (::testing::Test::HasFailure()) {
92  exit(1);
93  }
94  LOG(INFO) << "SSLContextLocksSetAfterInitIgnored passed";
95  exit(0);
96  },
97  ::testing::ExitedWithCode(0),
98  "SSLContextLocksSetAfterInitIgnored passed");
99 }
100 } // namespace folly
101 
102 int main(int argc, char* argv[]) {
103 #ifdef SIGPIPE
104  signal(SIGPIPE, SIG_IGN);
105 #endif
106  testing::InitGoogleTest(&argc, argv);
107  folly::init(&argc, &argv);
108 
109  return RUN_ALL_TESTS();
110 }
void setLockTypes(LockTypeMapping inLockTypes)
Definition: Init.cpp:76
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
static bool HasFailure()
Definition: gtest.h:407
void init()
Definition: Init.cpp:54
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
char ** argv
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370
void setLockTypesAndInit(LockTypeMapping inLockTypes)
Definition: Init.cpp:69
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
bool isLockDisabled(int lockId)
Definition: Init.cpp:91
TEST(SequencedExecutor, CPUThreadPoolExecutor)
int main(int argc, char *argv[])