Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-1363

[Build Failure] test_asyncio_cursor uses wrong parameter

    • Type: Icon: Build Failure Build Failure
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.6
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers

      https://github.com/mongodb/motor/actions/runs/10773652007/job/29873902289

      The type guard was added in PYTHON-4590.

      =================================== FAILURES ===================================
      _____________________ TestAsyncIOCursor.test_generate_keys _____________________
      
      self = <test.asyncio_tests.test_asyncio_cursor.TestAsyncIOCursor testMethod=test_generate_keys>
      
          @asyncio_test
          async def test_generate_keys(self):
              c = self.collection
              KMS_PROVIDERS = {"local": {"key": b"\x00" * 96}}
          
      >       async with motor_asyncio.AsyncIOMotorClientEncryption(
                  KMS_PROVIDERS, "keyvault.datakeys", c, bson.codec_options.CodecOptions()
              ) as client_encryption:
      
      test/asyncio_tests/test_asyncio_cursor.py:591: 
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
      motor/core.py:2176: in __init__
          delegate = self.__delegate_class__(
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
      
      self = <pymongo.synchronous.encryption.ClientEncryption object at 0x7f3bc6bb77c0>
      kms_providers = {'local': {'key': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}}
      key_vault_namespace = 'keyvault.datakeys'
      key_vault_client = Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=False, tls=False, driver=DriverInfo(name='Motor', version='3.6.0.dev0', platform='asyncio')), 'motor_test'), 'test_collection')
      codec_options = CodecOptions(document_class=dict, tz_aware=False, uuid_representation=UuidRepresentation.UNSPECIFIED, unicode_decode_e...ne, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), datetime_conversion=DatetimeConversion.DATETIME)
      kms_tls_options = None
      
          def __init__(
              self,
              kms_providers: Mapping[str, Any],
              key_vault_namespace: str,
              key_vault_client: MongoClient[_DocumentTypeArg],
              codec_options: CodecOptions[_DocumentTypeArg],
              kms_tls_options: Optional[Mapping[str, Any]] = None,
          ) -> None:
              """Explicit client-side field level encryption.
          
              The ClientEncryption class encapsulates explicit operations on a key
              vault collection that cannot be done directly on a MongoClient. Similar
              to configuring auto encryption on a MongoClient, it is constructed with
              a MongoClient (to a MongoDB cluster containing the key vault
              collection), KMS provider configuration, and keyVaultNamespace. It
              provides an API for explicitly encrypting and decrypting values, and
              creating data keys. It does not provide an API to query keys from the
              key vault collection, as this can be done directly on the MongoClient.
          
              See :ref:`explicit-client-side-encryption` for an example.
          
              :param kms_providers: Map of KMS provider options. The `kms_providers`
                  map values differ by provider:
          
                    - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings.
                      These are the AWS access key ID and AWS secret access key used
                      to generate KMS messages. An optional "sessionToken" may be
                      included to support temporary AWS credentials.
                    - `azure`: Map with "tenantId", "clientId", and "clientSecret" as
                      strings. Additionally, "identityPlatformEndpoint" may also be
                      specified as a string (defaults to 'login.microsoftonline.com').
                      These are the Azure Active Directory credentials used to
                      generate Azure Key Vault messages.
                    - `gcp`: Map with "email" as a string and "privateKey"
                      as `bytes` or a base64 encoded string.
                      Additionally, "endpoint" may also be specified as a string
                      (defaults to 'oauth2.googleapis.com'). These are the
                      credentials used to generate Google Cloud KMS messages.
                    - `kmip`: Map with "endpoint" as a host with required port.
                      For example: ``{"endpoint": "example.com:443"}``.
                    - `local`: Map with "key" as `bytes` (96 bytes in length) or
                      a base64 encoded string which decodes
                      to 96 bytes. "key" is the master key used to encrypt/decrypt
                      data keys. This key should be generated and stored as securely
                      as possible.
          
                  KMS providers may be specified with an optional name suffix
                  separated by a colon, for example "kmip:name" or "aws:name".
                  Named KMS providers do not support :ref:`CSFLE on-demand credentials`.
              :param key_vault_namespace: The namespace for the key vault collection.
                  The key vault collection contains all data keys used for encryption
                  and decryption. Data keys are stored as documents in this MongoDB
                  collection. Data keys are protected with encryption by a KMS
                  provider.
              :param key_vault_client: A MongoClient connected to a MongoDB cluster
                  containing the `key_vault_namespace` collection.
              :param codec_options: An instance of
                  :class:`~bson.codec_options.CodecOptions` to use when encoding a
                  value for encryption and decoding the decrypted BSON value. This
                  should be the same CodecOptions instance configured on the
                  MongoClient, Database, or Collection used to access application
                  data.
              :param kms_tls_options: A map of KMS provider names to TLS
                  options to use when creating secure connections to KMS providers.
                  Accepts the same TLS options as
                  :class:`pymongo.mongo_client.MongoClient`. For example, to
                  override the system default CA file::
          
                    kms_tls_options={'kmip': {'tlsCAFile': certifi.where()}}
          
                  Or to supply a client certificate::
          
                    kms_tls_options={'kmip': {'tlsCertificateKeyFile': 'client.pem'}}
          
              .. versionchanged:: 4.0
                 Added the `kms_tls_options` parameter and the "kmip" KMS provider.
          
              .. versionadded:: 3.9
              """
              if not _HAVE_PYMONGOCRYPT:
                  raise ConfigurationError(
                      "client-side field level encryption requires the pymongocrypt "
                      "library: install a compatible version with: "
                      "python -m pip install --upgrade 'pymongo[encryption]'"
                  )
          
              if not isinstance(codec_options, CodecOptions):
                  raise TypeError("codec_options must be an instance of bson.codec_options.CodecOptions")
          
              if not isinstance(key_vault_client, MongoClient):
      >           raise TypeError(f"MongoClient required but given {type(key_vault_client)}")
      E           TypeError: MongoClient required but given <class 'pymongo.synchronous.collection.Collection'>
      

            Assignee:
            noah.stapp@mongodb.com Noah Stapp
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: