source: mod_gnutls/test/Makefile.am @ 15f2849

Last change on this file since 15f2849 was 15f2849, checked in by Fiona Klute <fiona.klute@…>, 5 months ago

Optionally build with LLVM/clang profiling and gather data during tests

  • Property mode set to 100644
File size: 13.3 KB
Line 
1SUBDIRS = tests
2
3VALGRIND_SUPPRESS = suppressions.valgrind
4EXTRA_DIST = $(VALGRIND_SUPPRESS)
5
6if ENABLE_VALGRIND
7valgrind = --valgrind \
8        $(foreach supp,$(VALGRIND_SUPPRESS),--valgrind-suppressions "$(srcdir)/$(supp)")
9else
10valgrind =
11endif
12
13# Generate the test scripts
14test-%.bash: test-template.bash.in | tests/%/
15        testname="$(*)"; \
16        sed -e s/_NUM_/$${testname%%_*}/ -e 's,_VALGRIND_,$(valgrind),' < $< > $@
17        chmod a+x $@
18
19test_scripts = test-00_basic.bash \
20        test-01_serverwide_priorities.bash \
21        test-02_cache_in_vhost.bash \
22        test-03_cachetimeout_in_vhost.bash \
23        test-04_basic_nosni.bash \
24        test-05_mismatched-priorities.bash \
25        test-06_verify_sni_a.bash \
26        test-07_verify_sni_b.bash \
27        test-08_verify_no_sni_fallback_to_first_vhost.bash \
28        test-09_verify_no_sni_fails_with_wrong_order.bash \
29        test-10_basic_client_verification.bash \
30        test-11_basic_client_verification_fail.bash \
31        test-12_cgi_variables.bash \
32        test-13_cgi_variables_no_client_cert.bash \
33        test-14_resume_session.bash
34if USE_MSVA
35test_scripts += test-15_basic_msva.bash
36endif
37test_scripts += test-16_view-status.bash \
38        test-17_cgi_vars_large_cert.bash \
39        test-18_client_verification_wrong_cert.bash \
40        test-19_TLS_reverse_proxy.bash \
41        test-20_TLS_reverse_proxy_client_auth.bash \
42        test-21_TLS_reverse_proxy_wrong_cert.bash \
43        test-22_TLS_reverse_proxy_crl_revoke.bash \
44        test-23_TLS_reverse_proxy_mismatched_priorities.bash \
45        test-24_pkcs11_cert.bash \
46        test-25_Disable_TLS_1.0.bash \
47        test-26_redirect_HTTP_to_HTTPS.bash \
48        test-27_OCSP_server.bash \
49        test-28_HTTP2_support.bash \
50        test-29_force_handshake_vhost.bash \
51        test-30_ip_based_vhosts.bash \
52        test-31_vhost_SNI_serveralias_match.bash \
53        test-32_vhost_SNI_serveralias_mismatch.bash \
54        test-33_vhost_SNI_serveralias_missinghost.bash \
55        test-34_TLS_reverse_proxy_h2.bash \
56        test-35_client_reauth.bash \
57        test-36_OCSP_server_nonce.bash \
58        test-37_TLS_reverse_proxy_resume_session.bash
59
60MOSTLYCLEANFILES = $(test_scripts)
61dist_check_SCRIPTS = netns_py.bash test-template.bash.in
62
63TEST_EXTENSIONS = .bash .py
64PY_LOG_COMPILER = $(PYTHON)
65TESTS = doctest-mgstest.py $(test_scripts)
66
67check_PROGRAMS = pgpcrc
68pgpcrc_SOURCES = pgpcrc.c
69
70# build OCSP database tool
71if ENABLE_OCSP_TEST
72check_PROGRAMS += gen_ocsp_index
73gen_ocsp_index_SOURCES = gen_ocsp_index.c cert_helper.c
74gen_ocsp_index_CFLAGS = $(LIBGNUTLS_CFLAGS)
75gen_ocsp_index_LDFLAGS = $(LIBGNUTLS_LIBS)
76noinst_HEADERS = cert_helper.h
77endif
78
79# Python tools for tests
80noinst_PYTHON = https-test-client.py mgstest/http.py mgstest/__init__.py \
81        mgstest/hooks.py mgstest/ocsp.py mgstest/services.py \
82        mgstest/softhsm.py mgstest/tests.py mgstest/valgrind.py runtest.py \
83        softhsm-init.py doctest-mgstest.py required-modules.py data/ocsp.py
84
85# Identities in the miniature CA, server, and client environment for
86# the test suite
87shared_identities = authority authority/client
88pgp_identities = $(shared_identities)
89x509_only_identities = authority/server authority/imposter \
90        authority/subca authority/subca/server \
91        rogueca rogueca/rogueclient
92if ENABLE_OCSP_TEST
93x509_only_identities += authority/ocsp-responder authority/subca/ocsp-responder
94endif
95x509_identities = $(shared_identities) $(x509_only_identities)
96identities = $(shared_identities) $(x509_only_identities)
97# Append strings after ":=" to each identity to generate a list of
98# necessary files
99pgp_tokens = $(pgp_identities:=/cert.pgp) \
100        $(pgp_identities:=/secret.pgp)
101x509_keys = $(x509_identities:=/secret.key)
102x509_certs = $(x509_identities:=/x509.pem)
103x509_tokens = $(x509_certs) $(x509_keys)
104tokens = $(x509_tokens)
105if USE_MSVA
106tokens += $(pgp_tokens)
107endif
108
109if !DISABLE_FLOCK
110# flock command for write access to the authority keyring
111GPG_FLOCK = @FLOCK@ authority/lock
112endif
113
114include $(srcdir)/test_ca.mk
115
116# Test cases trying to create keys and certificates in parallel causes
117# race conditions. Ensure that all keys and certificates are generated
118# before tests get to run.
119#
120# NOTE: Once the support files have been generated, test cases can be
121# run with multiple jobs, but real parallelization would require
122# dynamic port assignments. At the moment, lock files ensure that only
123# one Apache instance (possibly plus a proxy back end instance) is
124# running at any time, so test cases actually have to wait for each
125# other - just not in any particular order.
126check_DATA = $(tokens) authority/server/crl.pem
127
128MOSTLYCLEANFILES += cache/* logs/* outputs/* authority/server/crl.pem
129
130cert_templates = authority/template.in authority/client/template.in \
131        authority/imposter/template.in authority/ocsp-responder/template \
132        authority/server/template.in \
133        authority/subca/template.in authority/subca/server/template.in \
134        authority/subca/ocsp-responder/template \
135        rogueca/template rogueca/rogueclient/template.in
136generated_templates = authority/template authority/client/template \
137        authority/imposter/template rogueca/rogueclient/template \
138        authority/server/template
139
140# Delete X.509 private keys on full clean. Note that unless you need
141# to generate fresh keys, the "mostlyclean" target should be
142# sufficient (see below).
143CLEANFILES = $(x509_keys)
144
145# Delete X.509 certificates and generated templates on "mostlyclean"
146# target. Certificates can be rebuilt without generating new key
147# pairs, and regenerating them makes it possible to change identities
148# (e.g. host names) without wasting time on new keys (which would
149# happen after "clean").
150MOSTLYCLEANFILES += $(x509_certs) $(generated_templates) $(identities:=/uid)
151
152
153# Delete PGP keyrings on "mostlyclean" target. They are created from
154# the X.509 private keys and certificates with an expiration time of
155# one day, so regenerating them is both fast and frequently
156# necessary.
157pgp_patterns = /*.pgp /*.pgp.raw /*.gpg /*.gpg~ /gpg.conf \
158        /*.kbx /*.kbx~ /S.gpg-agent /private-keys-v1.d/*
159MOSTLYCLEANFILES += $(foreach pat,$(pgp_patterns),$(pgp_identities:=$(pat))) \
160        authority/lock authority/tofu.db
161# GnuPG random pool, no need to regenerate on every build
162CLEANFILES += authority/random_seed
163
164# GnuPG 2 starts gpg-agent processes per GNUPGHOME (one for every PGP
165# identity) while creating the PGP certificates. This target is called
166# by both "check-local" and "mostlyclean-local": The former because
167# agent processes are started while preparing for "check" and are no
168# longer needed afterwards, the latter to make sure they are gone
169# along with their certificates.
170stop-gnupg-agent:
171        for id in $(pgp_identities) $(msva_home); do \
172                GNUPGHOME=$$id/ gpgconf --kill gpg-agent || true; \
173        done
174
175check-local: stop-gnupg-agent
176
177# Delete lock files for test servers on "mostlyclean" target.
178MOSTLYCLEANFILES += *.lock
179
180# rule to build MSVA trust database
181if USE_MSVA
182msva_home = msva.gnupghome
183check_DATA += $(msva_home)/trustdb.gpg authority/client/uid
184MOSTLYCLEANFILES += $(foreach pat,$(pgp_patterns),$(msva_home)$(pat))
185$(msva_home)/trustdb.gpg: authority/minimal.pgp authority/client/cert.pgp
186        mkdir -p -m 0700 $(dir $@)
187        GNUPGHOME=$(dir $@) gpg --import < $<
188        printf "%s:6:\n" "$$(GNUPGHOME=authority/ gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" | GNUPGHOME=$(dir $@) gpg --import-ownertrust
189        GNUPGHOME=$(dir $@) gpg --import < authority/client/cert.pgp
190        printf "keyserver does-not-exist.example\n" > $(msva_home)/gpg.conf
191endif
192
193if ENABLE_OCSP_TEST
194# rules to build OCSP database
195ocsp_index_data = authority/ocsp_index.txt authority/ocsp_index.txt.attr \
196        authority/subca/ocsp_index.txt authority/subca/ocsp_index.txt.attr
197check_DATA += $(ocsp_index_data)
198MOSTLYCLEANFILES += $(ocsp_index_data)
199
200# The "find" command builds a list of all certificates directly below
201# the CA that aren't for the ocsp-responder.
202%/ocsp_index.txt: $(x509_tokens) gen_ocsp_index
203        ./gen_ocsp_index $$(find $(*) -mindepth 2 -maxdepth 2 ! -path '*/ocsp-responder/*' -name x509.pem) > $@
204
205%/ocsp_index.txt.attr:
206        @mkdir -m 0700 -p $(dir $@)
207        echo "unique_subject = no" > $@
208
209# Build certificate chain files. Note that intermediate tokens must be
210# listed explicitly, or the dependency chain will be broken because
211# the higher level pattern matches, too.
212chain_tokens = authority/server/x509-chain.pem \
213        authority/subca/x509-chain.pem \
214        authority/subca/server/x509-chain.pem
215check_DATA += $(chain_tokens)
216MOSTLYCLEANFILES += $(chain_tokens) authority/x509-chain.pem
217endif
218
219# SoftHSM token, note that the SoftHSM 2 token is a directory
220SOFTHSM2_TOKEN = authority/server/softhsm2.db
221# included in mostlyclean-local below
222clean-softhsm2-db:
223        -rm -rf $(SOFTHSM2_TOKEN)
224
225if HAVE_SOFTHSM
226check_DATA += $(SOFTHSM2_TOKEN)
227endif HAVE_SOFTHSM
228
229check_DATA += make-test-dirs
230extra_dirs = logs cache outputs
231make-test-dirs:
232        mkdir -p $(extra_dirs)
233
234.PHONY: make-test-dirs clean-softhsm2-db stop-gnupg-agent
235
236
237if ENABLE_COVERAGE
238coverage_raw_dir = outputs/coverage
239MOSTLYCLEANFILES += $(coverage_raw_dir)/*
240endif
241
242mostlyclean-local: clean-softhsm2-db stop-gnupg-agent
243        -rmdir $(pgp_identities:=/private-keys-v1.d) || true
244if USE_MSVA
245        -rmdir $(msva_home)/private-keys-v1.d || true
246endif
247
248# Delete test data directories, and wait for test services to
249# exit. The reason for the wait is that Apache instances may take some
250# time to exit and delete their PID files. Occasionally some PID files
251# where still around during "distcheck" runs by the time the target
252# checked if the build directory was really empty after "distclean",
253# breaking the build. Delaying "clean-local" until PID files are gone
254# avoids this issue, and the timeout will expose actually unclean
255# stops.
256clean-local:
257if ENABLE_COVERAGE
258        -rmdir $(coverage_raw_dir) || true
259endif
260        -rmdir $(extra_dirs) || true
261if USE_MSVA
262        -rmdir $(msva_home) || true
263endif
264        wait=0; \
265        while ls *.pid && test "$$wait" -lt "@TEST_LOCK_WAIT@"; do \
266                wait=$$(($$wait + 1)); \
267                echo "waiting for test services to exit ($$wait seconds)"; \
268                sleep 1; \
269        done
270
271# Apache configuration and data files
272apache_data = base_apache.conf cgi_module.conf data/dump.cgi \
273        data/test.txt data/secret/mirror.cgi data/secret/test.txt \
274        mime.types proxy_mods.conf
275
276# Which modules are compiled into the Apache binary varies between
277# distributions. required-modules.py creates additional LoadModule
278# directives if needed.
279check_DATA += apache-conf/required-modules.conf
280MOSTLYCLEANFILES += apache-conf/required-modules.conf
281apache-conf/required-modules.conf: required-modules.py
282        APACHE2=@APACHE2@ AP_LIBEXECDIR=@AP_LIBEXECDIR@ $(PYTHON) $< >$@
283
284# Documentation for the test system
285test_doc = README.md sample_fail.yml sample_test.yml
286
287EXTRA_DIST += $(apache_data) $(cert_templates) $(shared_identities:=/uid.in) \
288        authority/server/crl.template $(test_doc)
289
290# Lockfile for the main Apache process
291test_lockfile = ./test.lock
292# Lockfile for the proxy backend Apache process (if any)
293backend_lockfile = ./backend.lock
294# Lockfile for the OCSP server Apache process (if any)
295ocsp_lockfile = ./ocsp.lock
296
297# port for the main Apache server
298TEST_PORT ?= 9932
299# port for MSVA in test cases that use it
300MSVA_PORT ?= 9933
301# port for TLS proxy backend server
302BACKEND_PORT ?= 9934
303# port for plain HTTP server
304TEST_HTTP_PORT ?= 9935
305# port for the OCSP responder
306if ENABLE_OCSP_TEST
307OCSP_PORT ?= 9936
308OCSP_URI_TEMPLATE = ocsp_uri = http://$(TEST_HOST):$(OCSP_PORT)/ocsp/
309endif
310# maximum time to wait for MSVA startup (milliseconds)
311TEST_SERVICE_MAX_WAIT ?= 10000
312# wait loop time for MSVA startup (milliseconds)
313TEST_SERVICE_WAIT ?= 400
314
315AM_TESTS_ENVIRONMENT = export APACHE2=@APACHE2@; \
316        export AP_LIBEXECDIR=@AP_LIBEXECDIR@; \
317        export PYTHON="@PYTHON@"; \
318        export TEST_LOCK_WAIT="@TEST_LOCK_WAIT@"; \
319        export TEST_IP="@TEST_IP@"; \
320        export TEST_HOST="@TEST_HOST@"; \
321        export TEST_PORT="$(TEST_PORT)"; \
322        export MSVA_PORT="$(MSVA_PORT)"; \
323        export TEST_SERVICE_MAX_WAIT="$(TEST_SERVICE_MAX_WAIT)"; \
324        export TEST_SERVICE_WAIT="$(TEST_SERVICE_WAIT)"; \
325        export TEST_QUERY_TIMEOUT="@TEST_QUERY_TIMEOUT@"; \
326        export BACKEND_HOST="@TEST_HOST@"; \
327        export BACKEND_PORT="$(BACKEND_PORT)"; \
328        export TEST_HTTP_PORT="$(TEST_HTTP_PORT)"; \
329        export HTTP_CLI="@HTTP_CLI@";
330
331if HAVE_SOFTHSM
332AM_TESTS_ENVIRONMENT += export SOFTHSM="@SOFTHSM@"; \
333        export SOFTHSM_LIB="@SOFTHSM_LIB@";
334endif
335
336if ENABLE_OCSP_TEST
337AM_TESTS_ENVIRONMENT += export OPENSSL="@OPENSSL@"; \
338        export OCSP_PORT="$(OCSP_PORT)";
339endif
340
341if ENABLE_VALGRIND
342AM_TESTS_ENVIRONMENT += export VALGRIND="@VALGRIND@";
343endif
344
345if ENABLE_NETNS
346AM_TESTS_ENVIRONMENT += export UNSHARE="@UNSHARE@"; \
347        export USE_TEST_NAMESPACE=1;
348endif
349# Without flock tests must not run in parallel, and PID files are used
350# to prevent conflicts between server instances. Otherwise set lock
351# files for flock.
352if DISABLE_FLOCK
353AM_TESTS_ENVIRONMENT += export TEST_LOCK="apache2.pid"; \
354        export BACKEND_LOCK="backend.pid"; \
355        export OCSP_LOCK="ocsp.pid";
356.NOTPARALLEL:
357else
358AM_TESTS_ENVIRONMENT += export FLOCK="@FLOCK@"; \
359        export TEST_LOCK="$(test_lockfile)"; \
360        export BACKEND_LOCK="$(backend_lockfile)"; \
361        export OCSP_LOCK="$(ocsp_lockfile)";
362endif
363
364if ENABLE_COVERAGE
365AM_TESTS_ENVIRONMENT += export LLVM_PROFILE_FILE="$(coverage_raw_dir)/%p-%3m.profraw";
366endif
367
368# Echo AM_TESTS_ENVIRONMENT. This can be useful for debugging, e.g. if
369# you want to manually run an Apache instance with Valgrind using the
370# same configuration as a test case.
371show-test-env: export TEST_ENV=$(AM_TESTS_ENVIRONMENT)
372show-test-env:
373        @echo "$${TEST_ENV}"
374
375# Build the test suite README as HTML if pandoc is available.
376if USE_PANDOC
377noinst_DATA = README.html
378MOSTLYCLEANFILES += $(noinst_DATA)
379%.html: %.md $(srcdir)/../doc/style.css
380        $(PANDOC) --css $(filter %.css,$^) --metadata pagetitle="$(<)" --self-contained -f markdown -o $@ $<
381endif
Note: See TracBrowser for help on using the repository browser.