Skip to content

Commit 4b1c775

Browse files
authored
Clear existing users before running /scram tests (#1215)
1 parent d44babf commit 4b1c775

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/libmongoc/tests/test-mongoc-scram.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ test_mongoc_scram_sasl_prep (void)
132132
}
133133
#endif
134134

135+
static void
136+
_clear_scram_users (void)
137+
{
138+
mongoc_client_t *const client = test_framework_new_default_client ();
139+
ASSERT (client);
140+
mongoc_database_t *const db = mongoc_client_get_database (client, "admin");
141+
ASSERT (db);
142+
(void) mongoc_database_remove_user (db, "sha1", NULL);
143+
(void) mongoc_database_remove_user (db, "sha256", NULL);
144+
(void) mongoc_database_remove_user (db, "both", NULL);
145+
mongoc_database_destroy (db);
146+
mongoc_client_destroy (client);
147+
}
148+
135149
static void
136150
_create_scram_users (void)
137151
{
@@ -424,6 +438,8 @@ test_mongoc_scram_auth (void *ctx)
424438
{
425439
BSON_UNUSED (ctx);
426440

441+
_clear_scram_users ();
442+
427443
/* Auth spec: "Create three test users, one with only SHA-1, one with only
428444
* SHA-256 and one with both" */
429445
_create_scram_users ();
@@ -483,6 +499,19 @@ skip_if_icu (void)
483499
return !skip_if_no_icu ();
484500
}
485501

502+
static void
503+
_clear_saslprep_users (void)
504+
{
505+
mongoc_client_t *const client = test_framework_new_default_client ();
506+
ASSERT (client);
507+
mongoc_database_t *const db = mongoc_client_get_database (client, "admin");
508+
ASSERT (db);
509+
(void) mongoc_database_remove_user (db, "IX", NULL);
510+
(void) mongoc_database_remove_user (db, ROMAN_NUMERAL_NINE, NULL);
511+
mongoc_database_destroy (db);
512+
mongoc_client_destroy (client);
513+
}
514+
486515
static void
487516
_create_saslprep_users (void)
488517
{
@@ -607,6 +636,7 @@ test_mongoc_saslprep_auth (void *ctx)
607636
{
608637
BSON_UNUSED (ctx);
609638

639+
_clear_saslprep_users ();
610640
_create_saslprep_users ();
611641
_test_mongoc_scram_saslprep_auth (false);
612642
_test_mongoc_scram_saslprep_auth (true);
@@ -632,6 +662,7 @@ test_mongoc_saslprep_auth_no_icu (void *ctx)
632662
{
633663
BSON_UNUSED (ctx);
634664

665+
_clear_saslprep_users ();
635666
_create_saslprep_users ();
636667
_test_mongoc_scram_saslprep_auth_no_icu (false);
637668
_test_mongoc_scram_saslprep_auth_no_icu (true);

0 commit comments

Comments
 (0)