mirror of
https://github.com/apidoorman/doorman.git
synced 2026-02-09 11:07:05 -06:00
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""
|
|
Test MongoDB authentication validation
|
|
Validates that MongoDB credentials are required when not in MEM mode
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
def test_mongodb_auth_logic():
|
|
"""Test the MongoDB authentication validation logic"""
|
|
|
|
test_cases = [
|
|
{
|
|
'name': 'MEM mode - no MongoDB credentials required',
|
|
'env': {'MEM_OR_EXTERNAL': 'MEM'},
|
|
'should_require_auth': False
|
|
},
|
|
{
|
|
'name': 'REDIS mode - MongoDB credentials required',
|
|
'env': {'MEM_OR_EXTERNAL': 'REDIS'},
|
|
'should_require_auth': True
|
|
},
|
|
{
|
|
'name': 'EXTERNAL mode - MongoDB credentials required',
|
|
'env': {'MEM_OR_EXTERNAL': 'EXTERNAL'},
|
|
'should_require_auth': True
|
|
}
|
|
]
|
|
|
|
print("MongoDB Authentication Validation Logic Tests")
|
|
print("=" * 70)
|
|
|
|
for test in test_cases:
|
|
mem_or_external = test['env'].get('MEM_OR_EXTERNAL', 'MEM').upper()
|
|
is_mem_mode = mem_or_external == 'MEM'
|
|
requires_auth = not is_mem_mode
|
|
|
|
status = '✓' if requires_auth == test['should_require_auth'] else '✗'
|
|
print(f"{status} {test['name']}")
|
|
print(f" MEM_OR_EXTERNAL={mem_or_external}")
|
|
print(f" Requires MongoDB auth: {requires_auth}")
|
|
print()
|
|
|
|
print("=" * 70)
|
|
print("Implementation Notes:")
|
|
print()
|
|
print("1. In MEM mode:")
|
|
print(" - MongoDB credentials NOT required")
|
|
print(" - Uses in-memory collections only")
|
|
print(" - database.py returns early (line 27-32)")
|
|
print()
|
|
print("2. In REDIS or EXTERNAL mode:")
|
|
print(" - MONGO_DB_USER and MONGO_DB_PASSWORD REQUIRED")
|
|
print(" - RuntimeError raised if credentials missing")
|
|
print(" - Connection URI includes authentication")
|
|
print()
|
|
print("3. Connection URI format:")
|
|
print(" mongodb://{user}:{pass}@{hosts}/doorman")
|
|
print(" mongodb://{user}:{pass}@{hosts}/doorman?replicaSet={rs}")
|
|
print()
|
|
|
|
if __name__ == '__main__':
|
|
test_mongodb_auth_logic()
|