elastic / connectors

Source code for all Elastic connectors, developed by the Search team at Elastic, and home of our Python connector development framework
https://www.elastic.co/guide/en/enterprise-search/master/index.html
Other
58 stars 116 forks source link

[MongoDB] string index out of range #2615

Open artem-shelkovnikov opened 3 weeks ago

artem-shelkovnikov commented 3 weeks ago

Bug Description

Bug found in telemetry, see stack trace:

 File "/usr/share/enterprise-search/lib/python3.10/site-packages/connectors/services/job_scheduling.py", line 96, in _schedule
    await data_source.validate_config()
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/connectors/sources/mongo.py", line 306, in validate_config
    await client[configured_database_name].validate_collection(
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/database.py", line 1301, in validate_collection
    result = self.command(cmd, session=session)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
    return func(self, *args, **kwargs)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/database.py", line 890, in command
    with self.__client._conn_for_reads(read_preference, session) as (
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1330, in _conn_from_server
    with self._checkout(server, session) as conn:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1252, in _checkout
    with server.checkout(handler=err_handler) as conn:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/pool.py", line 1637, in checkout
    conn = self._get_conn(handler=handler)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/pool.py", line 1756, in _get_conn
    conn = self.connect(handler=handler)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/pool.py", line 1607, in connect
    conn.authenticate()
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/pool.py", line 1078, in authenticate
    auth.authenticate(creds, self, reauthenticate=reauthenticate)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/auth.py", line 625, in authenticate
    auth_func(credentials, conn)
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/auth.py", line 528, in _authenticate_default
    return _authenticate_scram(credentials, conn, "SCRAM-SHA-256")
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/auth.py", line 238, in _authenticate_scram
    data = saslprep(credentials.password).encode("utf-8")
  File "/usr/share/enterprise-search/lib/python3.10/site-packages/pymongo/saslprep.py", line 97, in saslprep
    if in_table_d1(data[0]):

Looks like there's a problem validating wrong username/password, something invalid was entered and resulted in non-human-readable password. Probably a string with a space as the only character.

To Reproduce

Steps to reproduce the behavior:

  1. Needs triaging - create a MongoDB connector and enter invalid username/password
  2. Run a sync
  3. Weird error is displayed

Expected behavior

Human-readable error is displayed