Skip to content

Commit

Permalink
Merge pull request #141 from pirates-cat/ldap-ci-setup
Browse files Browse the repository at this point in the history
Solve LDAP setup issues in CI
  • Loading branch information
txels authored Apr 9, 2024
2 parents 55f58ad + b80ec2f commit daed2ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ jobs:
SHIPANARO_LDAP_USER_SEARCH: "(&(objectclass=pilotPerson)(uid=%(user)s))"
run: |
pipenv run ./manage.py compilemessages
pipenv run ./create_ldap_user.py tester tester
pipenv run ./create_test_ldap_user.py tester tester
pipenv run ./manage.py test
1 change: 1 addition & 0 deletions create_ldap_user.py → create_test_ldap_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class User:
from humans import directory

conn = directory.connect()
ou, ou_attrs = directory.create_ou(conn, "afiliats")
user_dn, user_attrs = directory.create_user(conn, user, email)
directory.set_password(conn, user_dn, password)

Expand Down
15 changes: 14 additions & 1 deletion humans/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
LDAP_BIND_DN = environ.get("SHIPANARO_LDAP_BIND_DN", "cn=admin,dc=pirata,dc=cat")
LDAP_BIND_PASS = environ.get("SHIPANARO_LDAP_BIND_PASSWORD", "admin")

ORG_UNIT = "ou=afiliats,dc=pirata,dc=cat"
DOMAIN = "dc=pirata,dc=cat"
ORG_UNIT = f"ou=afiliats,{DOMAIN}"


def connect() -> LDAPObject:
Expand All @@ -38,6 +39,18 @@ def create_user(connection, user, email):
return user_dn, user_attrs


def create_ou(connection, name):
dn = f"ou={name},{DOMAIN}"

attrs = {}
attrs["objectClass"] = [b"organizationalUnit"]
attrs["ou"] = (name.encode("utf-8"),)

ldif = modlist.addModlist(attrs)
result = connection.add_s(dn, ldif)
return dn, attrs


def get_user(connection, username):
search_dn = f"uid={username},{ORG_UNIT}"
try:
Expand Down

0 comments on commit daed2ad

Please sign in to comment.