Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lvps committed Apr 11, 2024
1 parent 6c1bef0 commit a35cb05
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI
on:
push:
pull_request:

env:
LDAP_BIND_SERVER: "ldap://dirsrv:3389"
LDAP_BIND_DN: "cn=Directory Manager"
LDAP_BIND_PASSWORD: "asd"
TEST_SUFFIX: "dc=example,dc=test"

jobs:
run-tests:
strategy:
matrix:
python: [ '3.9', '3.12', 'latest' ]

services:
dirsrv:
image: "389ds/dirsrv:3.0"
ports:
- 3389:3389
env:
DS_SUFFIX_NAME: ${{env.TEST_SUFFIX}}
DS_DM_PASSWORD: ${{env.LDAP_BIND_PASSWORD}}
options: >-
--health-cmd "dsctl localhost healthcheck --check backends:localhost:search" --health-interval 10s --health-timeout 5s --health-retries 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
run: |
pip install -r requirements.txt
- name: Install pytest
run: |
pip install pytest
- name: Run test script
run: |
pytest tests/tests.py
39 changes: 22 additions & 17 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def userunknown_old_key():

@pytest.fixture(autouse=True)
def reset_database():
# the official container takes a while before 389DS actually accepts the password that was passed as an env var,
# so we try to connect for 30 s and then actually reset the database
done = False
tries = 0
while not done:
try:
with LdapConnection() as conn:
done = True
except ldap.INVALID_CREDENTIALS as e:
tries += 1
if tries > 30:
raise e
else:
print(f"LDAP invalid credentials, attempt {str(tries)} failed")
time.sleep(1)

with LdapConnection() as conn:
things = (
f'ou=groups,{SUFFIX}',
Expand All @@ -110,23 +126,12 @@ def reset_database():
# conn.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-dynamic-plugins', b'on')])
# conn.modify_s('cn=MemberOf Plugin,cn=plugins,cn=config', [(ldap.MOD_REPLACE, 'nsslapd-pluginEnabled', b'on')])

done = False
tries = 0
while not done:
try:
with open(str(os.path.join(os.path.dirname(__file__), 'create-backend.ldif')), 'rb') as f:
parser = LdifReaderAdd(f, conn)
parser.parse()
done = True
except ldap.INVALID_CREDENTIALS as e:
# the official container takes a while before 389DS actually accepts the password that was passed as an env var
tries += 1
if tries > 30:
raise e
else:
time.sleep(1)
except ldap.ALREADY_EXISTS:
done = True
try:
with open(str(os.path.join(os.path.dirname(__file__), 'create-backend.ldif')), 'rb') as f:
parser = LdifReaderAdd(f, conn)
parser.parse()
except ldap.ALREADY_EXISTS:
pass

with open(str(os.path.join(os.path.dirname(__file__), 'testdata.ldif')), 'rb') as f:
parser = LdifReaderAdd(f, conn)
Expand Down

0 comments on commit a35cb05

Please sign in to comment.