1 /*
2 * Copyright (c) 2018-2021 Free Software Foundation, Inc.
3 *
4 * This file is part of Wget
5 *
6 * Wget is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Wget is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Wget If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <config.h>
21
22 #include <stdlib.h> // exit()
23 #include "libtest.h"
24
main(void)25 int main(void)
26 {
27 wget_test_url_t urls[]={
28 { .name = "/index.html",
29 .code = "200 Dontcare",
30 .body = "from HTTPS",
31 .headers = {
32 "Content-Type: text/plain",
33 },
34 .https_only = 1 // only exists for the HTTPS server
35 },
36 { .name = "/index.html",
37 .code = "200 Dontcare",
38 .body = "from HTTP",
39 .headers = {
40 "Content-Type: text/plain",
41 },
42 .http_only = 1 // only exists for the HTTP server
43 },
44 };
45
46 // functions won't come back if an error occurs
47 wget_test_start_server(
48 WGET_TEST_RESPONSE_URLS, &urls, countof(urls),
49 WGET_TEST_HTTPS_REJECT_CONNECTIONS,
50 WGET_TEST_FEATURE_MHD,
51 WGET_TEST_FEATURE_TLS,
52 0);
53
54 // wget2 tries HTTPS, then falls back to HTTP
55 wget_test(
56 // WGET_TEST_KEEP_TMPFILES, 1,
57 WGET_TEST_OPTIONS,
58 "--ca-certificate=" SRCDIR "/certs/x509-ca-cert.pem --no-ocsp"
59 " --https-enforce=soft --default-https-port={{sslport}} --default-http-port={{port}}",
60 WGET_TEST_REQUEST_URL, "http://localhost/index.html",
61 WGET_TEST_EXPECTED_ERROR_CODE, 0,
62 WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
63 { urls[1].name + 1, urls[1].body },
64 { NULL } },
65 0);
66
67 exit(EXIT_SUCCESS);
68 }
69