From 7c164a4887ce30c9bd2dd23b268cbf644cebf8b8 Mon Sep 17 00:00:00 2001 From: Vladimir Homutov Date: Thu, 26 Sep 2019 19:04:32 +0300 Subject: [PATCH] Added dockerfile for tests. It is now possible to run testsuite in docker, using supplied file. See instructions in t/README. Tests are adjusted to run on alpine linux which includes modular builds of openldap server software. --- Dockerfile.test | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ t/README | 7 +++++++ t/ldap-auth.t | 2 ++ t/runtests.sh | 13 +++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 Dockerfile.test create mode 100755 t/runtests.sh diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..6985ce7 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,49 @@ +FROM python:2-alpine + +WORKDIR /usr/src/app/ +COPY nginx-ldap-auth-daemon.py /usr/src/app/ + +WORKDIR /tests +COPY t/ldap-auth.t /tests +COPY t/runtests.sh /tests + +# Install required software +RUN \ + apk --no-cache add openldap-dev && \ + apk --no-cache add openldap && \ + apk --no-cache add openldap-back-hdb && \ + apk --no-cache add openldap-clients && \ + apk --no-cache add openssl && \ + apk --no-cache add nginx && \ + apk --no-cache add nginx-mod-http-geoip && \ + apk --no-cache add nginx-mod-stream-geoip && \ + apk --no-cache add nginx-mod-http-image-filter && \ + apk --no-cache add nginx-mod-stream && \ + apk --no-cache add nginx-mod-mail && \ + apk --no-cache add nginx-mod-http-perl && \ + apk --no-cache add nginx-mod-http-xslt-filter && \ + apk --no-cache add mercurial && \ + apk --no-cache add perl && \ + apk --no-cache add --virtual build-dependencies build-base && \ + pip install python-ldap && \ + pip install coverage && \ + apk del build-dependencies + + +# Install tests +RUN \ + cd /tests && \ + hg clone https://hg.nginx.org/nginx-tests && \ + mv ldap-auth.t nginx-tests + +WORKDIR /usr/src/app/ + +ENV TEST_LDAP_DAEMON=/usr/sbin/slapd +ENV TEST_LDAP_AUTH_DAEMON=/usr/src/app/nginx-ldap-auth-daemon.py +ENV TEST_NGINX_BINARY=/usr/sbin/nginx +ENV TEST_NGINX_MODULES=/usr/lib/nginx/modules +ENV LDAPTLS_REQCERT=never + +WORKDIR /tests/nginx-tests + +CMD ["/tests/runtests.sh"] diff --git a/t/README b/t/README index 9caf5bb..e124895 100644 --- a/t/README +++ b/t/README @@ -1,3 +1,10 @@ +To run tests use supplied Dockerfile.test: + +docker build -f Dockerfile.test -t my-tag . +docker run my-tag + +To run without Docker: + Test suite is available at http://hg.nginx.org/nginx-tests. Check the http://hg.nginx.org/nginx-tests/file/tip/README file for instructions on how to use it. diff --git a/t/ldap-auth.t b/t/ldap-auth.t index f83974b..22cc20f 100644 --- a/t/ldap-auth.t +++ b/t/ldap-auth.t @@ -264,6 +264,7 @@ access to * by users read by anonymous read +moduleload back_hdb database hdb suffix "dc=test,dc=local" rootdn "cn=root,dc=test,dc=local" @@ -298,6 +299,7 @@ access to * by users read by anonymous read +moduleload back_hdb database hdb suffix "ou=Users, dc=test,dc=local" rootdn "cn=root, ou=Users, dc=test,dc=local" diff --git a/t/runtests.sh b/t/runtests.sh new file mode 100755 index 0000000..3c23f92 --- /dev/null +++ b/t/runtests.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# shell script to start testsuite and run coverage +# to be executed as Dockerfile CMD + +export TEST_NGINX_LEAVE=1 +rm -rf /tmp/nginx-test-* + +perl ldap-auth.t + +testdir=$(find /tmp -name 'nginx-test-*' -print -quit) +cd $testdir +coverage2 html && printf "Coverage report: docker cp :$testdir/htmlcov \n"