|
33 | 33 | from bson.json_util import JSONOptions
|
34 | 34 | from bson.son import SON
|
35 | 35 |
|
| 36 | +from pymongo.cursor import CursorType |
36 | 37 | from pymongo.errors import (ConfigurationError,
|
37 | 38 | EncryptionError,
|
38 | 39 | InvalidOperation,
|
|
41 | 42 | ClientEncryption)
|
42 | 43 | from pymongo.encryption_options import AutoEncryptionOpts, _HAVE_PYMONGOCRYPT
|
43 | 44 | from pymongo.mongo_client import MongoClient
|
| 45 | +from pymongo.operations import InsertOne |
44 | 46 | from pymongo.write_concern import WriteConcern
|
45 | 47 |
|
46 | 48 | from test import unittest, IntegrationTest, PyMongoTestCase, client_context
|
@@ -256,6 +258,48 @@ def test_use_after_close(self):
|
256 | 258 | client.admin.command('isMaster')
|
257 | 259 |
|
258 | 260 |
|
| 261 | +class TestClientMaxWireVersion(IntegrationTest): |
| 262 | + |
| 263 | + @classmethod |
| 264 | + @unittest.skipUnless(_HAVE_PYMONGOCRYPT, 'pymongocrypt is not installed') |
| 265 | + def setUpClass(cls): |
| 266 | + super(TestClientMaxWireVersion, cls).setUpClass() |
| 267 | + |
| 268 | + @client_context.require_version_max(4, 0, 99) |
| 269 | + def test_raise_max_wire_version_error(self): |
| 270 | + opts = AutoEncryptionOpts(KMS_PROVIDERS, 'admin.datakeys') |
| 271 | + client = rs_or_single_client(auto_encryption_opts=opts) |
| 272 | + self.addCleanup(client.close) |
| 273 | + msg = 'Auto-encryption requires a minimum MongoDB version of 4.2' |
| 274 | + with self.assertRaisesRegex(ConfigurationError, msg): |
| 275 | + client.test.test.insert_one({}) |
| 276 | + with self.assertRaisesRegex(ConfigurationError, msg): |
| 277 | + client.admin.command('isMaster') |
| 278 | + with self.assertRaisesRegex(ConfigurationError, msg): |
| 279 | + client.test.test.find_one({}) |
| 280 | + with self.assertRaisesRegex(ConfigurationError, msg): |
| 281 | + client.test.test.bulk_write([InsertOne({})]) |
| 282 | + |
| 283 | + def test_raise_unsupported_error(self): |
| 284 | + opts = AutoEncryptionOpts(KMS_PROVIDERS, 'admin.datakeys') |
| 285 | + client = rs_or_single_client(auto_encryption_opts=opts) |
| 286 | + self.addCleanup(client.close) |
| 287 | + msg = 'find_raw_batches does not support auto encryption' |
| 288 | + with self.assertRaisesRegex(InvalidOperation, msg): |
| 289 | + client.test.test.find_raw_batches({}) |
| 290 | + |
| 291 | + msg = 'aggregate_raw_batches does not support auto encryption' |
| 292 | + with self.assertRaisesRegex(InvalidOperation, msg): |
| 293 | + client.test.test.aggregate_raw_batches([]) |
| 294 | + |
| 295 | + if client_context.is_mongos: |
| 296 | + msg = 'Exhaust cursors are not supported by mongos' |
| 297 | + else: |
| 298 | + msg = 'exhaust cursors do not support auto encryption' |
| 299 | + with self.assertRaisesRegex(InvalidOperation, msg): |
| 300 | + next(client.test.test.find(cursor_type=CursorType.EXHAUST)) |
| 301 | + |
| 302 | + |
259 | 303 | class TestExplicitSimple(EncryptionIntegrationTest):
|
260 | 304 |
|
261 | 305 | def test_encrypt_decrypt(self):
|
@@ -403,6 +447,7 @@ class TestSpec(SpecRunner):
|
403 | 447 |
|
404 | 448 | @classmethod
|
405 | 449 | @unittest.skipUnless(_HAVE_PYMONGOCRYPT, 'pymongocrypt is not installed')
|
| 450 | + @client_context.require_version_min(3, 6) # SpecRunner requires sessions. |
406 | 451 | def setUpClass(cls):
|
407 | 452 | super(TestSpec, cls).setUpClass()
|
408 | 453 |
|
|
0 commit comments