xref: /freebsd/crypto/openssl/test/http_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  * Copyright Siemens AG 2020
4*e0c4386eSCy Schubert  *
5*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
6*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
7*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
8*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
9*e0c4386eSCy Schubert  */
10*e0c4386eSCy Schubert 
11*e0c4386eSCy Schubert #include <openssl/http.h>
12*e0c4386eSCy Schubert #include <openssl/pem.h>
13*e0c4386eSCy Schubert #include <openssl/x509v3.h>
14*e0c4386eSCy Schubert #include <string.h>
15*e0c4386eSCy Schubert 
16*e0c4386eSCy Schubert #include "testutil.h"
17*e0c4386eSCy Schubert 
18*e0c4386eSCy Schubert static const ASN1_ITEM *x509_it = NULL;
19*e0c4386eSCy Schubert static X509 *x509 = NULL;
20*e0c4386eSCy Schubert #define RPATH "/path/result.crt"
21*e0c4386eSCy Schubert 
22*e0c4386eSCy Schubert typedef struct {
23*e0c4386eSCy Schubert     BIO *out;
24*e0c4386eSCy Schubert     char version;
25*e0c4386eSCy Schubert     int keep_alive;
26*e0c4386eSCy Schubert } server_args;
27*e0c4386eSCy Schubert 
28*e0c4386eSCy Schubert /*-
29*e0c4386eSCy Schubert  * Pretty trivial HTTP mock server:
30*e0c4386eSCy Schubert  * For POST, copy request headers+body from mem BIO 'in' as response to 'out'.
31*e0c4386eSCy Schubert  * For GET, redirect to RPATH, else respond with 'rsp' of ASN1 type 'it'.
32*e0c4386eSCy Schubert  * Respond with HTTP version 1.'version' and 'keep_alive' (unless implicit).
33*e0c4386eSCy Schubert  */
mock_http_server(BIO * in,BIO * out,char version,int keep_alive,ASN1_VALUE * rsp,const ASN1_ITEM * it)34*e0c4386eSCy Schubert static int mock_http_server(BIO *in, BIO *out, char version, int keep_alive,
35*e0c4386eSCy Schubert                             ASN1_VALUE *rsp, const ASN1_ITEM *it)
36*e0c4386eSCy Schubert {
37*e0c4386eSCy Schubert     const char *req, *path;
38*e0c4386eSCy Schubert     long count = BIO_get_mem_data(in, (unsigned char **)&req);
39*e0c4386eSCy Schubert     const char *hdr = (char *)req;
40*e0c4386eSCy Schubert     int is_get = count >= 4 && strncmp(hdr, "GET ", 4) == 0;
41*e0c4386eSCy Schubert     int len;
42*e0c4386eSCy Schubert 
43*e0c4386eSCy Schubert     /* first line should contain "<GET or POST> <path> HTTP/1.x" */
44*e0c4386eSCy Schubert     if (is_get)
45*e0c4386eSCy Schubert         hdr += 4;
46*e0c4386eSCy Schubert     else if (TEST_true(count >= 5 && strncmp(hdr, "POST ", 5) == 0))
47*e0c4386eSCy Schubert         hdr += 5;
48*e0c4386eSCy Schubert     else
49*e0c4386eSCy Schubert         return 0;
50*e0c4386eSCy Schubert 
51*e0c4386eSCy Schubert     path = hdr;
52*e0c4386eSCy Schubert     hdr = strchr(hdr, ' ');
53*e0c4386eSCy Schubert     if (hdr == NULL)
54*e0c4386eSCy Schubert         return 0;
55*e0c4386eSCy Schubert     len = strlen("HTTP/1.");
56*e0c4386eSCy Schubert     if (!TEST_strn_eq(++hdr, "HTTP/1.", len))
57*e0c4386eSCy Schubert         return 0;
58*e0c4386eSCy Schubert     hdr += len;
59*e0c4386eSCy Schubert     /* check for HTTP version 1.0 .. 1.1 */
60*e0c4386eSCy Schubert     if (!TEST_char_le('0', *hdr) || !TEST_char_le(*hdr++, '1'))
61*e0c4386eSCy Schubert         return 0;
62*e0c4386eSCy Schubert     if (!TEST_char_eq(*hdr++, '\r') || !TEST_char_eq(*hdr++, '\n'))
63*e0c4386eSCy Schubert         return 0;
64*e0c4386eSCy Schubert     count -= (hdr - req);
65*e0c4386eSCy Schubert     if (count < 0 || out == NULL)
66*e0c4386eSCy Schubert         return 0;
67*e0c4386eSCy Schubert 
68*e0c4386eSCy Schubert     if (strncmp(path, RPATH, strlen(RPATH)) != 0) {
69*e0c4386eSCy Schubert         if (!is_get)
70*e0c4386eSCy Schubert             return 0;
71*e0c4386eSCy Schubert         return BIO_printf(out, "HTTP/1.%c 301 Moved Permanently\r\n"
72*e0c4386eSCy Schubert                           "Location: %s\r\n\r\n",
73*e0c4386eSCy Schubert                           version, RPATH) > 0; /* same server */
74*e0c4386eSCy Schubert     }
75*e0c4386eSCy Schubert     if (BIO_printf(out, "HTTP/1.%c 200 OK\r\n", version) <= 0)
76*e0c4386eSCy Schubert         return 0;
77*e0c4386eSCy Schubert     if ((version == '0') == keep_alive) /* otherwise, default */
78*e0c4386eSCy Schubert         if (BIO_printf(out, "Connection: %s\r\n",
79*e0c4386eSCy Schubert                        version == '0' ? "keep-alive" : "close") <= 0)
80*e0c4386eSCy Schubert             return 0;
81*e0c4386eSCy Schubert     if (is_get) { /* construct new header and body */
82*e0c4386eSCy Schubert         if ((len = ASN1_item_i2d(rsp, NULL, it)) <= 0)
83*e0c4386eSCy Schubert             return 0;
84*e0c4386eSCy Schubert         if (BIO_printf(out, "Content-Type: application/x-x509-ca-cert\r\n"
85*e0c4386eSCy Schubert                        "Content-Length: %d\r\n\r\n", len) <= 0)
86*e0c4386eSCy Schubert             return 0;
87*e0c4386eSCy Schubert         return ASN1_item_i2d_bio(it, out, rsp);
88*e0c4386eSCy Schubert     } else {
89*e0c4386eSCy Schubert         len = strlen("Connection: ");
90*e0c4386eSCy Schubert         if (strncmp(hdr, "Connection: ", len) == 0) {
91*e0c4386eSCy Schubert             /* skip req Connection header */
92*e0c4386eSCy Schubert             hdr = strstr(hdr + len, "\r\n");
93*e0c4386eSCy Schubert             if (hdr == NULL)
94*e0c4386eSCy Schubert                 return 0;
95*e0c4386eSCy Schubert             hdr += 2;
96*e0c4386eSCy Schubert         }
97*e0c4386eSCy Schubert         /* echo remaining request header and body */
98*e0c4386eSCy Schubert         return BIO_write(out, hdr, count) == count;
99*e0c4386eSCy Schubert     }
100*e0c4386eSCy Schubert }
101*e0c4386eSCy Schubert 
http_bio_cb_ex(BIO * bio,int oper,const char * argp,size_t len,int cmd,long argl,int ret,size_t * processed)102*e0c4386eSCy Schubert static long http_bio_cb_ex(BIO *bio, int oper, const char *argp, size_t len,
103*e0c4386eSCy Schubert                            int cmd, long argl, int ret, size_t *processed)
104*e0c4386eSCy Schubert {
105*e0c4386eSCy Schubert     server_args *args = (server_args *)BIO_get_callback_arg(bio);
106*e0c4386eSCy Schubert 
107*e0c4386eSCy Schubert     if (oper == (BIO_CB_CTRL | BIO_CB_RETURN) && cmd == BIO_CTRL_FLUSH)
108*e0c4386eSCy Schubert         ret = mock_http_server(bio, args->out, args->version, args->keep_alive,
109*e0c4386eSCy Schubert                                (ASN1_VALUE *)x509, x509_it);
110*e0c4386eSCy Schubert     return ret;
111*e0c4386eSCy Schubert }
112*e0c4386eSCy Schubert 
test_http_x509(int do_get)113*e0c4386eSCy Schubert static int test_http_x509(int do_get)
114*e0c4386eSCy Schubert {
115*e0c4386eSCy Schubert     X509 *rcert = NULL;
116*e0c4386eSCy Schubert     BIO *wbio = BIO_new(BIO_s_mem());
117*e0c4386eSCy Schubert     BIO *rbio = BIO_new(BIO_s_mem());
118*e0c4386eSCy Schubert     server_args mock_args = { NULL, '0', 0 };
119*e0c4386eSCy Schubert     BIO *rsp, *req = ASN1_item_i2d_mem_bio(x509_it, (ASN1_VALUE *)x509);
120*e0c4386eSCy Schubert     STACK_OF(CONF_VALUE) *headers = NULL;
121*e0c4386eSCy Schubert     const char content_type[] = "application/x-x509-ca-cert";
122*e0c4386eSCy Schubert     int res = 0;
123*e0c4386eSCy Schubert 
124*e0c4386eSCy Schubert     if (wbio == NULL || rbio == NULL || req == NULL)
125*e0c4386eSCy Schubert         goto err;
126*e0c4386eSCy Schubert     mock_args.out = rbio;
127*e0c4386eSCy Schubert     BIO_set_callback_ex(wbio, http_bio_cb_ex);
128*e0c4386eSCy Schubert     BIO_set_callback_arg(wbio, (char *)&mock_args);
129*e0c4386eSCy Schubert 
130*e0c4386eSCy Schubert     rsp = do_get ?
131*e0c4386eSCy Schubert         OSSL_HTTP_get("/will-be-redirected",
132*e0c4386eSCy Schubert                       NULL /* proxy */, NULL /* no_proxy */,
133*e0c4386eSCy Schubert                       wbio, rbio, NULL /* bio_update_fn */, NULL /* arg */,
134*e0c4386eSCy Schubert                       0 /* buf_size */, headers, content_type,
135*e0c4386eSCy Schubert                       1 /* expect_asn1 */,
136*e0c4386eSCy Schubert                       OSSL_HTTP_DEFAULT_MAX_RESP_LEN, 0 /* timeout */)
137*e0c4386eSCy Schubert         : OSSL_HTTP_transfer(NULL, NULL /* host */, NULL /* port */, RPATH,
138*e0c4386eSCy Schubert                              0 /* use_ssl */,NULL /* proxy */, NULL /* no_pr */,
139*e0c4386eSCy Schubert                              wbio, rbio, NULL /* bio_fn */, NULL /* arg */,
140*e0c4386eSCy Schubert                              0 /* buf_size */, headers, content_type,
141*e0c4386eSCy Schubert                              req, content_type, 1 /* expect_asn1 */,
142*e0c4386eSCy Schubert                              OSSL_HTTP_DEFAULT_MAX_RESP_LEN, 0 /* timeout */,
143*e0c4386eSCy Schubert                              0 /* keep_alive */);
144*e0c4386eSCy Schubert     rcert = d2i_X509_bio(rsp, NULL);
145*e0c4386eSCy Schubert     BIO_free(rsp);
146*e0c4386eSCy Schubert     res = TEST_ptr(rcert) && TEST_int_eq(X509_cmp(x509, rcert), 0);
147*e0c4386eSCy Schubert 
148*e0c4386eSCy Schubert  err:
149*e0c4386eSCy Schubert     X509_free(rcert);
150*e0c4386eSCy Schubert     BIO_free(req);
151*e0c4386eSCy Schubert     BIO_free(wbio);
152*e0c4386eSCy Schubert     BIO_free(rbio);
153*e0c4386eSCy Schubert     sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
154*e0c4386eSCy Schubert     return res;
155*e0c4386eSCy Schubert }
156*e0c4386eSCy Schubert 
test_http_keep_alive(char version,int keep_alive,int kept_alive)157*e0c4386eSCy Schubert static int test_http_keep_alive(char version, int keep_alive, int kept_alive)
158*e0c4386eSCy Schubert {
159*e0c4386eSCy Schubert     BIO *wbio = BIO_new(BIO_s_mem());
160*e0c4386eSCy Schubert     BIO *rbio = BIO_new(BIO_s_mem());
161*e0c4386eSCy Schubert     BIO *rsp;
162*e0c4386eSCy Schubert     server_args mock_args = { NULL, '0', 0 };
163*e0c4386eSCy Schubert     const char *const content_type = "application/x-x509-ca-cert";
164*e0c4386eSCy Schubert     OSSL_HTTP_REQ_CTX *rctx = NULL;
165*e0c4386eSCy Schubert     int i, res = 0;
166*e0c4386eSCy Schubert 
167*e0c4386eSCy Schubert     if (wbio == NULL || rbio == NULL)
168*e0c4386eSCy Schubert         goto err;
169*e0c4386eSCy Schubert     mock_args.out = rbio;
170*e0c4386eSCy Schubert     mock_args.version = version;
171*e0c4386eSCy Schubert     mock_args.keep_alive = kept_alive;
172*e0c4386eSCy Schubert     BIO_set_callback_ex(wbio, http_bio_cb_ex);
173*e0c4386eSCy Schubert     BIO_set_callback_arg(wbio, (char *)&mock_args);
174*e0c4386eSCy Schubert 
175*e0c4386eSCy Schubert     for (res = 1, i = 1; res && i <= 2; i++) {
176*e0c4386eSCy Schubert         rsp = OSSL_HTTP_transfer(&rctx, NULL /* server */, NULL /* port */,
177*e0c4386eSCy Schubert                                  RPATH, 0 /* use_ssl */,
178*e0c4386eSCy Schubert                                  NULL /* proxy */, NULL /* no_proxy */,
179*e0c4386eSCy Schubert                                  wbio, rbio, NULL /* bio_update_fn */, NULL,
180*e0c4386eSCy Schubert                                  0 /* buf_size */, NULL /* headers */,
181*e0c4386eSCy Schubert                                  NULL /* content_type */, NULL /* req => GET */,
182*e0c4386eSCy Schubert                                  content_type, 0 /* ASN.1 not expected */,
183*e0c4386eSCy Schubert                                  0 /* max_resp_len */, 0 /* timeout */,
184*e0c4386eSCy Schubert                                  keep_alive);
185*e0c4386eSCy Schubert         if (keep_alive == 2 && kept_alive == 0)
186*e0c4386eSCy Schubert             res = res && TEST_ptr_null(rsp)
187*e0c4386eSCy Schubert                 && TEST_int_eq(OSSL_HTTP_is_alive(rctx), 0);
188*e0c4386eSCy Schubert         else
189*e0c4386eSCy Schubert             res = res && TEST_ptr(rsp)
190*e0c4386eSCy Schubert                 && TEST_int_eq(OSSL_HTTP_is_alive(rctx), keep_alive > 0);
191*e0c4386eSCy Schubert         BIO_free(rsp);
192*e0c4386eSCy Schubert         (void)BIO_reset(rbio); /* discard response contents */
193*e0c4386eSCy Schubert         keep_alive = 0;
194*e0c4386eSCy Schubert     }
195*e0c4386eSCy Schubert     OSSL_HTTP_close(rctx, res);
196*e0c4386eSCy Schubert 
197*e0c4386eSCy Schubert  err:
198*e0c4386eSCy Schubert     BIO_free(wbio);
199*e0c4386eSCy Schubert     BIO_free(rbio);
200*e0c4386eSCy Schubert     return res;
201*e0c4386eSCy Schubert }
202*e0c4386eSCy Schubert 
test_http_url_ok(const char * url,int exp_ssl,const char * exp_host,const char * exp_port,const char * exp_path)203*e0c4386eSCy Schubert static int test_http_url_ok(const char *url, int exp_ssl, const char *exp_host,
204*e0c4386eSCy Schubert                             const char *exp_port, const char *exp_path)
205*e0c4386eSCy Schubert {
206*e0c4386eSCy Schubert     char *user, *host, *port, *path, *query, *frag;
207*e0c4386eSCy Schubert     int exp_num, num, ssl;
208*e0c4386eSCy Schubert     int res;
209*e0c4386eSCy Schubert 
210*e0c4386eSCy Schubert     if (!TEST_int_eq(sscanf(exp_port, "%d", &exp_num), 1))
211*e0c4386eSCy Schubert         return 0;
212*e0c4386eSCy Schubert     res = TEST_true(OSSL_HTTP_parse_url(url, &ssl, &user, &host, &port, &num,
213*e0c4386eSCy Schubert                                         &path, &query, &frag))
214*e0c4386eSCy Schubert         && TEST_str_eq(host, exp_host)
215*e0c4386eSCy Schubert         && TEST_str_eq(port, exp_port)
216*e0c4386eSCy Schubert         && TEST_int_eq(num, exp_num)
217*e0c4386eSCy Schubert         && TEST_str_eq(path, exp_path)
218*e0c4386eSCy Schubert         && TEST_int_eq(ssl, exp_ssl);
219*e0c4386eSCy Schubert     if (res && *user != '\0')
220*e0c4386eSCy Schubert         res = TEST_str_eq(user, "user:pass");
221*e0c4386eSCy Schubert     if (res && *frag != '\0')
222*e0c4386eSCy Schubert         res = TEST_str_eq(frag, "fr");
223*e0c4386eSCy Schubert     if (res && *query != '\0')
224*e0c4386eSCy Schubert         res = TEST_str_eq(query, "q");
225*e0c4386eSCy Schubert     OPENSSL_free(user);
226*e0c4386eSCy Schubert     OPENSSL_free(host);
227*e0c4386eSCy Schubert     OPENSSL_free(port);
228*e0c4386eSCy Schubert     OPENSSL_free(path);
229*e0c4386eSCy Schubert     OPENSSL_free(query);
230*e0c4386eSCy Schubert     OPENSSL_free(frag);
231*e0c4386eSCy Schubert     return res;
232*e0c4386eSCy Schubert }
233*e0c4386eSCy Schubert 
test_http_url_path_query_ok(const char * url,const char * exp_path_qu)234*e0c4386eSCy Schubert static int test_http_url_path_query_ok(const char *url, const char *exp_path_qu)
235*e0c4386eSCy Schubert {
236*e0c4386eSCy Schubert     char *host, *path;
237*e0c4386eSCy Schubert     int res;
238*e0c4386eSCy Schubert 
239*e0c4386eSCy Schubert     res = TEST_true(OSSL_HTTP_parse_url(url, NULL, NULL, &host, NULL, NULL,
240*e0c4386eSCy Schubert                                         &path, NULL, NULL))
241*e0c4386eSCy Schubert         && TEST_str_eq(host, "host")
242*e0c4386eSCy Schubert         && TEST_str_eq(path, exp_path_qu);
243*e0c4386eSCy Schubert     OPENSSL_free(host);
244*e0c4386eSCy Schubert     OPENSSL_free(path);
245*e0c4386eSCy Schubert     return res;
246*e0c4386eSCy Schubert }
247*e0c4386eSCy Schubert 
test_http_url_dns(void)248*e0c4386eSCy Schubert static int test_http_url_dns(void)
249*e0c4386eSCy Schubert {
250*e0c4386eSCy Schubert     return test_http_url_ok("host:65535/path", 0, "host", "65535", "/path");
251*e0c4386eSCy Schubert }
252*e0c4386eSCy Schubert 
test_http_url_path_query(void)253*e0c4386eSCy Schubert static int test_http_url_path_query(void)
254*e0c4386eSCy Schubert {
255*e0c4386eSCy Schubert     return test_http_url_path_query_ok("http://usr@host:1/p?q=x#frag", "/p?q=x")
256*e0c4386eSCy Schubert         && test_http_url_path_query_ok("http://host?query#frag", "/?query")
257*e0c4386eSCy Schubert         && test_http_url_path_query_ok("http://host:9999#frag", "/");
258*e0c4386eSCy Schubert }
259*e0c4386eSCy Schubert 
test_http_url_userinfo_query_fragment(void)260*e0c4386eSCy Schubert static int test_http_url_userinfo_query_fragment(void)
261*e0c4386eSCy Schubert {
262*e0c4386eSCy Schubert     return test_http_url_ok("user:pass@host/p?q#fr", 0, "host", "80", "/p");
263*e0c4386eSCy Schubert }
264*e0c4386eSCy Schubert 
test_http_url_ipv4(void)265*e0c4386eSCy Schubert static int test_http_url_ipv4(void)
266*e0c4386eSCy Schubert {
267*e0c4386eSCy Schubert     return test_http_url_ok("https://1.2.3.4/p/q", 1, "1.2.3.4", "443", "/p/q");
268*e0c4386eSCy Schubert }
269*e0c4386eSCy Schubert 
test_http_url_ipv6(void)270*e0c4386eSCy Schubert static int test_http_url_ipv6(void)
271*e0c4386eSCy Schubert {
272*e0c4386eSCy Schubert     return test_http_url_ok("http://[FF01::101]:6", 0, "[FF01::101]", "6", "/");
273*e0c4386eSCy Schubert }
274*e0c4386eSCy Schubert 
test_http_url_invalid(const char * url)275*e0c4386eSCy Schubert static int test_http_url_invalid(const char *url)
276*e0c4386eSCy Schubert {
277*e0c4386eSCy Schubert     char *host = "1", *port = "1", *path = "1";
278*e0c4386eSCy Schubert     int num = 1, ssl = 1;
279*e0c4386eSCy Schubert     int res;
280*e0c4386eSCy Schubert 
281*e0c4386eSCy Schubert     res = TEST_false(OSSL_HTTP_parse_url(url, &ssl, NULL, &host, &port, &num,
282*e0c4386eSCy Schubert                                          &path, NULL, NULL))
283*e0c4386eSCy Schubert         && TEST_ptr_null(host)
284*e0c4386eSCy Schubert         && TEST_ptr_null(port)
285*e0c4386eSCy Schubert         && TEST_ptr_null(path);
286*e0c4386eSCy Schubert     if (!res) {
287*e0c4386eSCy Schubert         OPENSSL_free(host);
288*e0c4386eSCy Schubert         OPENSSL_free(port);
289*e0c4386eSCy Schubert         OPENSSL_free(path);
290*e0c4386eSCy Schubert     }
291*e0c4386eSCy Schubert     return res;
292*e0c4386eSCy Schubert }
293*e0c4386eSCy Schubert 
test_http_url_invalid_prefix(void)294*e0c4386eSCy Schubert static int test_http_url_invalid_prefix(void)
295*e0c4386eSCy Schubert {
296*e0c4386eSCy Schubert     return test_http_url_invalid("htttps://1.2.3.4:65535/pkix");
297*e0c4386eSCy Schubert }
298*e0c4386eSCy Schubert 
test_http_url_invalid_port(void)299*e0c4386eSCy Schubert static int test_http_url_invalid_port(void)
300*e0c4386eSCy Schubert {
301*e0c4386eSCy Schubert     return test_http_url_invalid("https://1.2.3.4:65536/pkix")
302*e0c4386eSCy Schubert            && test_http_url_invalid("https://1.2.3.4:");
303*e0c4386eSCy Schubert }
304*e0c4386eSCy Schubert 
test_http_url_invalid_path(void)305*e0c4386eSCy Schubert static int test_http_url_invalid_path(void)
306*e0c4386eSCy Schubert {
307*e0c4386eSCy Schubert     return test_http_url_invalid("https://[FF01::101]pkix");
308*e0c4386eSCy Schubert }
309*e0c4386eSCy Schubert 
test_http_get_x509(void)310*e0c4386eSCy Schubert static int test_http_get_x509(void)
311*e0c4386eSCy Schubert {
312*e0c4386eSCy Schubert     return test_http_x509(1);
313*e0c4386eSCy Schubert }
314*e0c4386eSCy Schubert 
test_http_post_x509(void)315*e0c4386eSCy Schubert static int test_http_post_x509(void)
316*e0c4386eSCy Schubert {
317*e0c4386eSCy Schubert     return test_http_x509(0);
318*e0c4386eSCy Schubert }
319*e0c4386eSCy Schubert 
test_http_keep_alive_0_no_no(void)320*e0c4386eSCy Schubert static int test_http_keep_alive_0_no_no(void)
321*e0c4386eSCy Schubert {
322*e0c4386eSCy Schubert     return test_http_keep_alive('0', 0, 0);
323*e0c4386eSCy Schubert }
324*e0c4386eSCy Schubert 
test_http_keep_alive_1_no_no(void)325*e0c4386eSCy Schubert static int test_http_keep_alive_1_no_no(void)
326*e0c4386eSCy Schubert {
327*e0c4386eSCy Schubert     return test_http_keep_alive('1', 0, 0);
328*e0c4386eSCy Schubert }
329*e0c4386eSCy Schubert 
test_http_keep_alive_0_prefer_yes(void)330*e0c4386eSCy Schubert static int test_http_keep_alive_0_prefer_yes(void)
331*e0c4386eSCy Schubert {
332*e0c4386eSCy Schubert     return test_http_keep_alive('0', 1, 1);
333*e0c4386eSCy Schubert }
334*e0c4386eSCy Schubert 
test_http_keep_alive_1_prefer_yes(void)335*e0c4386eSCy Schubert static int test_http_keep_alive_1_prefer_yes(void)
336*e0c4386eSCy Schubert {
337*e0c4386eSCy Schubert     return test_http_keep_alive('1', 1, 1);
338*e0c4386eSCy Schubert }
339*e0c4386eSCy Schubert 
test_http_keep_alive_0_require_yes(void)340*e0c4386eSCy Schubert static int test_http_keep_alive_0_require_yes(void)
341*e0c4386eSCy Schubert {
342*e0c4386eSCy Schubert     return test_http_keep_alive('0', 2, 1);
343*e0c4386eSCy Schubert }
344*e0c4386eSCy Schubert 
test_http_keep_alive_1_require_yes(void)345*e0c4386eSCy Schubert static int test_http_keep_alive_1_require_yes(void)
346*e0c4386eSCy Schubert {
347*e0c4386eSCy Schubert     return test_http_keep_alive('1', 2, 1);
348*e0c4386eSCy Schubert }
349*e0c4386eSCy Schubert 
test_http_keep_alive_0_require_no(void)350*e0c4386eSCy Schubert static int test_http_keep_alive_0_require_no(void)
351*e0c4386eSCy Schubert {
352*e0c4386eSCy Schubert     return test_http_keep_alive('0', 2, 0);
353*e0c4386eSCy Schubert }
354*e0c4386eSCy Schubert 
test_http_keep_alive_1_require_no(void)355*e0c4386eSCy Schubert static int test_http_keep_alive_1_require_no(void)
356*e0c4386eSCy Schubert {
357*e0c4386eSCy Schubert     return test_http_keep_alive('1', 2, 0);
358*e0c4386eSCy Schubert }
359*e0c4386eSCy Schubert 
cleanup_tests(void)360*e0c4386eSCy Schubert void cleanup_tests(void)
361*e0c4386eSCy Schubert {
362*e0c4386eSCy Schubert     X509_free(x509);
363*e0c4386eSCy Schubert }
364*e0c4386eSCy Schubert 
365*e0c4386eSCy Schubert OPT_TEST_DECLARE_USAGE("cert.pem\n")
366*e0c4386eSCy Schubert 
setup_tests(void)367*e0c4386eSCy Schubert int setup_tests(void)
368*e0c4386eSCy Schubert {
369*e0c4386eSCy Schubert     if (!test_skip_common_options())
370*e0c4386eSCy Schubert         return 0;
371*e0c4386eSCy Schubert 
372*e0c4386eSCy Schubert     x509_it = ASN1_ITEM_rptr(X509);
373*e0c4386eSCy Schubert     if (!TEST_ptr((x509 = load_cert_pem(test_get_argument(0), NULL))))
374*e0c4386eSCy Schubert         return 0;
375*e0c4386eSCy Schubert 
376*e0c4386eSCy Schubert     ADD_TEST(test_http_url_dns);
377*e0c4386eSCy Schubert     ADD_TEST(test_http_url_path_query);
378*e0c4386eSCy Schubert     ADD_TEST(test_http_url_userinfo_query_fragment);
379*e0c4386eSCy Schubert     ADD_TEST(test_http_url_ipv4);
380*e0c4386eSCy Schubert     ADD_TEST(test_http_url_ipv6);
381*e0c4386eSCy Schubert     ADD_TEST(test_http_url_invalid_prefix);
382*e0c4386eSCy Schubert     ADD_TEST(test_http_url_invalid_port);
383*e0c4386eSCy Schubert     ADD_TEST(test_http_url_invalid_path);
384*e0c4386eSCy Schubert     ADD_TEST(test_http_get_x509);
385*e0c4386eSCy Schubert     ADD_TEST(test_http_post_x509);
386*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_0_no_no);
387*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_1_no_no);
388*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_0_prefer_yes);
389*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_1_prefer_yes);
390*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_0_require_yes);
391*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_1_require_yes);
392*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_0_require_no);
393*e0c4386eSCy Schubert     ADD_TEST(test_http_keep_alive_1_require_no);
394*e0c4386eSCy Schubert     return 1;
395*e0c4386eSCy Schubert }
396