Skip to content

Commit 488c3e5

Browse files
committed
support unified tests
1 parent 9705893 commit 488c3e5

15 files changed

+1822
-89
lines changed

src/libmongoc/src/mongoc/mongoc-util-private.h

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ mongoc_ends_with (const char *str, const char *suffix);
100100
void
101101
mongoc_lowercase (const char *src, char *buf /* OUT */);
102102

103+
void
104+
mongoc_lowercase_inplace (char *src);
105+
103106
bool
104107
mongoc_parse_port (uint16_t *port, const char *str);
105108

src/libmongoc/src/mongoc/mongoc-util.c

+12
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,18 @@ mongoc_lowercase (const char *src, char *buf /* OUT */)
526526
}
527527
}
528528

529+
void
530+
mongoc_lowercase_inplace (char *src)
531+
{
532+
for (; *src; ++src) {
533+
/* UTF8 non-ascii characters have a 1 at the leftmost bit. If this is the
534+
* case, just copy */
535+
if ((*src & (0x1 << 7)) == 0) {
536+
*src = (char) tolower (*src);
537+
}
538+
}
539+
}
540+
529541
bool
530542
mongoc_parse_port (uint16_t *port, const char *str)
531543
{

src/libmongoc/tests/json-test.c

+23-23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "json-test-operations.h"
2929
#include "json-test-monitoring.h"
3030
#include "TestSuite.h"
31+
#include "test-conveniences.h"
3132
#include "test-libmongoc.h"
3233

3334
#ifdef _MSC_VER
@@ -1354,10 +1355,9 @@ set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts)
13541355
}
13551356
}
13561357

1357-
static void
1358-
set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
1358+
void
1359+
set_auto_encryption_opts (mongoc_client_t *client, bson_t *opts)
13591360
{
1360-
bson_t opts;
13611361
bson_iter_t iter;
13621362
mongoc_auto_encryption_opts_t *auto_encryption_opts;
13631363
bson_error_t error;
@@ -1366,14 +1366,9 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
13661366

13671367
ASSERT (client);
13681368

1369-
if (!bson_has_field (test, "clientOptions.autoEncryptOpts")) {
1370-
return;
1371-
}
1372-
1373-
bson_lookup_doc (test, "clientOptions.autoEncryptOpts", &opts);
13741369
auto_encryption_opts = mongoc_auto_encryption_opts_new ();
13751370

1376-
if (bson_iter_init_find (&iter, &opts, "kmsProviders")) {
1371+
if (bson_iter_init_find (&iter, opts, "kmsProviders")) {
13771372
bson_t kms_providers = BSON_INITIALIZER;
13781373
bson_t tls_opts = BSON_INITIALIZER;
13791374
bson_t tmp;
@@ -1383,7 +1378,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
13831378
&tmp, &kms_providers, "aws", "awsTemporary", "awsTemporaryNoSessionToken", "azure", "gcp", "kmip", NULL);
13841379

13851380
/* AWS credentials are set from environment variables. */
1386-
if (bson_has_field (&opts, "kmsProviders.aws")) {
1381+
if (bson_has_field (opts, "kmsProviders.aws")) {
13871382
char *const secret_access_key = test_framework_getenv ("MONGOC_TEST_AWS_SECRET_ACCESS_KEY");
13881383
char *const access_key_id = test_framework_getenv ("MONGOC_TEST_AWS_ACCESS_KEY_ID");
13891384

@@ -1408,9 +1403,9 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
14081403
bson_free (access_key_id);
14091404
}
14101405

1411-
const bool need_aws_with_session_token = bson_has_field (&opts, "kmsProviders.awsTemporary");
1406+
const bool need_aws_with_session_token = bson_has_field (opts, "kmsProviders.awsTemporary");
14121407
const bool need_aws_with_temp_creds =
1413-
need_aws_with_session_token || bson_has_field (&opts, "kmsProviders.awsTemporaryNoSessionToken");
1408+
need_aws_with_session_token || bson_has_field (opts, "kmsProviders.awsTemporaryNoSessionToken");
14141409

14151410
if (need_aws_with_temp_creds) {
14161411
char *const secret_access_key = test_framework_getenv ("MONGOC_TEST_AWS_TEMP_SECRET_ACCESS_KEY");
@@ -1449,7 +1444,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
14491444
bson_free (session_token);
14501445
}
14511446

1452-
if (bson_has_field (&opts, "kmsProviders.azure")) {
1447+
if (bson_has_field (opts, "kmsProviders.azure")) {
14531448
char *azure_tenant_id;
14541449
char *azure_client_id;
14551450
char *azure_client_secret;
@@ -1477,7 +1472,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
14771472
bson_free (azure_client_secret);
14781473
}
14791474

1480-
if (bson_has_field (&opts, "kmsProviders.gcp")) {
1475+
if (bson_has_field (opts, "kmsProviders.gcp")) {
14811476
char *gcp_email;
14821477
char *gcp_privatekey;
14831478

@@ -1497,7 +1492,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
14971492
bson_free (gcp_privatekey);
14981493
}
14991494

1500-
if (bson_has_field (&opts, "kmsProviders.kmip")) {
1495+
if (bson_has_field (opts, "kmsProviders.kmip")) {
15011496
char *kmip_tls_ca_file;
15021497
char *kmip_tls_certificate_key_file;
15031498

@@ -1527,23 +1522,23 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
15271522
bson_destroy (&tls_opts);
15281523
}
15291524

1530-
if (bson_iter_init_find (&iter, &opts, "schemaMap")) {
1525+
if (bson_iter_init_find (&iter, opts, "schemaMap")) {
15311526
bson_t schema_map;
15321527

15331528
bson_iter_bson (&iter, &schema_map);
15341529
mongoc_auto_encryption_opts_set_schema_map (auto_encryption_opts, &schema_map);
15351530
bson_destroy (&schema_map);
15361531
}
15371532

1538-
if (bson_iter_init_find (&iter, &opts, "bypassAutoEncryption")) {
1533+
if (bson_iter_init_find (&iter, opts, "bypassAutoEncryption")) {
15391534
mongoc_auto_encryption_opts_set_bypass_auto_encryption (auto_encryption_opts, bson_iter_as_bool (&iter));
15401535
}
15411536

1542-
if (bson_iter_init_find (&iter, &opts, "bypassQueryAnalysis")) {
1537+
if (bson_iter_init_find (&iter, opts, "bypassQueryAnalysis")) {
15431538
mongoc_auto_encryption_opts_set_bypass_query_analysis (auto_encryption_opts, bson_iter_as_bool (&iter));
15441539
}
15451540

1546-
if (bson_iter_init_find (&iter, &opts, "keyVaultNamespace")) {
1541+
if (bson_iter_init_find (&iter, opts, "keyVaultNamespace")) {
15471542
const char *keyvault_ns;
15481543
char *db_name;
15491544
char *coll_name;
@@ -1565,7 +1560,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
15651560
mongoc_auto_encryption_opts_set_keyvault_namespace (auto_encryption_opts, "keyvault", "datakeys");
15661561
}
15671562

1568-
if (bson_iter_init_find (&iter, &opts, "extra")) {
1563+
if (bson_iter_init_find (&iter, opts, "extra")) {
15691564
bson_t tmp;
15701565

15711566
bson_iter_bson (&iter, &tmp);
@@ -1574,7 +1569,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
15741569
bson_init (&extra);
15751570
}
15761571

1577-
if (bson_iter_init_find (&iter, &opts, "encryptedFieldsMap")) {
1572+
if (bson_iter_init_find (&iter, opts, "encryptedFieldsMap")) {
15781573
BSON_ASSERT (BSON_ITER_HOLDS_DOCUMENT (&iter));
15791574
bson_t efm;
15801575

@@ -1596,7 +1591,7 @@ set_auto_encryption_opts (mongoc_client_t *client, bson_t *test)
15961591
bson_free (env_cryptSharedLibPath);
15971592
}
15981593

1599-
if (bson_iter_init_find (&iter, &opts, "keyExpirationMS")) {
1594+
if (bson_iter_init_find (&iter, opts, "keyExpirationMS")) {
16001595
BSON_ASSERT (BSON_ITER_HOLDS_INT (&iter));
16011596
const int expiration = bson_iter_as_int64 (&iter);
16021597
BSON_ASSERT (expiration > 0);
@@ -1769,7 +1764,12 @@ run_json_general_test (const json_test_config_t *config)
17691764
MONGOC_WARNING ("Error in killAllSessions: %s", error.message);
17701765
}
17711766

1772-
set_auto_encryption_opts (client, &test);
1767+
if (bson_has_field (&test, "clientOptions.autoEncryptOpts")) {
1768+
bson_t opts;
1769+
bson_lookup_doc (&test, "clientOptions.autoEncryptOpts", &opts);
1770+
set_auto_encryption_opts (client, &opts);
1771+
}
1772+
17731773
/* Drop and recreate test database/collection if necessary. */
17741774
if (!test_framework_is_mongohouse ()) {
17751775
// mongohouse test user is not authorized to run `drop`.

src/libmongoc/tests/json-test.h

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ install_json_test_suite (TestSuite *suite, const char *base, const char *subdir,
107107
void
108108
set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts);
109109

110+
void
111+
set_auto_encryption_opts (mongoc_client_t *client, bson_t *opts);
112+
110113
void
111114
insert_data (const char *db_name, const char *collection_name, const bson_t *scenario);
112115

0 commit comments

Comments
 (0)