Skip to content

Commit a82a9ac

Browse files
CSHARP-4285: Update expected error in fle2-InsertFind-Unindexed test. (mongodb#861)
1 parent 7f4091b commit a82a9ac

File tree

3 files changed

+289
-9
lines changed

3 files changed

+289
-9
lines changed

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/tests/legacy/README.rst

Lines changed: 283 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ Using ``crypt_shared``
330330
On platforms where crypt_shared_ is available, drivers should prefer to test
331331
with the ``crypt_shared`` library instead of spawning mongocryptd.
332332

333+
crypt_shared_ is released alongside the server.
334+
crypt_shared_ is only available in versions 6.0 and above.
335+
Drivers SHOULD prefer testing a version of crypt_shared_ that matches the server version being tested.
336+
Driver tests on server versions less than 6.0 SHOULD use mongocryptd.
337+
333338
Drivers MUST continue to run all tests with mongocryptd on at least one
334339
platform for all tested server versions.
335340

@@ -1656,6 +1661,7 @@ Use ``clientEncryption`` to encrypt the value "encrypted indexed value" with the
16561661
class EncryptOpts {
16571662
keyId : <key1ID>
16581663
algorithm: "Indexed",
1664+
contentionFactor: 0
16591665
}
16601666
16611667
Store the result in ``insertPayload``.
@@ -1669,7 +1675,8 @@ Use ``clientEncryption`` to encrypt the value "encrypted indexed value" with the
16691675
class EncryptOpts {
16701676
keyId : <key1ID>
16711677
algorithm: "Indexed",
1672-
queryType: Equality
1678+
queryType: "equality",
1679+
contentionFactor: 0
16731680
}
16741681
16751682
Store the result in ``findPayload``.
@@ -1704,7 +1711,8 @@ Use ``clientEncryption`` to encrypt the value "encrypted indexed value" with the
17041711
class EncryptOpts {
17051712
keyId : <key1ID>
17061713
algorithm: "Indexed",
1707-
queryType: Equality
1714+
queryType: "equality",
1715+
contentionFactor: 0
17081716
}
17091717
17101718
Store the result in ``findPayload``.
@@ -1720,7 +1728,7 @@ Use ``clientEncryption`` to encrypt the value "encrypted indexed value" with the
17201728
class EncryptOpts {
17211729
keyId : <key1ID>
17221730
algorithm: "Indexed",
1723-
queryType: Equality,
1731+
queryType: "equality",
17241732
contentionFactor: 10
17251733
}
17261734
@@ -1760,6 +1768,7 @@ Use ``clientEncryption`` to encrypt the value "encrypted indexed value" with the
17601768
class EncryptOpts {
17611769
keyId : <key1ID>
17621770
algorithm: "Indexed",
1771+
contentionFactor: 0
17631772
}
17641773
17651774
Store the result in ``payload``.
@@ -1785,6 +1794,8 @@ Use ``clientEncryption`` to decrypt ``payload``. Assert the returned value equal
17851794
13. Unique Index on keyAltNames
17861795
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17871796

1797+
The following setup must occur before running each of the following test cases.
1798+
17881799
Setup
17891800
`````
17901801

@@ -1817,8 +1828,8 @@ The command should be equivalent to:
18171828

18181829
5. Using ``client_encryption``, create a data key with a ``local`` KMS provider and the keyAltName "def".
18191830

1820-
Case 1: createKey()
1821-
```````````````````
1831+
Case 1: createDataKey()
1832+
```````````````````````
18221833

18231834
1. Use ``client_encryption`` to create a new local data key with a keyAltName "abc" and assert the operation does not fail.
18241835

@@ -1833,8 +1844,273 @@ Case 2: addKeyAltName()
18331844

18341845
2. Use ``client_encryption`` to add a keyAltName "abc" to the key created in Step 1 and assert the operation does not fail.
18351846

1836-
3. Repeat Step 2 and assert the operation does not fail.
1847+
3. Repeat Step 2, assert the operation does not fail, and assert the returned key document contains the keyAltName "abc" added in Step 2.
18371848

18381849
4. Use ``client_encryption`` to add a keyAltName "def" to the key created in Step 1 and assert the operation fails due to a duplicate key server error (error code 11000).
18391850

1840-
5. Use ``client_encryption`` to add a keyAltName "def" to the existing key and assert the operation does not fail.
1851+
5. Use ``client_encryption`` to add a keyAltName "def" to the existing key, assert the operation does not fail, and assert the returned key document contains the keyAltName "def" added during Setup.
1852+
1853+
14. Decryption Events
1854+
~~~~~~~~~~~~~~~~~~~~~
1855+
1856+
Before running each of the following test cases, perform the following Test Setup.
1857+
1858+
Test Setup
1859+
``````````
1860+
1861+
Create a MongoClient named ``setupClient``.
1862+
1863+
Drop and create the collection ``db.decryption_events``.
1864+
1865+
Create a ClientEncryption object named ``clientEncryption`` with these options:
1866+
1867+
.. code:: typescript
1868+
1869+
ClientEncryptionOpts {
1870+
keyVaultClient: <setupClient>,
1871+
keyVaultNamespace: "keyvault.datakeys",
1872+
kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } }
1873+
}
1874+
1875+
Create a data key with the "local" KMS provider. Storing the result in a variable named ``keyID``.
1876+
1877+
Use ``clientEncryption`` to encrypt the string "hello" with the following ``EncryptOpts``:
1878+
1879+
.. code:: typescript
1880+
1881+
EncryptOpts {
1882+
keyId: <keyID>,
1883+
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
1884+
}
1885+
1886+
Store the result in a variable named ``ciphertext``.
1887+
1888+
Copy ``ciphertext`` into a variable named ``malformedCiphertext``. Change the
1889+
last byte to a different value. This will produce an invalid HMAC tag.
1890+
1891+
Create a MongoClient named ``encryptedClient`` with these ``AutoEncryptionOpts``:
1892+
1893+
.. code:: typescript
1894+
1895+
AutoEncryptionOpts {
1896+
keyVaultNamespace: "keyvault.datakeys";
1897+
kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } }
1898+
}
1899+
1900+
Configure ``encryptedClient`` with "retryReads=false".
1901+
Register a listener for CommandSucceeded events on ``encryptedClient``.
1902+
The listener must store the most recent ``CommandSucceededEvent`` reply for the "aggregate" command.
1903+
The listener must store the most recent ``CommandFailedEvent`` error for the "aggregate" command.
1904+
1905+
Case 1: Command Error
1906+
`````````````````````
1907+
1908+
Use ``setupClient`` to configure the following failpoint:
1909+
1910+
.. code:: typescript
1911+
1912+
{
1913+
"configureFailPoint": "failCommand",
1914+
"mode": {
1915+
"times": 1
1916+
},
1917+
"data": {
1918+
"errorCode": 123,
1919+
"failCommands": [
1920+
"aggregate"
1921+
]
1922+
}
1923+
}
1924+
1925+
Use ``encryptedClient`` to run an aggregate on ``db.decryption_events``.
1926+
1927+
Expect an exception to be thrown from the command error. Expect a ``CommandFailedEvent``.
1928+
1929+
Case 2: Network Error
1930+
`````````````````````
1931+
1932+
Use ``setupClient`` to configure the following failpoint:
1933+
1934+
.. code:: typescript
1935+
1936+
{
1937+
"configureFailPoint": "failCommand",
1938+
"mode": {
1939+
"times": 1
1940+
},
1941+
"data": {
1942+
"errorCode": 123,
1943+
"closeConnection": true,
1944+
"failCommands": [
1945+
"aggregate"
1946+
]
1947+
}
1948+
}
1949+
1950+
Use ``encryptedClient`` to run an aggregate on ``db.decryption_events``.
1951+
1952+
Expect an exception to be thrown from the network error. Expect a ``CommandFailedEvent``.
1953+
1954+
Case 3: Decrypt Error
1955+
`````````````````````
1956+
1957+
Use ``encryptedClient`` to insert the document ``{ "encrypted": <malformedCiphertext> }`` into ``db.decryption_events``.
1958+
1959+
Use ``encryptedClient`` to run an aggregate on ``db.decryption_events`` with an empty pipeline.
1960+
1961+
Expect an exception to be thrown from the decryption error.
1962+
Expect a ``CommandSucceededEvent``. Expect the ``CommandSucceededEvent.reply`` to contain BSON binary for the field ``cursor.firstBatch.encrypted``.
1963+
1964+
Case 4: Decrypt Success
1965+
```````````````````````
1966+
1967+
Use ``encryptedClient`` to insert the document ``{ "encrypted": <ciphertext> }`` into ``db.decryption_events``.
1968+
1969+
Use ``encryptedClient`` to run an aggregate on ``db.decryption_events`` with an empty pipeline.
1970+
1971+
Expect no exception.
1972+
Expect a ``CommandSucceededEvent``. Expect the ``CommandSucceededEvent.reply`` to contain BSON binary for the field ``cursor.firstBatch.encrypted``.
1973+
1974+
1975+
15. On-demand AWS Credentials
1976+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1977+
1978+
These tests require valid AWS credentials. Refer: `Automatic AWS Credentials`_.
1979+
1980+
For these cases, create a ClientEncryption_ object :math:`C` with the following
1981+
options:
1982+
1983+
.. code-block:: typescript
1984+
1985+
ClientEncryptionOpts {
1986+
keyVaultClient: <setupClient>,
1987+
keyVaultNamespace: "keyvault.datakeys",
1988+
kmsProviders: { "aws": {} },
1989+
}
1990+
1991+
Case 1: Failure
1992+
```````````````
1993+
1994+
Do not run this test case in an environment where AWS credentials are available
1995+
(e.g. via environment variables or a metadata URL). (Refer:
1996+
`Obtaining credentials for AWS <auth-aws_>`_)
1997+
1998+
Attempt to create a datakey with :math:`C` using the ``"aws"`` KMS provider.
1999+
Expect this to fail due to a lack of KMS provider credentials.
2000+
2001+
Case 2: Success
2002+
```````````````
2003+
2004+
For this test case, the environment variables ``AWS_ACCESS_KEY_ID`` and
2005+
``AWS_SECRET_ACCESS_KEY`` must be defined and set to a valid set of AWS
2006+
credentials.
2007+
2008+
Use the client encryption to create a datakey using the ``"aws"`` KMS provider.
2009+
This should successfully load and use the AWS credentials that were defined in
2010+
the environment.
2011+
2012+
.. _Automatic AWS Credentials: ../client-side-encryption.rst#automatic-aws-credentials
2013+
.. _ClientEncryption: ../client-side-encryption.rst#clientencryption
2014+
.. _auth-aws: ../../auth/auth.rst#obtaining-credentials
2015+
2016+
16. Rewrap
2017+
~~~~~~~~~~
2018+
2019+
Case 1: Rewrap with separate ClientEncryption
2020+
`````````````````````````````````````````````
2021+
2022+
When the following test case requests setting ``masterKey``, use the following values based on the KMS provider:
2023+
2024+
For "aws":
2025+
2026+
.. code:: javascript
2027+
2028+
{
2029+
"region": "us-east-1",
2030+
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"
2031+
}
2032+
2033+
For "azure":
2034+
2035+
.. code:: javascript
2036+
2037+
{
2038+
"keyVaultEndpoint": "key-vault-csfle.vault.azure.net",
2039+
"keyName": "key-name-csfle"
2040+
}
2041+
2042+
For "gcp":
2043+
2044+
.. code:: javascript
2045+
2046+
{
2047+
"projectId": "devprod-drivers",
2048+
"location": "global",
2049+
"keyRing": "key-ring-csfle",
2050+
"keyName": "key-name-csfle"
2051+
}
2052+
2053+
For "kmip":
2054+
2055+
.. code:: javascript
2056+
2057+
{}
2058+
2059+
For "local", do not set a masterKey document.
2060+
2061+
Run the following test case for each pair of KMS providers (referred to as ``srcProvider`` and ``dstProvider``).
2062+
Include pairs where ``srcProvider`` equals ``dstProvider``.
2063+
2064+
1. Drop the collection ``keyvault.datakeys``.
2065+
2066+
2. Create a ``ClientEncryption`` object named ``clientEncryption1`` with these options:
2067+
.. code:: typescript
2068+
2069+
ClientEncryptionOpts {
2070+
keyVaultClient: <new MongoClient>;
2071+
keyVaultNamespace: "keyvault.datakeys";
2072+
kmsProviders: <all KMS providers>
2073+
}
2074+
2075+
3. Call ``clientEncryption1.createDataKey`` with ``srcProvider`` and these options:
2076+
.. code:: typescript
2077+
2078+
class DataKeyOpts {
2079+
masterKey: <depends on srcProvider>
2080+
}
2081+
2082+
Store the return value in ``keyID``.
2083+
2084+
4. Call ``clientEncryption1.encrypt`` with the value "test" and these options:
2085+
.. code:: typescript
2086+
2087+
class EncryptOpts {
2088+
keyId : keyID,
2089+
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
2090+
}
2091+
2092+
Store the return value in ``ciphertext``.
2093+
2094+
5. Create a ``ClientEncryption`` object named ``clientEncryption2`` with these options:
2095+
.. code:: typescript
2096+
2097+
ClientEncryptionOpts {
2098+
keyVaultClient: <new MongoClient>;
2099+
keyVaultNamespace: "keyvault.datakeys";
2100+
kmsProviders: <all KMS providers>
2101+
}
2102+
2103+
6. Call ``clientEncryption2.rewrapManyDataKey`` with an empty ``filter`` and these options:
2104+
2105+
.. code:: typescript
2106+
2107+
class RewrapManyDataKeyOpts {
2108+
provider: dstProvider
2109+
masterKey: <depends on dstProvider>
2110+
}
2111+
2112+
Assert that the returned ``RewrapManyDataKeyResult.bulkWriteResult.modifiedCount`` is 1.
2113+
2114+
7. Call ``clientEncryption1.decrypt`` with the ``ciphertext``. Assert the return value is "test".
2115+
2116+
8. Call ``clientEncryption2.decrypt`` with the ``ciphertext``. Assert the return value is "test".

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/tests/legacy/fle2-InsertFind-Unindexed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
}
242242
},
243243
"result": {
244-
"errorContains": "Cannot query"
244+
"errorContains": "encrypt"
245245
}
246246
}
247247
]

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/tests/legacy/fle2-InsertFind-Unindexed.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ tests:
8080
arguments:
8181
filter: { encryptedUnindexed: "value123" }
8282
result:
83-
errorContains: "Cannot query"
83+
# Expected error message changed in https://github.com/10gen/mongo-enterprise-modules/commit/212b584d4f7a44bed41c826a180a4aff00923d7a#diff-5f12b55e8d5c52c2f62853ec595dc2c1e2e5cb4fdbf7a32739a8e3acb3c6f818
84+
# Before the message was "cannot query non-indexed fields with the randomized encryption algorithm"
85+
# After: "can only execute encrypted equality queries with an encrypted equality index"
86+
# Use a small common substring.
87+
errorContains: "encrypt"

0 commit comments

Comments
 (0)