Skip to content

Clear existing users before running /scram tests #1215

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

Merged
merged 1 commit into from
Mar 9, 2023
Merged
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
31 changes: 31 additions & 0 deletions src/libmongoc/tests/test-mongoc-scram.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ test_mongoc_scram_sasl_prep (void)
}
#endif

static void
_clear_scram_users (void)
{
mongoc_client_t *const client = test_framework_new_default_client ();
ASSERT (client);
mongoc_database_t *const db = mongoc_client_get_database (client, "admin");
ASSERT (db);
(void) mongoc_database_remove_user (db, "sha1", NULL);
(void) mongoc_database_remove_user (db, "sha256", NULL);
(void) mongoc_database_remove_user (db, "both", NULL);
mongoc_database_destroy (db);
mongoc_client_destroy (client);
}

static void
_create_scram_users (void)
{
Expand Down Expand Up @@ -424,6 +438,8 @@ test_mongoc_scram_auth (void *ctx)
{
BSON_UNUSED (ctx);

_clear_scram_users ();

/* Auth spec: "Create three test users, one with only SHA-1, one with only
* SHA-256 and one with both" */
_create_scram_users ();
Expand Down Expand Up @@ -483,6 +499,19 @@ skip_if_icu (void)
return !skip_if_no_icu ();
}

static void
_clear_saslprep_users (void)
{
mongoc_client_t *const client = test_framework_new_default_client ();
ASSERT (client);
mongoc_database_t *const db = mongoc_client_get_database (client, "admin");
ASSERT (db);
(void) mongoc_database_remove_user (db, "IX", NULL);
(void) mongoc_database_remove_user (db, ROMAN_NUMERAL_NINE, NULL);
mongoc_database_destroy (db);
mongoc_client_destroy (client);
}

static void
_create_saslprep_users (void)
{
Expand Down Expand Up @@ -607,6 +636,7 @@ test_mongoc_saslprep_auth (void *ctx)
{
BSON_UNUSED (ctx);

_clear_saslprep_users ();
_create_saslprep_users ();
_test_mongoc_scram_saslprep_auth (false);
_test_mongoc_scram_saslprep_auth (true);
Expand All @@ -632,6 +662,7 @@ test_mongoc_saslprep_auth_no_icu (void *ctx)
{
BSON_UNUSED (ctx);

_clear_saslprep_users ();
_create_saslprep_users ();
_test_mongoc_scram_saslprep_auth_no_icu (false);
_test_mongoc_scram_saslprep_auth_no_icu (true);
Expand Down