Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXX-2745 fix missing include directives for SSL-related config macros #1333

Merged
merged 5 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mongocxx/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ set_dist_list(src_mongocxx_lib_DIST
mongocxx/private/scoped_bson_value.hh
mongocxx/private/search_index_model.hh
mongocxx/private/search_index_view.hh
mongocxx/private/ssl.hh
mongocxx/private/uri.hh
mongocxx/private/write_concern.hh
mongocxx/v_noabi/mongocxx/gridfs/bucket.hh
Expand Down
24 changes: 24 additions & 0 deletions src/mongocxx/lib/mongocxx/private/ssl.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <mongocxx/private/config/config.hh>
#include <mongocxx/private/mongoc.hh>

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#define MONGOCXX_SSL_IS_ENABLED() true
#else
#define MONGOCXX_SSL_IS_ENABLED() false
#endif
5 changes: 3 additions & 2 deletions src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <mongocxx/private/pipeline.hh>
#include <mongocxx/private/read_concern.hh>
#include <mongocxx/private/read_preference.hh>
#include <mongocxx/private/ssl.hh>
#include <mongocxx/private/uri.hh>
#include <mongocxx/private/write_concern.hh>

Expand Down Expand Up @@ -74,7 +75,7 @@ class database_names {
client::client() noexcept = default;

client::client(mongocxx::v_noabi::uri const& uri, options::client const& options) {
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
if (options.tls_opts()) {
if (!uri.tls())
throw exception{error_code::k_invalid_parameter, "cannot set TLS options if 'tls=true' not in URI"};
Expand Down Expand Up @@ -127,7 +128,7 @@ client::client(mongocxx::v_noabi::uri const& uri, options::client const& options
}
}

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
if (options.tls_opts()) {
auto mongoc_opts = options::make_tls_opts(*options.tls_opts());
_impl->tls_options = std::move(mongoc_opts.second);
Expand Down
3 changes: 2 additions & 1 deletion src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include <list>

#include <mongocxx/private/mongoc.hh>
#include <mongocxx/private/ssl.hh>

namespace mongocxx {
namespace v_noabi {
namespace options {

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
inline std::pair<::mongoc_ssl_opt_t, std::list<bsoncxx::v_noabi::string::view_or_value>> make_tls_opts(
tls const& tls_opts) {
::mongoc_ssl_opt_t out{};
Expand Down
3 changes: 2 additions & 1 deletion src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <mongocxx/private/client.hh>
#include <mongocxx/private/mongoc_error.hh>
#include <mongocxx/private/pool.hh>
#include <mongocxx/private/ssl.hh>
#include <mongocxx/private/uri.hh>

namespace mongocxx {
Expand Down Expand Up @@ -57,7 +58,7 @@ pool::~pool() = default;

pool::pool(uri const& uri, options::pool const& options)
: _impl{bsoncxx::make_unique<impl>(construct_client_pool(uri._impl->uri_t))} {
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
if (options.client_opts().tls_opts()) {
if (!uri.tls())
throw exception{error_code::k_invalid_parameter, "cannot set TLS options if 'tls=true' not in URI"};
Expand Down
5 changes: 3 additions & 2 deletions src/mongocxx/test/catch_helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <mongocxx/exception/exception.hpp>

#include <mongocxx/private/mongoc.hh>
#include <mongocxx/private/ssl.hh>

#include <bsoncxx/test/catch.hh>

Expand Down Expand Up @@ -73,7 +74,7 @@ class mongocxx_exception_matcher : public Catch::Matchers::MatcherBase<mongocxx:
auto client_pool_try_pop = libmongoc::client_pool_try_pop.create_instance(); \
((void)0)

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
#define MOCK_POOL \
MOCK_POOL_NOSSL; \
auto client_pool_set_ssl_opts = libmongoc::client_pool_set_ssl_opts.create_instance(); \
Expand Down Expand Up @@ -101,7 +102,7 @@ class mongocxx_exception_matcher : public Catch::Matchers::MatcherBase<mongocxx:
auto client_find_databases_with_opts = mongocxx::libmongoc::client_find_databases_with_opts.create_instance(); \
((void)0)

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
#define MOCK_CLIENT \
MOCK_CLIENT_NOSSL; \
auto client_set_ssl_opts = libmongoc::client_set_ssl_opts.create_instance(); \
Expand Down
3 changes: 2 additions & 1 deletion src/mongocxx/test/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <mongocxx/private/conversions.hh>
#include <mongocxx/private/mongoc.hh>
#include <mongocxx/private/ssl.hh>

#include <bsoncxx/test/catch.hh>

Expand Down Expand Up @@ -423,7 +424,7 @@ TEST_CASE("integration tests for client metadata handshake feature") {
}
}

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
TEST_CASE("A client can be constructed with SSL options", "[client]") {
MOCK_CLIENT;

Expand Down
3 changes: 2 additions & 1 deletion src/mongocxx/test/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mongocxx/pool.hpp>

#include <mongocxx/private/mongoc.hh>
#include <mongocxx/private/ssl.hh>

#include <bsoncxx/test/catch.hh>

Expand Down Expand Up @@ -64,7 +65,7 @@ TEST_CASE("a pool is created with the correct MongoDB URI", "[pool]") {
REQUIRE(destroy_called);
}

#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
#if MONGOCXX_SSL_IS_ENABLED()
TEST_CASE(
"If we pass an engaged SSL options struct to the pool class, we will use it to configure the "
"underlying mongoc pool",
Expand Down