1 | # Unit Tests for Apache's mod_gnutls |
---|
2 | |
---|
3 | Authors: |
---|
4 | Daniel Kahn Gillmor <dkg@fifthhorseman.net>, |
---|
5 | Fiona Klute <fiona.klute@gmx.de> |
---|
6 | |
---|
7 | There are a lot of ways that a TLS-capable web server can go wrong. I |
---|
8 | want to at least test for some basic/common configurations. |
---|
9 | |
---|
10 | |
---|
11 | ## Running the tests |
---|
12 | |
---|
13 | From the top level of the source, or from `test/` (where this README is), |
---|
14 | just run: |
---|
15 | |
---|
16 | ```bash |
---|
17 | $ make check |
---|
18 | ``` |
---|
19 | |
---|
20 | You can also run specific test cases by passing their script names to |
---|
21 | make in the `TESTS` variable: |
---|
22 | |
---|
23 | ```bash |
---|
24 | $ TESTS="test-03_cachetimeout_in_vhost.bash" make -e check |
---|
25 | ``` |
---|
26 | |
---|
27 | This should be handy when you're just trying to experiment with a new |
---|
28 | test and don't want to wait for the full test suite to run. |
---|
29 | |
---|
30 | The default configuration assumes that a loopback device with IPv4 and |
---|
31 | IPv6 support is available (`TEST_IP="[::1] 127.0.0.1"`) and that |
---|
32 | `TEST_HOST="localhost"` resolves to at least one of these |
---|
33 | addresses. If this does not apply to your system, you can pass |
---|
34 | different values to `./configure`, e.g. to use IPv4 only: |
---|
35 | |
---|
36 | ```bash |
---|
37 | $ TEST_HOST="localhost" TEST_IP="127.0.0.1" ./configure |
---|
38 | ``` |
---|
39 | |
---|
40 | If tests fail due to expired certificates or PGP signatures, run |
---|
41 | |
---|
42 | ```bash |
---|
43 | $ make mostlyclean |
---|
44 | ``` |
---|
45 | |
---|
46 | to delete them and create fresh ones on the next test run. You could |
---|
47 | also use `make clean`, but in that case the keys will be deleted as |
---|
48 | well and have to be recreated, too, which takes more time. |
---|
49 | |
---|
50 | |
---|
51 | ## Adding a Test |
---|
52 | |
---|
53 | Please add more tests! |
---|
54 | |
---|
55 | The simplest way to add a test is (from the directory containing this |
---|
56 | file): |
---|
57 | |
---|
58 | ```bash |
---|
59 | $ ./newtest |
---|
60 | ``` |
---|
61 | |
---|
62 | This will prompt you for a simple name for the test, copy a starting |
---|
63 | set of files from `tests/00_basic`, and create a script which you can |
---|
64 | add to the `test_scripts` variable in `Makefile.am` when your test is |
---|
65 | ready for inclusion in the test suite. The files in the test directory |
---|
66 | must be added to `EXTRA_DIST` in `tests/Makefile.am`. |
---|
67 | |
---|
68 | |
---|
69 | ## Implementation |
---|
70 | |
---|
71 | Each test consists of a script in the directory containing this README |
---|
72 | and a directory in tests/, which the test suite uses to spin up an |
---|
73 | isolated Apache instance (or more, for tests that need a proxy or OCSP |
---|
74 | responder) and try to connect to it with gnutls-cli and make a simple |
---|
75 | HTTP 1.1 or 1.0 request. |
---|
76 | |
---|
77 | Test directories usually contain the following files: |
---|
78 | |
---|
79 | * `apache.conf` -- Apache configuration to be used |
---|
80 | |
---|
81 | * `test.yml` -- Defines the client connection(s) including parameters |
---|
82 | for `gnutls-cli`, the request(s), and expected response(s). Please |
---|
83 | see the module documentation of [mgstest.tests](./mgstest/tests.py) |
---|
84 | for details, and [`sample_test.yml`](./sample_test.yml) and |
---|
85 | [`sample_fail.yml`](./sample_fail.yml) for examples. |
---|
86 | |
---|
87 | * `backend.conf` [optional] -- Apache configuration for the proxy |
---|
88 | backend server, if any |
---|
89 | |
---|
90 | * `ocsp.conf` [optional] -- Apache configuration for the OCSP |
---|
91 | responder, if any |
---|
92 | |
---|
93 | * `fail.server` [optional] -- if this file exists, it means we expect |
---|
94 | the web server to fail to even start due to some serious |
---|
95 | configuration problem. |
---|
96 | |
---|
97 | * `hooks.py` [optional] -- Defines hook functions that modify or |
---|
98 | override the default behavior of `runtest.py`. Please see the module |
---|
99 | documentation of [mgstest.hooks](./mgstest/hooks.py) for details. |
---|
100 | |
---|
101 | The [`runtest.py`](./runtest.py) program is used to start the required |
---|
102 | services send a request (or more) based on the files described |
---|
103 | above. Note that currently some tests take additional steps in their |
---|
104 | test scripts, though `hooks.py` is the preferred mechanism. |
---|
105 | |
---|
106 | By default (if the `unshare` command is available and has the |
---|
107 | permissions required to create network and user namespaces), each test |
---|
108 | case is run inside its own network namespace. This avoids address and |
---|
109 | port conflicts with other tests as well has the host system. Otherwise |
---|
110 | the tests use a lock file to prevent port conflicts between |
---|
111 | themselves. |
---|
112 | |
---|
113 | When writing your own tests, make sure to call `runtest.py` through |
---|
114 | `netns_py.bash` like the current tests do to ensure compatibility with |
---|
115 | the namespace and lock file mechanisms. |
---|
116 | |
---|
117 | ## Robustness and Tuning |
---|
118 | |
---|
119 | Here are some things that you might want to tune about the tests based |
---|
120 | on your expected setup (along with the variables that can be passed to |
---|
121 | "make check" to adjust them): |
---|
122 | |
---|
123 | * They need a functioning loopback device. |
---|
124 | |
---|
125 | * They expect to have ports 9932 (`TEST_PORT` as defined in |
---|
126 | `Makefile.am`) through 9936 available for test services to bind to, |
---|
127 | and open for connections on the addresses listed in `TEST_IP`. |
---|
128 | |
---|
129 | * Depending on the compile time configuration of the Apache binary |
---|
130 | installed on your system you may need to load additional Apache |
---|
131 | modules. The recommended way to do this is to drop a configuration |
---|
132 | file into the `apache-conf/` directory. Patches to detect such |
---|
133 | situations and automatically configure the tests accordingly are |
---|
134 | welcome. |
---|
135 | |
---|
136 | * If a machine is particularly slow or under heavy load, it's possible |
---|
137 | that tests fail for timing reasons. [`TEST_QUERY_TIMEOUT` (timeout |
---|
138 | for the HTTPS request in seconds)] |
---|
139 | |
---|
140 | The first two of these issues are avoided when the tests are isolated |
---|
141 | using network namespaces, which is the default (see "Implementation" |
---|
142 | above). The `./configure` script tries to detect if namespaces can be |
---|
143 | used (some Linux distributions disable them for unprivileged |
---|
144 | users). If this detection returns a false positive or you do not want |
---|
145 | to use namespace isolation for some other reason, you can run |
---|
146 | configure with the `--disable-test-namespaces` option. |
---|
147 | |
---|
148 | In some situations you may want to see the exact environment as |
---|
149 | configured by make, e.g. if you want to manually run an Apache |
---|
150 | instance with Valgrind using the same configuration as a test |
---|
151 | case. Use `make show-test-env` to dump `AM_TESTS_ENVIRONMENT` to |
---|
152 | stdout. If you want to load the test environment into the current bash |
---|
153 | instance, you can use: |
---|
154 | |
---|
155 | ```bash |
---|
156 | $ eval $(make show-test-env) |
---|
157 | ``` |
---|
158 | |
---|
159 | If you are building on an exotic architecture which does not support |
---|
160 | flock (or timeouts using `flock -w`), `./configure` should detect that |
---|
161 | and disable locking, or you can disable it manually by passing |
---|
162 | `--disable-flock` to `./configure`. This will force serial execution |
---|
163 | of tests, including environment setup. |
---|