@@ -1910,6 +1910,38 @@ def test_bypassAutoEncryption(self):
19101910 with self .assertRaises (ServerSelectionTimeoutError ):
19111911 mongocryptd_client .admin .command ("ping" )
19121912
1913+ @unittest .skipUnless (os .environ .get ("TEST_CRYPT_SHARED" ), "crypt_shared lib is not installed" )
1914+ def test_via_loading_shared_library (self ):
1915+ key_vault = client_context .client .keyvault .datakeys
1916+ key_vault .drop ()
1917+ key_vault .create_index (
1918+ "keyAltNames" , unique = True , partialFilterExpression = {"keyAltNames" : {"$exists" : True }}
1919+ )
1920+ key_vault .insert_one (json_data ("external" , "external-key.json" ))
1921+ schemas = {"db.coll" : json_data ("external" , "external-schema.json" )}
1922+ opts = AutoEncryptionOpts (
1923+ kms_providers = {"local" : {"key" : LOCAL_MASTER_KEY }},
1924+ key_vault_namespace = "keyvault.datakeys" ,
1925+ schema_map = schemas ,
1926+ mongocryptd_uri = "mongodb://localhost:47021/db?serverSelectionTimeoutMS=1000" ,
1927+ mongocryptd_spawn_args = [
1928+ "--pidfilepath=bypass-spawning-mongocryptd.pid" ,
1929+ "--port=47021" ,
1930+ ],
1931+ crypt_shared_lib_required = True ,
1932+ )
1933+ client_encrypted = rs_or_single_client (auto_encryption_opts = opts )
1934+ self .addCleanup (client_encrypted .close )
1935+ client_encrypted .db .coll .drop ()
1936+ client_encrypted .db .coll .insert_one ({"encrypted" : "test" })
1937+ self .assertEncrypted (client_context .client .db .coll .find_one ({})["encrypted" ])
1938+ no_mongocryptd_client = MongoClient (
1939+ host = "mongodb://localhost:47021/db?serverSelectionTimeoutMS=1000"
1940+ )
1941+ self .addCleanup (no_mongocryptd_client .close )
1942+ with self .assertRaises (ServerSelectionTimeoutError ):
1943+ no_mongocryptd_client .db .command ("ping" )
1944+
19131945
19141946# https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#kms-tls-tests
19151947class TestKmsTLSProse (EncryptionIntegrationTest ):
0 commit comments