mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

mongoengine get_db() does not raise an exception if password set to None

Open gilgamesh7 opened this issue 4 years ago • 4 comments

We use mongoengine==0.23.0 and utilize get_db() to check if mongoengine.connect() returns an authenticated pymongo.connection.Connection object. The behaviour is as expected if the password is incorrect, we get a Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'} exception. However, if the password is set to None , get_db() does not raise an exception and the execution proceeds till the first mongoDB interaction is encountered, at which point we get the {'ok': 0.0, 'errmsg': 'there are no users authenticated', 'code': 13, 'codeName': 'Unauthorized'} exception. Is there a fix or a workaround for this ?

gilgamesh7 avatar Jun 27 '21 23:06 gilgamesh7

I find '+' in my password. And I remove it, then there is no error

chengwenxian avatar Aug 19 '21 01:08 chengwenxian

I find '+' in my password. And I remove it, then there is no error

I means that you can reset your password by 0-9,a-z,A-Z, ".", "_"

chengwenxian avatar Aug 19 '21 01:08 chengwenxian

I find '+' in my password. And I remove it, then there is no error

I means that you can reset your password by 0-9,a-z,A-Z, ".", "_"

Thank you chengwenxian ! Unfortunately, this is not the issue, the issue is that get_db works even when the password is none

gilgamesh7 avatar Aug 19 '21 03:08 gilgamesh7

I find '+' in my password. And I remove it, then there is no error

I means that you can reset your password by 0-9,a-z,A-Z, ".", "_"

Thank you chengwenxian ! Unfortunately, this is not the issue, the issue is that get_db works even when the password is none

Is your authSource same with your db name? like this: mongodb://test:111111@localhost:27017/test_db?authSource=test_db And create, grant user in your db. It resoved this problem, too.

chengwenxian avatar Aug 19 '21 09:08 chengwenxian

@gilgamesh7 My guess is that this is a Pymongo behavior, not MongoEngine. I believe testing your connection right after connect is the recommended approach

bagerard avatar Dec 17 '23 13:12 bagerard