From 63cbdc2f24465359b80f62726d2aad870980d8a2 Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Sat, 23 Nov 2019 18:52:19 +0100 Subject: [PATCH] Better handling of environment variables checks --- image/service/slapd/startup.sh | 7 +++---- test/test.bats | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/image/service/slapd/startup.sh b/image/service/slapd/startup.sh index fe605a6a..e6d8c29b 100755 --- a/image/service/slapd/startup.sh +++ b/image/service/slapd/startup.sh @@ -83,13 +83,12 @@ if [ ! -e "$FIRST_START_DONE" ]; then fi # Check that LDAP_BASE_DN and LDAP_DOMAIN are in sync domain_from_base_dn=$(echo $LDAP_BASE_DN | tr ',' '\n' | sed -e 's/^.*=//' | tr '\n' '.' | sed -e 's/\.$//') - set +e - echo "$domain_from_base_dn" | egrep -q ".*$LDAP_DOMAIN\$" - if [ $? -ne 0 ]; then + if `echo "$domain_from_base_dn" | egrep -q ".*$LDAP_DOMAIN\$" || echo $LDAP_DOMAIN | egrep -q ".*$domain_from_base_dn\$"`; then + : # pass + else log-helper error "Error: domain $domain_from_base_dn derived from LDAP_BASE_DN $LDAP_BASE_DN does not match LDAP_DOMAIN $LDAP_DOMAIN" exit 1 fi - set -e } function is_new_schema() { diff --git a/test/test.bats b/test/test.bats index 0c23e147..8902921a 100644 --- a/test/test.bats +++ b/test/test.bats @@ -22,7 +22,7 @@ load test_helper } -@test "ldap domain with ldap base dn" { +@test "ldap domain with non-matching ldap base dn" { run_image -h ldap.example.org -e LDAP_TLS=false -e LDAP_DOMAIN=example.com -e LDAP_BASE_DN="dc=example,dc=org" @@ -35,7 +35,7 @@ load test_helper } -@test "ldap domain with ldap base dn subdomain" { +@test "ldap domain with matching ldap base dn subdomain" { run_image -h ldap.example.fr -e LDAP_TLS=false -e LDAP_DOMAIN=example.fr -e LDAP_BASE_DN="ou=myou,o=example,c=fr" @@ -48,6 +48,19 @@ load test_helper } +@test "ldap base dn domain with matching ldap subdomain" { + + run_image -h ldap.example.fr -e LDAP_TLS=false -e LDAP_DOMAIN=mysub.example.fr -e LDAP_BASE_DN="o=example,c=fr" + + sleep 5 + + CSTATUS=$(check_container) + clear_container + + [ "$CSTATUS" == "running 0" ] + +} + @test "ldap domain with ldap base dn subdomain included" { run_image -h ldap.example.com -e LDAP_TLS=false -e LDAP_DOMAIN=example.com -e LDAP_BASE_DN="ou=myou,o=example,dc=com,c=fr"