Skip to content

Commit

Permalink
separate user_attrs into privileged so other methods can run
Browse files Browse the repository at this point in the history
  • Loading branch information
ja5087 committed Apr 21, 2019
1 parent 4620511 commit f72177c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ocflib/account/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def validate_calnet_uid(uid):
raise ValidationError(
'CalNet UID already has account: ' + str(existing_accounts))

attrs = search.user_attrs_ucb(uid)
attrs = search.user_attrs_ucb_privileged(uid)

if not attrs:
raise ValidationError("CalNet UID can't be found in university LDAP.")
Expand Down
5 changes: 5 additions & 0 deletions ocflib/account/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def user_attrs_ucb(uid):
base=UCB_LDAP_PEOPLE)


def user_attrs_ucb_privileged(uid):
return user_attrs(uid, connection=ldap.ldap_ucb_privileged,
base=UCB_LDAP_PEOPLE)


def user_exists(account):
"""Returns whether username is an OCF account."""
return bool(user_attrs(account))
Expand Down
8 changes: 4 additions & 4 deletions ocflib/vhost/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests

from ocflib.account.search import user_attrs
from ocflib.account.search import user_attrs_ucb
from ocflib.account.search import user_attrs_ucb_privileged

VHOST_DB_PATH = '/home/s/st/staff/vhost/vhost.conf'
VHOST_DB_URL = 'https://www.ocf.berkeley.edu/~staff/vhost.conf'
Expand Down Expand Up @@ -86,9 +86,9 @@ def eligible_for_vhost(user):
if 'callinkOid' in attrs:
return True
elif 'calnetUid' in attrs:
attrs_ucb = user_attrs_ucb(attrs['calnetUid'])
# TODO: Uncomment when we get a privileged LDAP bind.
if attrs_ucb: # and 'EMPLOYEE-TYPE-ACADEMIC' in attrs_ucb['berkeleyEduAffiliations']:
attrs_ucb = user_attrs_ucb_privileged(attrs['calnetUid'])

if attrs_ucb and 'EMPLOYEE-TYPE-ACADEMIC' in attrs_ucb['berkeleyEduAffiliations']:
return True

return False
4 changes: 2 additions & 2 deletions tests/account/creation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def fake_credentials(mock_rsa_key):
@pytest.yield_fixture
def mock_valid_calnet_uid():
with mock.patch(
'ocflib.account.search.user_attrs_ucb',
'ocflib.account.search.user_attrs_ucb_privileged',
return_value={'berkeleyEduAffiliations': ['STUDENT-TYPE-REGISTERED']}
):
yield
Expand All @@ -453,7 +453,7 @@ def mock_valid_calnet_uid():
@pytest.yield_fixture
def mock_invalid_calnet_uid():
with mock.patch(
'ocflib.account.search.user_attrs_ucb',
'ocflib.account.search.user_attrs_ucb_privileged',
return_value={'berkeleyEduAffiliations': ['STUDENT-STATUS-EXPIRED']},
):
yield
Expand Down

0 comments on commit f72177c

Please sign in to comment.