1 /*
2  * Copyright (c) 2013-2014 Tim Ruehsen
3  * Copyright (c) 2015-2021 Free Software Foundation, Inc.
4  *
5  * This file is part of libwget.
6  *
7  * Libwget is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Libwget is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with libwget.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  *
21  * Test suite function library header
22  *
23  * Changelog
24  * 10.03.2013  Tim Ruehsen  created
25  *
26  * Test suite function library
27  *
28  * To create the X.509 stuff, I followed the instructions at
29  *   gnutls.org/manual/html_node/gnutls_002dserv-Invocation.html
30  *
31  */
32 
33 #ifndef TESTS_LIBTEST_H
34 #define TESTS_LIBTEST_H
35 
36 #include <wget.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define WGET_TEST_EXIT_SKIP 77
43 
44 // defines for wget_test_start_http_server()
45 #define WGET_TEST_RESPONSE_URLS 1002
46 #define WGET_TEST_HTTP_ONLY 1003
47 #define WGET_TEST_HTTPS_ONLY 1004
48 #define WGET_TEST_HTTP_REJECT_CONNECTIONS 1005
49 #define WGET_TEST_HTTPS_REJECT_CONNECTIONS 1006
50 #define WGET_TEST_H2_ONLY 1007
51 #define WGET_TEST_SKIP_H2 1008
52 #define WGET_TEST_FEATURE_MHD 1101
53 #define WGET_TEST_FEATURE_TLS 1102
54 #define WGET_TEST_FEATURE_IDN 1103
55 #define WGET_TEST_FEATURE_PLUGIN 1104
56 #define WGET_TEST_FEATURE_OCSP 1105
57 #define WGET_TEST_FEATURE_OCSP_STAPLING 1106
58 
59 // defines for wget_test()
60 #define WGET_TEST_REQUEST_URL 2001
61 #define WGET_TEST_OPTIONS 2002
62 #define WGET_TEST_EXPECTED_ERROR_CODE 2003
63 #define WGET_TEST_EXPECTED_FILES 2004
64 #define WGET_TEST_EXISTING_FILES 2005
65 #define WGET_TEST_KEEP_TMPFILES 2006
66 #define WGET_TEST_REQUEST_URLS 2007
67 #define WGET_TEST_EXECUTABLE 2008
68 #define WGET_TEST_SERVER_SEND_CONTENT_LENGTH 2009
69 #define WGET_TEST_EXPECTED_ERROR_CODE2 2010
70 #define WGET_TEST_CLEAN_DIRECTORY 2011
71 
72 // defines for wget_test_check_file_system()
73 #define WGET_TEST_FS_CASEMATTERS 3001 // file system is case-sensitive
74 
75 // for post-handshake authentication
76 #define WGET_TEST_POST_HANDSHAKE_AUTH 3002
77 
78 // for OCSP testing
79 #define WGET_TEST_OCSP_RESP_FILE 3003
80 
81 typedef enum {
82 	INTERRUPT_RESPONSE_DISABLED = 0,
83 	INTERRUPT_RESPONSE_DURING_BODY
84 } interrupt_response_mode_t;
85 
86 #define countof(a) (sizeof(a)/sizeof(*(a)))
87 
88 #define TEST_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
89 
90 WGET_GCC_UNUSED static const char *WGET_TEST_SOME_HTML_BODY = "\
91 <html>\n\
92 <head>\n\
93   <title>The Title</title>\n\
94 </head>\n\
95 <body>\n\
96   <p>\n\
97     Some text\n\
98   </p>\n\
99 </body>\n\
100 </html>\n";
101 
102 typedef struct {
103 	const char *
104 		name;
105 	const char *
106 		content;
107 	time_t
108 		timestamp;
109 	char
110 		restricted_mode;
111 	size_t
112 		content_length;
113 	const char *
114 		hardlink;
115 } wget_test_file_t;
116 
117 typedef struct {
118 	const char *
119 		name;
120 	const char *
121 		code;
122 	const char *
123 		body;
124 	const char *
125 		body_original;
126 	const char *
127 		headers[10];
128 	const char *
129 		headers_original[10];
130 	const char *
131 		request_headers[10];
132 	const char *
133 		expected_req_headers[10];
134 	const char *
135 		unexpected_req_headers[10];
136 	const char *
137 		expected_method;
138 	int64_t
139 		modified;
140 
141 	// auth fields
142 	const char *
143 		auth_method;
144 	const char *
145 		auth_username;
146 	const char *
147 		auth_password;
148 	size_t
149 		body_len; // The length of the body in bytes. 0 means use strlen(body)
150 
151 	interrupt_response_mode_t
152 		interrupt_response_mode;
153 	size_t
154 		interrupt_response_after_nbytes;
155 
156 	bool
157 		https_only : 1,
158 		http_only : 1;
159 } wget_test_url_t;
160 
161 WGETAPI void wget_test_stop_server(void);
162 WGETAPI void wget_test_start_server(int first_key, ...);
163 WGETAPI void wget_test(int first_key, ...);
164 WGETAPI int wget_test_check_file_system(void);
165 WGETAPI void wget_test_set_executable(const char *);
166 WGETAPI int wget_test_get_http_server_port(void) WGET_GCC_PURE;
167 WGETAPI int wget_test_get_https_server_port(void) WGET_GCC_PURE;
168 WGETAPI int wget_test_get_ocsp_server_port(void) WGET_GCC_PURE;
169 WGETAPI int wget_test_get_h2_server_port(void) WGET_GCC_PURE;
170 
171 #if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
172 #	pragma GCC diagnostic ignored "-Wmissing-field-initializers"
173 #endif
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif	/* _LIBWGET_LIBTEST_H */
180