Check for overflows in EOC.
[openssl.git] / test / README.ssltest.md
1 # SSL tests
2
3 SSL testcases are configured in the `ssl-tests` directory.
4
5 Each `ssl_*.conf.in` file contains a number of test configurations. These files
6 are used to generate testcases in the OpenSSL CONF format.
7
8 The precise test output can be dependent on the library configuration. The test
9 harness generates the output files on the fly.
10
11 However, for verification, we also include checked-in configuration outputs
12 corresponding to the default configuration. These testcases live in
13 `test/ssl-tests/*.conf` files. Therefore, whenever you're adding or updating a
14 generated test, you should run
15
16 ```
17 $ ./config
18 $ cd test
19 $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/my.conf.in \
20   > ssl-tests/my.conf
21 ```
22
23 where `my.conf.in` is your test input file.
24
25 For example, to generate the test cases in `ssl-tests/01-simple.conf.in`, do
26
27 ```
28 $ TOP=.. perl generate_ssl_tests.pl ssl-tests/01-simple.conf.in > ssl-tests/01-simple.conf
29 ```
30
31 For more details, see `ssl-tests/01-simple.conf.in` for an example.
32
33 ## Configuring the test
34
35 First, give your test a name. The names do not have to be unique.
36
37 An example test input looks like this:
38
39 ```
40     {
41         name => "test-default",
42         server => { "CipherString" => "DEFAULT" },
43         client => { "CipherString" => "DEFAULT" },
44         test   => { "ExpectedResult" => "Success" },
45     }
46 ```
47
48 The test section supports the following options:
49
50 * ExpectedResult - expected handshake outcome. One of
51   - Success - handshake success
52   - ServerFail - serverside handshake failure
53   - ClientFail - clientside handshake failure
54   - InternalError - some other error
55
56 * ClientAlert, ServerAlert - expected alert. See `ssl_test_ctx.c` for known
57   values.
58
59 * Protocol - expected negotiated protocol. One of
60   SSLv3, TLSv1, TLSv1.1, TLSv1.2.
61
62 * ClientVerifyCallback - the client's custom certificate verify callback.
63   Used to test callback behaviour. One of
64   - AcceptAll - accepts all certificates.
65   - RejectAll - rejects all certificates.
66
67 ## Configuring the client and server
68
69 The client and server configurations can be any valid `SSL_CTX`
70 configurations. For details, see the manpages for `SSL_CONF_cmd`.
71
72 Give your configurations as a dictionary of CONF commands, e.g.
73
74 ```
75 server => {
76     "CipherString" => "DEFAULT",
77     "MinProtocol" => "TLSv1",
78 }
79 ```
80
81 ### Default server and client configurations
82
83 The default server certificate and CA files are added to the configurations
84 automatically. Server certificate verification is requested by default.
85
86 You can override these options by redefining them:
87
88 ```
89 client => {
90     "VerifyCAFile" => "/path/to/custom/file"
91 }
92 ```
93
94 or by deleting them
95
96 ```
97 client => {
98     "VerifyCAFile" => undef
99 }
100 ```
101
102 ## Adding a test to the test harness
103
104 Add your configuration file to `test/recipes/80-test_ssl_new.t`.
105
106 ## Running the tests with the test harness
107
108 ```
109 HARNESS_VERBOSE=yes make TESTS=test_ssl_new test
110 ```
111
112 ## Running a test manually
113
114 These steps are only needed during development. End users should run `make test`
115 or follow the instructions above to run the SSL test suite.
116
117 To run an SSL test manually from the command line, the `TEST_CERTS_DIR`
118 environment variable to point to the location of the certs. E.g., from the root
119 OpenSSL directory, do
120
121 ```
122 $ TEST_CERTS_DIR=test/certs test/ssl_test test/ssl-tests/01-simple.conf
123 ```
124
125 or for shared builds
126
127 ```
128 $ TEST_CERTS_DIR=test/certs util/shlib_wrap.sh test/ssl_test \
129   test/ssl-tests/01-simple.conf
130 ```
131
132 Note that the test expectations sometimes depend on the Configure settings. For
133 example, the negotiated protocol depends on the set of available (enabled)
134 protocols: a build with `enable-ssl3` has different test expectations than a
135 build with `no-ssl3`.
136
137 The Perl test harness automatically generates expected outputs, so users who
138 just run `make test` do not need any extra steps.
139
140 However, when running a test manually, keep in mind that the repository version
141 of the generated `test/ssl-tests/*.conf` correspond to expected outputs in with
142 the default Configure options. To run `ssl_test` manually from the command line
143 in a build with a different configuration, you may need to generate the right
144 `*.conf` file from the `*.conf.in` input first.