diff --git a/bindings/python/.evergreen/test.sh b/bindings/python/.evergreen/test.sh index a45ba0459..66f7b8cca 100755 --- a/bindings/python/.evergreen/test.sh +++ b/bindings/python/.evergreen/test.sh @@ -23,7 +23,7 @@ if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin "C:/python/Python38/python.exe" "C:/python/Python39/python.exe" "C:/python/Python310/python.exe") - export CSFLE_PATH=../crypt_shared/bin/mongo_crypt_v1.dll + export CRYPT_SHARED_PATH=../crypt_shared/bin/mongo_crypt_v1.dll C:/python/Python310/python.exe drivers-evergreen-tools/.evergreen/mongodl.py --component crypt_shared \ --version latest --out ../crypt_shared/ elif [ "Darwin" = "$(uname -s)" ]; then @@ -38,7 +38,7 @@ elif [ "Darwin" = "$(uname -s)" ]; then "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.9/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3") - export CSFLE_PATH="../crypt_shared/lib/mongo_crypt_v1.dylib" + export CRYPT_SHARED_PATH="../crypt_shared/lib/mongo_crypt_v1.dylib" python3 drivers-evergreen-tools/.evergreen/mongodl.py --component crypt_shared \ --version latest --out ../crypt_shared/ else @@ -49,7 +49,7 @@ else "/opt/python/3.6/bin/python3" "/opt/python/pypy/bin/pypy" "/opt/python/pypy3.6/bin/pypy3") - export CSFLE_PATH="../crypt_shared/lib/mongo_crypt_v1.so" + export CRYPT_SHARED_PATH="../crypt_shared/lib/mongo_crypt_v1.so" /opt/mongodbtoolchain/v3/bin/python3 drivers-evergreen-tools/.evergreen/mongodl.py --component \ crypt_shared --version latest --out ../crypt_shared/ --target rhel70 fi @@ -62,9 +62,9 @@ for PYTHON_BINARY in "${PYTHONS[@]}"; do python -m pip install --prefer-binary -r test-requirements.txt python setup.py test echo "Running tests with CSFLE on dynamic library path..." - DYLD_FALLBACK_LIBRARY_PATH=../csfle/lib/:$DYLD_FALLBACK_LIBRARY_PATH \ - LD_LIBRARY_PATH=../csfle/lib:$LD_LIBRARY_PATH \ - PATH=../csfle/bin:$PATH \ + TEST_CRYPT_SHARED=1 DYLD_FALLBACK_LIBRARY_PATH=../crypt_shared/lib/:$DYLD_FALLBACK_LIBRARY_PATH \ + LD_LIBRARY_PATH=../crypt_shared/lib:$LD_LIBRARY_PATH \ + PATH=../crypt_shared/bin:$PATH \ python setup.py test deactivate rm -rf .venv diff --git a/bindings/python/test/test_mongocrypt.py b/bindings/python/test/test_mongocrypt.py index 4a351b667..20045e7d0 100644 --- a/bindings/python/test/test_mongocrypt.py +++ b/bindings/python/test/test_mongocrypt.py @@ -257,8 +257,8 @@ def _test_kms_context(self, ctx): def test_encrypt(self): mc = self.create_mongocrypt() self.addCleanup(mc.close) - if mc.crypt_shared_lib_version != None: - self.skipTest("This test's assumptions about the state of mongocrypt do not hold when CSFLE is loaded") + if mc.crypt_shared_lib_version is not None: + self.skipTest("this test must be skipped when crypt_shared is loaded") with mc.encryption_context('text', bson_data('command.json')) as ctx: self.assertEqual(ctx.state, lib.MONGOCRYPT_CTX_NEED_MONGO_COLLINFO) @@ -380,34 +380,30 @@ def mongo_crypt_opts(): 'aws': {'accessKeyId': 'example', 'secretAccessKey': 'example'}, 'local': {'key': b'\x00'*96}}) - def test_csfle(self): - mc = MongoCrypt(MongoCryptOptions({ - 'aws': {'accessKeyId': 'example', 'secretAccessKey': 'example'}, - 'local': {'key': b'\x00'*96}}), MockCallback()) - if mc.crypt_shared_lib_version is None: - self.skipTest("This test requires CSFLE.") - # Test that we can pick up CSFLE automatically - encrypter = AutoEncrypter(MockCallback(), MongoCryptOptions({ + @unittest.skipUnless(os.getenv("TEST_CRYPT_SHARED"), "this test requires TEST_CRYPT_SHARED=1") + def test_crypt_shared(self): + kms_providers = { 'aws': {'accessKeyId': 'example', 'secretAccessKey': 'example'}, - 'local': {'key': b'\x00'*96}}, - bypass_encryption=False, - crypt_shared_lib_required=True)) + 'local': {'key': b'\x00'*96}} + mc = MongoCrypt(MongoCryptOptions(kms_providers), MockCallback()) + self.addCleanup(mc.close) + self.assertIsNotNone(mc.crypt_shared_lib_version) + # Test that we can pick up crypt_shared automatically + encrypter = AutoEncrypter(MockCallback(), MongoCryptOptions( + kms_providers, + bypass_encryption=False, + crypt_shared_lib_required=True)) self.addCleanup(encrypter.close) - encrypter = AutoEncrypter(MockCallback(), - MongoCryptOptions({ - 'aws': {'accessKeyId': 'example', - 'secretAccessKey': 'example'}, - 'local': {'key': b'\x00' * 96}}, - crypt_shared_lib_path=os.environ["CSFLE_PATH"], - crypt_shared_lib_required=True)) + encrypter = AutoEncrypter(MockCallback(), MongoCryptOptions( + kms_providers, + crypt_shared_lib_path=os.environ["CRYPT_SHARED_PATH"], + crypt_shared_lib_required=True)) self.addCleanup(encrypter.close) with self.assertRaisesRegex(MongoCryptError, "/doesnotexist"): - AutoEncrypter(MockCallback(),MongoCryptOptions({ - 'aws': {'accessKeyId': 'example', - 'secretAccessKey': 'example'}, - 'local': {'key': b'\x00' * 96}}, - crypt_shared_lib_path="/doesnotexist", - crypt_shared_lib_required=True)) + AutoEncrypter(MockCallback(), MongoCryptOptions( + kms_providers, + crypt_shared_lib_path="/doesnotexist", + crypt_shared_lib_required=True)) def test_encrypt(self): encrypter = AutoEncrypter(MockCallback(