Skip to content

Commit 4ccd9db

Browse files
CDRIVER-5773 remove code for MONGODB-CR (#1788)
* add option to check for substring when skipping Useful to skip all "MONGODB-OIDC" tests. OIDC is not-yet implemented. * sync spec tests from commit: mongodb/specifications@82be6f2 * skip tests failing due to known bugs or unimplemented features * remove MONGODB-CR code --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent 70d204f commit 4ccd9db

File tree

13 files changed

+386
-262
lines changed

13 files changed

+386
-262
lines changed

.evergreen/scripts/run-auth-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ echo "Authenticating using PLAIN"
157157
LD_LIBRARY_PATH="${openssl_lib_prefix}" "${ping}" "mongodb://${auth_plain:?}@${auth_host}/?authMechanism=PLAIN&${c_timeout}"
158158

159159
echo "Authenticating using default auth mechanism"
160+
# Though the auth source is named "mongodb-cr", authentication uses the default mechanism (currently SCRAM-SHA-1).
160161
LD_LIBRARY_PATH="${openssl_lib_prefix}" "${ping}" "mongodb://${auth_mongodbcr:?}@${auth_host}/mongodb-cr?${c_timeout}"
161162

162163
if [[ "${sasl}" != "OFF" ]]; then

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 1 addition & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -931,179 +931,6 @@ _cluster_run_hello (mongoc_cluster_t *cluster,
931931
}
932932

933933

934-
/*
935-
*--------------------------------------------------------------------------
936-
*
937-
* _mongoc_cluster_build_basic_auth_digest --
938-
*
939-
* Computes the Basic Authentication digest using the credentials
940-
* configured for @cluster and the @nonce provided.
941-
*
942-
* The result should be freed by the caller using bson_free() when
943-
* they are finished with it.
944-
*
945-
* Returns:
946-
* A newly allocated string containing the digest.
947-
*
948-
* Side effects:
949-
* None.
950-
*
951-
*--------------------------------------------------------------------------
952-
*/
953-
954-
static char *
955-
_mongoc_cluster_build_basic_auth_digest (mongoc_cluster_t *cluster, const char *nonce)
956-
{
957-
const char *username;
958-
const char *password;
959-
char *password_digest;
960-
char *password_md5;
961-
char *digest_in;
962-
char *ret;
963-
964-
ENTRY;
965-
966-
/*
967-
* The following generates the digest to be used for basic authentication
968-
* with a MongoDB server. More information on the format can be found
969-
* at the following location:
970-
*
971-
* https://www.mongodb.com/docs/meta-driver/latest/legacy/
972-
* implement-authentication-in-driver/
973-
*/
974-
975-
BSON_ASSERT (cluster);
976-
BSON_ASSERT (cluster->uri);
977-
978-
username = mongoc_uri_get_username (cluster->uri);
979-
password = mongoc_uri_get_password (cluster->uri);
980-
password_digest = bson_strdup_printf ("%s:mongo:%s", username, password);
981-
password_md5 = _mongoc_hex_md5 (password_digest);
982-
digest_in = bson_strdup_printf ("%s%s%s", nonce, username, password_md5);
983-
ret = _mongoc_hex_md5 (digest_in);
984-
bson_free (digest_in);
985-
bson_free (password_md5);
986-
bson_free (password_digest);
987-
988-
RETURN (ret);
989-
}
990-
991-
992-
/*
993-
*--------------------------------------------------------------------------
994-
*
995-
* _mongoc_cluster_auth_node_cr --
996-
*
997-
* Performs authentication of @node using the credentials provided
998-
* when configuring the @cluster instance.
999-
*
1000-
* This is the Challenge-Response mode of authentication.
1001-
*
1002-
* Returns:
1003-
* true if authentication was successful; otherwise false and
1004-
* @error is set.
1005-
*
1006-
* Side effects:
1007-
* None.
1008-
*
1009-
*--------------------------------------------------------------------------
1010-
*/
1011-
1012-
static bool
1013-
_mongoc_cluster_auth_node_cr (mongoc_cluster_t *cluster,
1014-
mongoc_stream_t *stream,
1015-
mongoc_server_description_t *sd,
1016-
bson_error_t *error)
1017-
{
1018-
mongoc_cmd_parts_t parts;
1019-
bson_iter_t iter;
1020-
const char *auth_source;
1021-
bson_t command;
1022-
bson_t reply;
1023-
char *digest;
1024-
char *nonce;
1025-
bool ret;
1026-
mongoc_server_stream_t *server_stream;
1027-
mc_shared_tpld td;
1028-
1029-
ENTRY;
1030-
1031-
BSON_ASSERT (cluster);
1032-
BSON_ASSERT (stream);
1033-
1034-
if (!(auth_source = mongoc_uri_get_auth_source (cluster->uri)) || (*auth_source == '\0')) {
1035-
auth_source = "admin";
1036-
}
1037-
1038-
/*
1039-
* To authenticate a node using basic authentication, we need to first
1040-
* get the nonce from the server. We use that to hash our password which
1041-
* is sent as a reply to the server. If everything went good we get a
1042-
* success notification back from the server.
1043-
*/
1044-
1045-
/*
1046-
* Execute the getnonce command to fetch the nonce used for generating
1047-
* md5 digest of our password information.
1048-
*/
1049-
bson_init (&command);
1050-
bson_append_int32 (&command, "getnonce", 8, 1);
1051-
mongoc_cmd_parts_init (&parts, cluster->client, auth_source, MONGOC_QUERY_SECONDARY_OK, &command);
1052-
parts.prohibit_lsid = true;
1053-
1054-
td = mc_tpld_take_ref (cluster->client->topology);
1055-
server_stream = _mongoc_cluster_create_server_stream (td.ptr, sd, stream);
1056-
mc_tpld_drop_ref (&td);
1057-
1058-
if (!mongoc_cluster_run_command_parts (cluster, server_stream, &parts, &reply, error)) {
1059-
mongoc_server_stream_cleanup (server_stream);
1060-
bson_destroy (&command);
1061-
bson_destroy (&reply);
1062-
RETURN (false);
1063-
}
1064-
bson_destroy (&command);
1065-
if (!bson_iter_init_find_case (&iter, &reply, "nonce")) {
1066-
bson_set_error (error, MONGOC_ERROR_CLIENT, MONGOC_ERROR_CLIENT_GETNONCE, "Invalid reply from getnonce");
1067-
bson_destroy (&reply);
1068-
RETURN (false);
1069-
}
1070-
1071-
/*
1072-
* Build our command to perform the authentication.
1073-
*/
1074-
nonce = bson_iter_dup_utf8 (&iter, NULL);
1075-
digest = _mongoc_cluster_build_basic_auth_digest (cluster, nonce);
1076-
bson_init (&command);
1077-
bson_append_int32 (&command, "authenticate", 12, 1);
1078-
bson_append_utf8 (&command, "user", 4, mongoc_uri_get_username (cluster->uri), -1);
1079-
bson_append_utf8 (&command, "nonce", 5, nonce, -1);
1080-
bson_append_utf8 (&command, "key", 3, digest, -1);
1081-
bson_destroy (&reply);
1082-
bson_free (nonce);
1083-
bson_free (digest);
1084-
1085-
/*
1086-
* Execute the authenticate command. mongoc_cluster_run_command_private
1087-
* checks for {ok: 1} in the response.
1088-
*/
1089-
mongoc_cmd_parts_init (&parts, cluster->client, auth_source, MONGOC_QUERY_SECONDARY_OK, &command);
1090-
parts.prohibit_lsid = true;
1091-
ret = mongoc_cluster_run_command_parts (cluster, server_stream, &parts, &reply, error);
1092-
1093-
if (!ret) {
1094-
/* error->message is already set */
1095-
error->domain = MONGOC_ERROR_CLIENT;
1096-
error->code = MONGOC_ERROR_CLIENT_AUTHENTICATE;
1097-
}
1098-
1099-
mongoc_server_stream_cleanup (server_stream);
1100-
bson_destroy (&command);
1101-
bson_destroy (&reply);
1102-
1103-
RETURN (ret);
1104-
}
1105-
1106-
1107934
/*
1108935
*--------------------------------------------------------------------------
1109936
*
@@ -1779,9 +1606,7 @@ _mongoc_cluster_auth_node (mongoc_cluster_t *cluster,
17791606
}
17801607
}
17811608

1782-
if (0 == strcasecmp (mechanism, "MONGODB-CR")) {
1783-
ret = _mongoc_cluster_auth_node_cr (cluster, stream, sd, error);
1784-
} else if (0 == strcasecmp (mechanism, "MONGODB-X509")) {
1609+
if (0 == strcasecmp (mechanism, "MONGODB-X509")) {
17851610
ret = _mongoc_cluster_auth_node_x509 (cluster, stream, sd, error);
17861611
} else if (0 == strcasecmp (mechanism, "SCRAM-SHA-1")) {
17871612
ret = _mongoc_cluster_auth_node_scram_sha_1 (cluster, stream, sd, error);

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ mongoc_uri_get_auth_source (const mongoc_uri_t *uri)
19611961
/* Auth spec:
19621962
* "For GSSAPI and MONGODB-X509 authMechanisms the authSource defaults to
19631963
* $external. For PLAIN the authSource defaults to the database name if
1964-
* supplied on the connection string or $external. For MONGODB-CR,
1964+
* supplied on the connection string or $external. For
19651965
* SCRAM-SHA-1 and SCRAM-SHA-256 authMechanisms, the authSource defaults to
19661966
* the database name if supplied on the connection string or admin."
19671967
*/

src/libmongoc/tests/json-test.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,16 @@ test_should_be_skipped (const test_skip_t *skips, const char *description)
19861986
{
19871987
if (skips) {
19881988
for (const test_skip_t *iter = skips; iter->description != NULL; iter++) {
1989-
if (0 == strcmp (description, iter->description)) {
1989+
if (iter->check_substring) {
1990+
if (NULL != strstr (description, iter->description)) {
1991+
fprintf (stderr,
1992+
" - %s SKIPPED (contains '%s'), due to reason: %s\n",
1993+
description,
1994+
iter->description,
1995+
iter->reason);
1996+
return true;
1997+
}
1998+
} else if (0 == strcmp (description, iter->description)) {
19901999
fprintf (stderr, " - %s SKIPPED, due to reason: %s\n", description, iter->reason);
19912000
return true;
19922001
}

src/libmongoc/tests/json-test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef void (*test_hook) (void *test);
3232

3333
typedef struct {
3434
const char *description;
35+
bool check_substring; // If true, check that `description` matches a substring of the test description.
3536
const char *reason;
3637
} test_skip_t;
3738

0 commit comments

Comments
 (0)