diff --git a/.test.env b/.test.env index aeb3a2a..14fd82c 100644 --- a/.test.env +++ b/.test.env @@ -7,3 +7,8 @@ LDAP_BIND_DN=cn=admin,dc=sram,dc=tld LDAP_SIZELIMIT=5 SBS_API_RECORDING=Yes +SBS_URL=http://localhost:3000 +SBS_USER=sysread +SBS_PASS=secret + +CONTAINER_TOOL=podman diff --git a/Makefile b/Makefile index 41a906d..942f36d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ # Makefile +include .test.env +export $(shell sed 's/=.*//' .test.env) + +# Set CONTAINER_TOOL to 'docker' if not defined in .test.env +CONTAINER_TOOL ?= dockers + all: pytest image: - docker build -t plsc . + $(CONTAINER_TOOL) build -t plsc . ldap_start: etc/ldap_start.sh @@ -15,6 +21,6 @@ ldap_stop: etc/ldap_stop.sh pytest: image ldap_start - docker run --rm -ti --network host --volume ${PWD}/api:/opt/plsc/api plsc pytest + $(CONTAINER_TOOL) run --rm -ti --network host --volume ${PWD}/api:/opt/plsc/api plsc pytest clean: ldap_stop diff --git a/README.md b/README.md index 3f17e93..8c23197 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ SBS_USER=sysread SBS_PASS=secret SBS_API_RECORDING=Yes SBS_VERIFY_SSL=Yes + +CONTAINER_TOOL=docker ``` You have the option to run against an operational instance of SBS by specifing the **SBS_URL** and **SBS_USER** /**SBS_PASS** constants as shown above. If you do not want to access an SBS instance, just leave these constant out. @@ -108,6 +110,14 @@ In case you are testing against an operational SBS instance, you have the option When you omit the **SBS_URL** variable, the tests will run API requests agains the contents off this local **./api/...** directory +You may choose to use a different tool than **docker** to run build/run the containers, for example if you want to use **podman** then simply set: + +``` +... +CONTAINER_TOOL=podman +... +``` + When all these preperations are completed, you can now run the tests: ```bash diff --git a/etc/ldap_show.sh b/etc/ldap_show.sh index 685e655..f58a9c5 100755 --- a/etc/ldap_show.sh +++ b/etc/ldap_show.sh @@ -6,6 +6,7 @@ else source .test.env fi +CONTAINER_TOOL=${CONTAINER_TOOL:-docker} # Display result... -docker exec my-ldap ldapsearch -x -H ldap://localhost -b "${LDAP_BASE_DN:-dc=example,dc=org}" +$CONTAINER_TOOL exec my-ldap ldapsearch -x -H ldap://localhost -b "${LDAP_BASE_DN:-dc=example,dc=org}" diff --git a/etc/ldap_start.sh b/etc/ldap_start.sh index 0193109..4b9c27c 100755 --- a/etc/ldap_start.sh +++ b/etc/ldap_start.sh @@ -6,10 +6,12 @@ else source .test.env fi +CONTAINER_TOOL=${CONTAINER_TOOL:-docker} + etc/ldap_stop.sh 2>&1 >/dev/null # Start LDAP server and record pid -docker run \ +$CONTAINER_TOOL run \ --name my-ldap \ --env LDAP_DOMAIN="${LDAP_DOMAIN:-example.org}" \ --env LDAP_BASE_DN="${LDAP_BASE_DN:-dc=example,dc=org}" \ @@ -22,14 +24,14 @@ docker run \ osixia/openldap:latest --loglevel debug --copy-service # copy LDIF files into running container... -docker cp etc/ldif my-ldap:/tmp +$CONTAINER_TOOL cp etc/ldif my-ldap:/tmp sleep 5 # Add schemas -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/access.ldif -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/config.ldif -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/eduPerson.ldif -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/voPerson.ldif -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/groupOfMembers.ldif -docker exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/sramPerson.ldif \ No newline at end of file +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/access.ldif +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/config.ldif +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/eduPerson.ldif +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/voPerson.ldif +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/groupOfMembers.ldif +$CONTAINER_TOOL exec my-ldap ldapadd -H ldap://localhost -D cn=admin,cn=config -w "${LDAP_CONFIG_PASSWORD:-changeme}" -f /tmp/ldif/sramPerson.ldif \ No newline at end of file diff --git a/etc/ldap_stop.sh b/etc/ldap_stop.sh index 27445c3..9a2666b 100755 --- a/etc/ldap_stop.sh +++ b/etc/ldap_stop.sh @@ -1,4 +1,7 @@ #!/bin/bash + +CONTAINER_TOOL=${CONTAINER_TOOL:-docker} + # Kill previous server -docker stop my-ldap +$CONTAINER_TOOL stop my-ldap diff --git a/plsc_ordered.py b/plsc_ordered.py index dc52b52..7fc8242 100755 --- a/plsc_ordered.py +++ b/plsc_ordered.py @@ -75,28 +75,7 @@ def sbs2ldap_record(sbs_uid: str, sbs_user: SBSPerson) -> Tuple[str, LDAPEntry]: record['objectClass'].append('ldapPublicKey') record['voPersonStatus'] = [sbs_user.get('status', 'undefined')] - - # sramPerson attributes - lld = sbs_user.get('last_login_date') - if not lld or lld == "None": - lld = "1970-01-01 00:00:00" - - last_login_date = datetime.datetime.strptime(lld + "+0000", '%Y-%m-%d %H:%M:%S%z') - now = datetime.datetime.now().astimezone() - inactive_days = (now - last_login_date).days - - def res(days, interval): - (div, mod) = divmod(days, interval) - return div * interval - - if inactive_days >= YEAR: - inactive_days = res(inactive_days, YEAR) - elif inactive_days >= MONTH: - inactive_days = res(inactive_days, MONTH) - elif inactive_days >= WEEK: - inactive_days = res(inactive_days, WEEK) - - record['sramInactiveDays'] = [inactive_days] + record['sramInactiveDays'] = [sbs_user.get('sram_inactive_days', 'undefined')] # clean up the lists, such that we return empty lists if no attribute is present, rather than [None] for key, val in record.items(): diff --git a/tests/test_all.py b/tests/test_all.py index d59bfe9..bc41cd1 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -63,6 +63,14 @@ def check_people(rdn, people, context_checks): self.assertTrue('ldapPublicKey' in user_object[list(user_object)[0]]['objectClass']) self.assertTrue('sshPublicKey' in user_object[list(user_object)[0]].keys()) + # Check sram inactive days + if u['user'].get('sram_inactive_days', None): + self.assertTrue('sramInactiveDays' in user_object[list(user_object)[0]].keys()) + self.assertEqual( + user_object[list(user_object)[0]]['sramInactiveDays'], + [str(u['user']['sram_inactive_days'])] + ) + # Here a sequence of function can be initiated to verify this person in a particular context for f in context_checks: f(u, user_object)