Skip to content

Commit 79ee4b4

Browse files
committed
CDRIVER-4401 use deterministic encryption in prose test (#1025)
* use deterministic encryption to match specified test * use test case numbering from DRIVERS-2350 * add one to make malformed ciphertext Last byte of ciphertext may be expectedly 0
1 parent 0f572c8 commit 79ee4b4

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/libmongoc/tests/test-mongoc-client-side-encryption.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,7 +4308,7 @@ decryption_events_setup (void)
43084308
plaintext.value.v_utf8.len = strlen (plaintext.value.v_utf8.str);
43094309

43104310
mongoc_client_encryption_encrypt_opts_set_algorithm (
4311-
eOpts, MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM);
4311+
eOpts, MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC);
43124312
mongoc_client_encryption_encrypt_opts_set_keyid (eOpts, &keyID);
43134313

43144314
ASSERT_OR_PRINT (
@@ -4323,10 +4323,10 @@ decryption_events_setup (void)
43234323
{
43244324
bson_value_copy (&def->ciphertext, &def->malformedCiphertext);
43254325
ASSERT (def->ciphertext.value_type == BSON_TYPE_BINARY);
4326-
/* Set the last data byte to zero to make malformed. The last data byte is
4326+
/* Change the last data byte to make malformed. The last data byte is
43274327
* part of the HMAC tag. */
43284328
def->malformedCiphertext.value.v_binary
4329-
.data[def->malformedCiphertext.value.v_binary.data_len - 1] = 0;
4329+
.data[def->malformedCiphertext.value.v_binary.data_len - 1]++;
43304330
}
43314331

43324332
/* Create a MongoClient with automatic decryption. */
@@ -4387,11 +4387,12 @@ decryption_events_fixture_destroy (decryption_events_fixture *def)
43874387
bson_free (def);
43884388
}
43894389

4390+
/* Prose test 14: Case 1: Command Error */
43904391
/* test_decryption_events_command_error is a regression test for CDRIVER-4401.
43914392
* Send a command on an encrypted client resulting in a { 'ok': 0 } reply.
43924393
* Expect an error returned and a CommandFailed event to be emitted. */
43934394
static void
4394-
test_decryption_events_command_error (void *unused)
4395+
test_decryption_events_case1 (void *unused)
43954396
{
43964397
bool got;
43974398
bson_error_t error;
@@ -4431,11 +4432,12 @@ test_decryption_events_command_error (void *unused)
44314432
decryption_events_fixture_destroy (def);
44324433
}
44334434

4435+
/* Prose test 14: Case 2: Network Error */
44344436
/* test_decryption_events_network_error is a regression test for CDRIVER-4401.
44354437
* Send a command on an encrypted client resulting in a network error.
44364438
* Expect an error returned and a CommandFailed event to be emitted. */
44374439
static void
4438-
test_decryption_events_network_error (void *unused)
4440+
test_decryption_events_case2 (void *unused)
44394441

44404442
{
44414443
bool got;
@@ -4477,12 +4479,13 @@ test_decryption_events_network_error (void *unused)
44774479
decryption_events_fixture_destroy (def);
44784480
}
44794481

4482+
/* Prose test 14: Case 3: Decrypt Error. */
44804483
/* test_decryption_events_decrypt_error is a regression test for CDRIVER-4401.
44814484
* Decrypt a reply with a malformed ciphertext.
44824485
* Expect an error returned and a CommandSucceeded event to be emitted with
44834486
* ciphertext. */
44844487
static void
4485-
test_decryption_events_decrypt_error (void *unused)
4488+
test_decryption_events_case3 (void *unused)
44864489
{
44874490
bool got;
44884491
bson_error_t error;
@@ -4524,12 +4527,13 @@ test_decryption_events_decrypt_error (void *unused)
45244527
decryption_events_fixture_destroy (def);
45254528
}
45264529

4530+
/* Prose test 14: Case 4: Decrypt Success. */
45274531
/* test_decryption_events_decrypt_success is a regression test for CDRIVER-4401.
45284532
* Decrypt a reply with a valid ciphertext.
45294533
* Expect a successful return and a CommandSucceeded event to be emitted with
45304534
* ciphertext. */
45314535
static void
4532-
test_decryption_events_decrypt_success (void *unused)
4536+
test_decryption_events_case4 (void *unused)
45334537
{
45344538
bool got;
45354539
bson_error_t error;
@@ -4966,37 +4970,37 @@ test_client_side_encryption_install (TestSuite *suite)
49664970
test_framework_skip_if_single);
49674971

49684972
TestSuite_AddFull (suite,
4969-
"/client_side_encryption/decryption_events/command_error",
4970-
test_decryption_events_command_error,
4973+
"/client_side_encryption/decryption_events/case1",
4974+
test_decryption_events_case1,
49714975
NULL /* dtor */,
49724976
NULL /* ctx */,
49734977
test_framework_skip_if_no_client_side_encryption,
49744978
test_framework_skip_if_max_wire_version_less_than_8);
49754979

49764980
TestSuite_AddFull (suite,
4977-
"/client_side_encryption/decryption_events/network_error",
4978-
test_decryption_events_network_error,
4981+
"/client_side_encryption/decryption_events/case2",
4982+
test_decryption_events_case2,
49794983
NULL /* dtor */,
49804984
NULL /* ctx */,
49814985
test_framework_skip_if_no_client_side_encryption,
49824986
test_framework_skip_if_max_wire_version_less_than_8);
49834987

49844988
TestSuite_AddFull (suite,
4985-
"/client_side_encryption/decryption_events/decrypt_error",
4986-
test_decryption_events_decrypt_error,
4989+
"/client_side_encryption/decryption_events/case3",
4990+
test_decryption_events_case3,
49874991
NULL /* dtor */,
49884992
NULL /* ctx */,
49894993
test_framework_skip_if_no_client_side_encryption,
49904994
test_framework_skip_if_max_wire_version_less_than_8);
49914995

4992-
TestSuite_AddFull (
4993-
suite,
4994-
"/client_side_encryption/decryption_events/decrypt_success",
4995-
test_decryption_events_decrypt_success,
4996-
NULL /* dtor */,
4997-
NULL /* ctx */,
4998-
test_framework_skip_if_no_client_side_encryption,
4999-
test_framework_skip_if_max_wire_version_less_than_8);
4996+
4997+
TestSuite_AddFull (suite,
4998+
"/client_side_encryption/decryption_events/case4",
4999+
test_decryption_events_case4,
5000+
NULL /* dtor */,
5001+
NULL /* ctx */,
5002+
test_framework_skip_if_no_client_side_encryption,
5003+
test_framework_skip_if_max_wire_version_less_than_8);
50005004

50015005
TestSuite_AddFull (suite,
50025006
"/client_side_encryption/qe_docs_example",

0 commit comments

Comments
 (0)