Skip to content

Commit bda5ecb

Browse files
committed
Create LDAPWrapper to enable local development
Set up ldap 'mock' to allow for testing without access to actual ldap, and for mocking out fake accounts to test various features
1 parent 232ab3f commit bda5ecb

File tree

7 files changed

+281
-216
lines changed

7 files changed

+281
-216
lines changed

config.env.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
# LDAP config
3232
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
3333
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
34+
LDAP_MOCK_MEMBERS = [
35+
{'uid':'evals', 'groups': ['eboard', 'eboard-evaluations', 'active']},
36+
{'uid':'imps-3da', 'groups': ['eboard', 'eboard-imps', '3da', 'active']},
37+
{
38+
'uid':'rtp-cm-webs-onfloor',
39+
'groups': ['active-rtp', 'rtp', 'constitutional_maintainers', 'webmaster', 'active', 'onfloor'],
40+
'room_number': 1024
41+
},
42+
{'uid':'misc-rtp', 'groups': ['rtp']},
43+
{'uid':'onfloor', 'groups': ['active', 'onfloor'], 'room_number': 1024},
44+
{'uid':'active-offfloor', 'groups': ['active']},
45+
{'uid':'alum', 'groups': ['member']},
46+
]
3447

3548
# Mail Config
3649
MAIL_PROD = strtobool(environ.get("PACKET_MAIL_PROD", "False"))

packet/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
# OIDC Auth
6262
auth = OIDCAuthentication({'app': APP_CONFIG}, app)
6363

64-
# LDAP
65-
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
66-
6764
# Sentry
6865
sentry_sdk.init(
6966
dsn=app.config['SENTRY_DSN'],
@@ -73,6 +70,7 @@
7370
app.logger.info('OIDCAuth and LDAP configured')
7471

7572
# pylint: disable=wrong-import-position
73+
from .ldap import ldap
7674
from . import models
7775
from . import context_processors
7876
from . import commands

packet/context_processors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
from functools import lru_cache
77
from datetime import datetime
88

9-
from packet.ldap import ldap_get_member
109
from packet.models import Freshman
11-
from packet import app
10+
from packet import app, ldap
1211

1312

1413
# pylint: disable=bare-except
1514
@lru_cache(maxsize=128)
1615
def get_csh_name(username):
1716
try:
18-
member = ldap_get_member(username)
17+
member = ldap.get_member(username)
1918
return member.cn + ' (' + member.uid + ')'
2019
except:
2120
return username

0 commit comments

Comments
 (0)