Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bindings/python/.evergreen/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
48 changes: 22 additions & 26 deletions bindings/python/test/test_mongocrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down