SSLErrorsTest.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2016-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. */
  16. #include <folly/io/async/ssl/SSLErrors.h>
  17. #include <folly/portability/GTest.h>
  18. #include <folly/portability/OpenSSL.h>
  19. using namespace testing;
  20. using namespace folly;
  21. TEST(SSLErrorsTest, TestMessage) {
  22. ERR_load_crypto_strings();
  23. unsigned long err;
  24. #ifdef OPENSSL_IS_BORINGSSL
  25. err = ERR_PACK(ERR_LIB_X509, X509_R_CERT_ALREADY_IN_HASH_TABLE);
  26. #else
  27. err = ERR_PACK(
  28. ERR_LIB_X509,
  29. X509_F_X509_STORE_ADD_CERT,
  30. X509_R_CERT_ALREADY_IN_HASH_TABLE);
  31. #endif
  32. SSLException ex(0, err, 0, 0);
  33. // This is flaky - we should not be testing error strings
  34. // which may change version to version
  35. #if defined(OPENSSL_IS_BORINGSSL)
  36. std::string expectedMsg =
  37. "AsyncSocketException: error:0b000069:X.509 certificate routines:"
  38. "OPENSSL_internal:CERT_ALREADY_IN_HASH_TABLE, type = SSL error";
  39. #else
  40. std::string expectedMsg =
  41. "AsyncSocketException: error:0B07C065:"
  42. "x509 certificate routines:X509_STORE_add_cert:"
  43. "cert already in hash table, type = SSL error";
  44. #endif
  45. std::string actual = ex.what();
  46. EXPECT_EQ(expectedMsg, actual);
  47. }