Skip to content

Commit bcbbd27

Browse files
authored
SWIFT-1256 Pull in final changes for libmongoc 1.19 (#661)
1 parent b509e82 commit bcbbd27

File tree

10 files changed

+60
-37
lines changed

10 files changed

+60
-37
lines changed

Sources/CLibMongoC/include/CLibMongoC_bson-version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3)
3333
*/
34-
#define BSON_MINOR_VERSION (18)
34+
#define BSON_MINOR_VERSION (19)
3535

3636

3737
/**
@@ -54,7 +54,7 @@
5454
*
5555
* BSON version.
5656
*/
57-
#define BSON_VERSION (1.18.0)
57+
#define BSON_VERSION (1.19.0)
5858

5959

6060
/**
@@ -63,7 +63,7 @@
6363
* BSON version, encoded as a string, useful for printing and
6464
* concatenation.
6565
*/
66-
#define BSON_VERSION_S "1.18.0"
66+
#define BSON_VERSION_S "1.19.0"
6767

6868

6969
/**

Sources/CLibMongoC/include/CLibMongoC_mongoc-version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* MONGOC minor version component (e.g. 2 if %MONGOC_VERSION is 1.2.3)
3333
*/
34-
#define MONGOC_MINOR_VERSION (18)
34+
#define MONGOC_MINOR_VERSION (19)
3535

3636

3737
/**
@@ -55,7 +55,7 @@
5555
*
5656
* MONGOC version.
5757
*/
58-
#define MONGOC_VERSION (1.18.0)
58+
#define MONGOC_VERSION (1.19.0)
5959

6060

6161
/**
@@ -64,7 +64,7 @@
6464
* MONGOC version, encoded as a string, useful for printing and
6565
* concatenation.
6666
*/
67-
#define MONGOC_VERSION_S "1.18.0"
67+
#define MONGOC_VERSION_S "1.19.0"
6868

6969

7070
/**

Sources/CLibMongoC/mongoc/mongoc-cluster.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,7 @@ _mongoc_cluster_stream_for_server (mongoc_cluster_t *cluster,
23212321
mongoc_server_stream_cleanup (server_stream);
23222322
mongoc_cluster_disconnect_node (cluster, server_id);
23232323
bson_mutex_unlock (&topology->mutex);
2324+
_mongoc_bson_init_if_set (reply);
23242325
return NULL;
23252326
}
23262327
}

Sources/CLibMongoC/mongoc/mongoc-cmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,9 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
10221022
}
10231023

10241024
ret = true;
1025-
} else if (server_type == MONGOC_SERVER_MONGOS) {
1025+
} else if (server_type == MONGOC_SERVER_MONGOS ||
1026+
server_stream->topology_type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
1027+
/* TODO (CDRIVER-4117) remove the check of the topology description type. */
10261028
_mongoc_cmd_parts_assemble_mongos (parts, server_stream);
10271029
ret = true;
10281030
} else {

Sources/CLibMongoC/mongoc/mongoc-server-description-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,10 @@ bool
200200
mongoc_server_description_has_service_id (
201201
const mongoc_server_description_t *description);
202202

203+
/* mongoc_global_mock_service_id is only used for testing. The test runner sets
204+
* this to true when testing against a load balanced deployment to mock the
205+
* presence of a serviceId field in the "hello" response. The purpose of this is
206+
* further described in the Load Balancer test README. */
207+
extern bool mongoc_global_mock_service_id;
208+
203209
#endif

Sources/CLibMongoC/mongoc/mongoc-server-description.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static bson_oid_t kObjectIdZero = {{0}};
3333

3434
const bson_oid_t kZeroServiceId = {{0}};
3535

36+
bool mongoc_global_mock_service_id = false;
37+
3638
static bool
3739
_match_tag_set (const mongoc_server_description_t *sd,
3840
bson_iter_t *tag_set_iter);
@@ -735,6 +737,16 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
735737
}
736738
}
737739

740+
741+
if (mongoc_global_mock_service_id) {
742+
bson_iter_t pid_iter;
743+
744+
if (bson_iter_init_find (&pid_iter, &sd->topology_version, "processId") &&
745+
BSON_ITER_HOLDS_OID (&pid_iter)) {
746+
bson_oid_copy (bson_iter_oid (&pid_iter), &sd->service_id);
747+
}
748+
}
749+
738750
if (is_shard) {
739751
sd->type = MONGOC_SERVER_MONGOS;
740752
} else if (sd->set_name) {

Sources/CLibMongoC/mongoc/mongoc-uri.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,6 @@ mongoc_uri_finalize_auth (mongoc_uri_t *uri,
13391339
if (bson_iter_init_find_case (
13401340
&iter, &uri->credentials, MONGOC_URI_AUTHSOURCE)) {
13411341
source = bson_iter_utf8 (&iter, NULL);
1342-
require_auth = true;
13431342
}
13441343

13451344
if (mongoc_uri_get_auth_mechanism (uri)) {

Sources/MongoSwift/ConnectionString.swift

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,38 +242,47 @@ internal class ConnectionString {
242242

243243
/// Sets and validates authentication-related on the underlying `mongoc_uri_t`.
244244
private func applyAndValidateAuthOptions(_ options: MongoClientOptions?) throws {
245-
guard let credential = options?.credential else {
246-
return
247-
}
245+
if let credential = options?.credential {
246+
if let username = credential.username {
247+
guard mongoc_uri_set_username(self._uri, username) else {
248+
throw self.failedToSet("username", to: username)
249+
}
250+
}
248251

249-
if let username = credential.username {
250-
guard mongoc_uri_set_username(self._uri, username) else {
251-
throw self.failedToSet("username", to: username)
252+
if let password = credential.password {
253+
guard mongoc_uri_set_password(self._uri, password) else {
254+
throw MongoError.InvalidArgumentError(message: "Failed to set password")
255+
}
252256
}
253-
}
254257

255-
if let password = credential.password {
256-
guard mongoc_uri_set_password(self._uri, password) else {
257-
throw MongoError.InvalidArgumentError(message: "Failed to set password")
258+
if let authSource = credential.source {
259+
guard mongoc_uri_set_auth_source(self._uri, authSource) else {
260+
throw self.failedToSet(MONGOC_URI_AUTHSOURCE, to: authSource)
261+
}
258262
}
259-
}
260263

261-
if let authSource = credential.source {
262-
guard mongoc_uri_set_auth_source(self._uri, authSource) else {
263-
throw self.failedToSet(MONGOC_URI_AUTHSOURCE, to: authSource)
264+
if let mechanism = credential.mechanism {
265+
guard mongoc_uri_set_auth_mechanism(self._uri, mechanism.name) else {
266+
throw self.failedToSet(MONGOC_URI_AUTHMECHANISM, to: mechanism)
267+
}
264268
}
265-
}
266269

267-
if let mechanism = credential.mechanism {
268-
guard mongoc_uri_set_auth_mechanism(self._uri, mechanism.name) else {
269-
throw self.failedToSet(MONGOC_URI_AUTHMECHANISM, to: mechanism)
270+
try credential.mechanismProperties?.withBSONPointer { mechanismPropertiesPtr in
271+
guard mongoc_uri_set_mechanism_properties(self._uri, mechanismPropertiesPtr) else {
272+
let desc = String(describing: credential.mechanismProperties)
273+
throw self.failedToSet(MONGOC_URI_AUTHMECHANISMPROPERTIES, to: desc)
274+
}
270275
}
271276
}
272277

273-
try credential.mechanismProperties?.withBSONPointer { mechanismPropertiesPtr in
274-
guard mongoc_uri_set_mechanism_properties(self._uri, mechanismPropertiesPtr) else {
275-
let desc = String(describing: credential.mechanismProperties)
276-
throw self.failedToSet(MONGOC_URI_AUTHMECHANISMPROPERTIES, to: desc)
278+
// libmongoc incorrectly permits an empty string as auth source. this logic could be removed once CDRIVER-3517
279+
// is complete (Swift work tracked by SWIFT-1298), however we are likely to be using the pure Swift URI parser
280+
// by the time that happens anyway.
281+
if let authSource = self.authSource {
282+
guard !authSource.isEmpty else {
283+
throw MongoError.InvalidArgumentError(
284+
message: "\(MONGOC_URI_AUTHSOURCE) cannot be set to an empty string"
285+
)
277286
}
278287
}
279288
}

Tests/MongoSwiftTests/AuthTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ final class AuthTests: MongoSwiftTestCase {
2727

2828
for (_, file) in testFiles {
2929
for testCase in file.tests {
30-
// skipping due to CDRIVER-3517
31-
// TODO: SWIFT-1298 unskip this test
32-
guard testCase.description != "must raise an error when the authSource is empty" else {
33-
continue
34-
}
35-
3630
guard testCase.valid else {
3731
expect(try ConnectionString(testCase.uri))
3832
.to(

etc/vendor-libmongoc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eou pipefail
44

55
PWD=`pwd`
66
LIBMONGOC_MAJOR_VERSION=1
7-
LIBMONGOC_MINOR_VERSION=18
7+
LIBMONGOC_MINOR_VERSION=19
88
LIBMONGOC_PATCH_VERSION=0
99
LIBMONGOC_PRERELEASE_VERSION=
1010

0 commit comments

Comments
 (0)