Return True if db_user/db_password is already an admin user.
(self)
| 372 | return auth_type in auth_mechs |
| 373 | |
| 374 | def _check_user_provided(self): |
| 375 | """Return True if db_user/db_password is already an admin user.""" |
| 376 | client: MongoClient = pymongo.MongoClient( |
| 377 | host, |
| 378 | port, |
| 379 | username=db_user, |
| 380 | password=db_pwd, |
| 381 | **self.default_client_options, |
| 382 | ) |
| 383 | |
| 384 | try: |
| 385 | return db_user in _all_users(client.admin) |
| 386 | except pymongo.errors.OperationFailure as e: |
| 387 | assert e.details is not None |
| 388 | msg = e.details.get("errmsg", "") |
| 389 | if e.code == 18 or "auth fails" in msg: |
| 390 | # Auth failed. |
| 391 | return False |
| 392 | else: |
| 393 | raise |
| 394 | finally: |
| 395 | client.close() |
| 396 | |
| 397 | def _server_started_with_auth(self): |
| 398 | # MongoDB >= 2.0 |
no test coverage detected