diff options
Diffstat (limited to 'src/transport/test_http_common.c')
-rw-r--r-- | src/transport/test_http_common.c | 227 |
1 files changed, 113 insertions, 114 deletions
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c index 70ad04719..251b1543a 100644 --- a/src/transport/test_http_common.c +++ b/src/transport/test_http_common.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_http_common.c | 21 | * @file transport/test_http_common.c |
22 | * @brief base test case for common http functionality | 22 | * @brief base test case for common http functionality |
@@ -28,124 +28,124 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | static void | 30 | static void |
31 | clean (struct SplittedHTTPAddress *addr) | 31 | clean(struct SplittedHTTPAddress *addr) |
32 | { | 32 | { |
33 | if (NULL == addr) | 33 | if (NULL == addr) |
34 | return; | 34 | return; |
35 | GNUNET_free_non_null (addr->host); | 35 | GNUNET_free_non_null(addr->host); |
36 | GNUNET_free_non_null (addr->path); | 36 | GNUNET_free_non_null(addr->path); |
37 | GNUNET_free_non_null (addr->protocol); | 37 | GNUNET_free_non_null(addr->protocol); |
38 | GNUNET_free (addr); | 38 | GNUNET_free(addr); |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static int |
43 | check (struct SplittedHTTPAddress *addr, | 43 | check(struct SplittedHTTPAddress *addr, |
44 | const char *protocol, | 44 | const char *protocol, |
45 | const char *host, | 45 | const char *host, |
46 | int port, | 46 | int port, |
47 | const char *path) | 47 | const char *path) |
48 | { | 48 | { |
49 | if (NULL == addr) | 49 | if (NULL == addr) |
50 | return GNUNET_NO; | 50 | return GNUNET_NO; |
51 | if (((NULL == addr->protocol) && (NULL != protocol)) || | 51 | if (((NULL == addr->protocol) && (NULL != protocol)) || |
52 | ((NULL != addr->protocol) && (NULL == protocol))) | 52 | ((NULL != addr->protocol) && (NULL == protocol))) |
53 | { | ||
54 | GNUNET_break (0); | ||
55 | return GNUNET_NO; | ||
56 | } | ||
57 | else if ((NULL != addr->protocol) && (NULL != protocol)) | ||
58 | { | ||
59 | if (0 != strcmp(addr->protocol, protocol)) | ||
60 | { | 53 | { |
61 | GNUNET_break (0); | 54 | GNUNET_break(0); |
62 | return GNUNET_NO; | 55 | return GNUNET_NO; |
63 | } | 56 | } |
64 | } | 57 | else if ((NULL != addr->protocol) && (NULL != protocol)) |
58 | { | ||
59 | if (0 != strcmp(addr->protocol, protocol)) | ||
60 | { | ||
61 | GNUNET_break(0); | ||
62 | return GNUNET_NO; | ||
63 | } | ||
64 | } | ||
65 | 65 | ||
66 | if (((NULL == addr->host) && (NULL != host)) || | 66 | if (((NULL == addr->host) && (NULL != host)) || |
67 | ((NULL != addr->host) && (NULL == host))) | 67 | ((NULL != addr->host) && (NULL == host))) |
68 | { | ||
69 | GNUNET_break (0); | ||
70 | return GNUNET_NO; | ||
71 | } | ||
72 | else if ((NULL != addr->host) && (NULL != host)) | ||
73 | { | ||
74 | if (0 != strcmp(addr->host, host)) | ||
75 | { | 68 | { |
76 | GNUNET_break (0); | 69 | GNUNET_break(0); |
77 | return GNUNET_NO; | 70 | return GNUNET_NO; |
78 | } | 71 | } |
79 | } | 72 | else if ((NULL != addr->host) && (NULL != host)) |
73 | { | ||
74 | if (0 != strcmp(addr->host, host)) | ||
75 | { | ||
76 | GNUNET_break(0); | ||
77 | return GNUNET_NO; | ||
78 | } | ||
79 | } | ||
80 | 80 | ||
81 | if (((NULL == addr->path) && (NULL != path)) || | 81 | if (((NULL == addr->path) && (NULL != path)) || |
82 | ((NULL != addr->path) && (NULL == path))) | 82 | ((NULL != addr->path) && (NULL == path))) |
83 | { | ||
84 | GNUNET_break (0); | ||
85 | return GNUNET_NO; | ||
86 | } | ||
87 | else if ((NULL != addr->path) && (NULL != path)) | ||
88 | { | ||
89 | if (0 != strcmp(addr->path, path)) | ||
90 | { | 83 | { |
91 | GNUNET_break (0); | 84 | GNUNET_break(0); |
92 | return GNUNET_NO; | 85 | return GNUNET_NO; |
93 | } | 86 | } |
94 | } | 87 | else if ((NULL != addr->path) && (NULL != path)) |
88 | { | ||
89 | if (0 != strcmp(addr->path, path)) | ||
90 | { | ||
91 | GNUNET_break(0); | ||
92 | return GNUNET_NO; | ||
93 | } | ||
94 | } | ||
95 | 95 | ||
96 | if ((addr->port != port)) | 96 | if ((addr->port != port)) |
97 | { | 97 | { |
98 | GNUNET_break (0); | 98 | GNUNET_break(0); |
99 | return GNUNET_NO; | 99 | return GNUNET_NO; |
100 | } | 100 | } |
101 | return GNUNET_OK; | 101 | return GNUNET_OK; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | static int | 105 | static int |
106 | check_pass (const char *src, | 106 | check_pass(const char *src, |
107 | const char *protocol, | 107 | const char *protocol, |
108 | const char *host, | 108 | const char *host, |
109 | int port, | 109 | int port, |
110 | const char *path) | 110 | const char *path) |
111 | { | 111 | { |
112 | struct SplittedHTTPAddress *spa; | 112 | struct SplittedHTTPAddress *spa; |
113 | 113 | ||
114 | spa = http_split_address (src); | 114 | spa = http_split_address(src); |
115 | if (NULL == spa) | 115 | if (NULL == spa) |
116 | { | 116 | { |
117 | GNUNET_break (0); | 117 | GNUNET_break(0); |
118 | return GNUNET_SYSERR; | 118 | return GNUNET_SYSERR; |
119 | } | 119 | } |
120 | if (GNUNET_OK != check(spa, protocol, host, port, path)) | 120 | if (GNUNET_OK != check(spa, protocol, host, port, path)) |
121 | { | 121 | { |
122 | clean (spa); | 122 | clean(spa); |
123 | GNUNET_break (0); | 123 | GNUNET_break(0); |
124 | return GNUNET_SYSERR; | 124 | return GNUNET_SYSERR; |
125 | } | 125 | } |
126 | clean (spa); | 126 | clean(spa); |
127 | return GNUNET_OK; | 127 | return GNUNET_OK; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | static int | 131 | static int |
132 | check_fail (const char *src) | 132 | check_fail(const char *src) |
133 | { | 133 | { |
134 | struct SplittedHTTPAddress * spa; | 134 | struct SplittedHTTPAddress * spa; |
135 | 135 | ||
136 | spa = http_split_address (src); | 136 | spa = http_split_address(src); |
137 | if (NULL != spa) | 137 | if (NULL != spa) |
138 | { | 138 | { |
139 | GNUNET_break (0); | 139 | GNUNET_break(0); |
140 | clean (spa); | 140 | clean(spa); |
141 | return GNUNET_SYSERR; | 141 | return GNUNET_SYSERR; |
142 | } | 142 | } |
143 | return GNUNET_OK; | 143 | return GNUNET_OK; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | static void | 147 | static void |
148 | test_pass_hostname () | 148 | test_pass_hostname() |
149 | { | 149 | { |
150 | check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); | 150 | check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); |
151 | check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); | 151 | check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); |
@@ -157,12 +157,11 @@ test_pass_hostname () | |||
157 | check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); | 157 | check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); |
158 | check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); | 158 | check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); |
159 | check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); | 159 | check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); |
160 | |||
161 | } | 160 | } |
162 | 161 | ||
163 | 162 | ||
164 | static void | 163 | static void |
165 | test_pass_ipv4 () | 164 | test_pass_ipv4() |
166 | { | 165 | { |
167 | check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); | 166 | check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); |
168 | check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); | 167 | check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); |
@@ -177,7 +176,7 @@ test_pass_ipv4 () | |||
177 | 176 | ||
178 | 177 | ||
179 | static void | 178 | static void |
180 | test_fail_ipv6 () | 179 | test_fail_ipv6() |
181 | { | 180 | { |
182 | check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); | 181 | check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); |
183 | check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); | 182 | check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); |
@@ -192,64 +191,64 @@ test_fail_ipv6 () | |||
192 | 191 | ||
193 | 192 | ||
194 | static void | 193 | static void |
195 | test_fail () | 194 | test_fail() |
196 | { | 195 | { |
197 | if (GNUNET_SYSERR == check_fail ("")) | 196 | if (GNUNET_SYSERR == check_fail("")) |
198 | GNUNET_break (0); | 197 | GNUNET_break(0); |
199 | if (GNUNET_SYSERR == check_fail ("http")) | 198 | if (GNUNET_SYSERR == check_fail("http")) |
200 | GNUNET_break (0); | 199 | GNUNET_break(0); |
201 | if (GNUNET_SYSERR == check_fail ("://")) | 200 | if (GNUNET_SYSERR == check_fail("://")) |
202 | GNUNET_break (0); | 201 | GNUNET_break(0); |
203 | if (GNUNET_SYSERR == check_fail ("http://")) | 202 | if (GNUNET_SYSERR == check_fail("http://")) |
204 | GNUNET_break (0); | 203 | GNUNET_break(0); |
205 | if (GNUNET_SYSERR == check_fail ("//localhost")) | 204 | if (GNUNET_SYSERR == check_fail("//localhost")) |
206 | GNUNET_break (0); | 205 | GNUNET_break(0); |
207 | if (GNUNET_SYSERR == check_fail ("//:80")) | 206 | if (GNUNET_SYSERR == check_fail("//:80")) |
208 | GNUNET_break (0); | 207 | GNUNET_break(0); |
209 | if (GNUNET_SYSERR == check_fail ("//:80/")) | 208 | if (GNUNET_SYSERR == check_fail("//:80/")) |
210 | GNUNET_break (0); | 209 | GNUNET_break(0); |
211 | if (GNUNET_SYSERR == check_fail ("//:80:")) | 210 | if (GNUNET_SYSERR == check_fail("//:80:")) |
212 | GNUNET_break (0); | 211 | GNUNET_break(0); |
213 | if (GNUNET_SYSERR == check_fail ("http://localhost:a/")) | 212 | if (GNUNET_SYSERR == check_fail("http://localhost:a/")) |
214 | GNUNET_break (0); | 213 | GNUNET_break(0); |
215 | if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/")) | 214 | if (GNUNET_SYSERR == check_fail("http://127.0.0.1:a/")) |
216 | GNUNET_break (0); | 215 | GNUNET_break(0); |
217 | } | 216 | } |
218 | 217 | ||
219 | 218 | ||
220 | int | 219 | int |
221 | main (int argc, char *argv[]) | 220 | main(int argc, char *argv[]) |
222 | { | 221 | { |
223 | int ret = 0; | 222 | int ret = 0; |
224 | struct SplittedHTTPAddress * spa; | 223 | struct SplittedHTTPAddress * spa; |
225 | 224 | ||
226 | GNUNET_log_setup ("test", "DEBUG", NULL); | 225 | GNUNET_log_setup("test", "DEBUG", NULL); |
227 | spa = http_split_address (""); | 226 | spa = http_split_address(""); |
228 | if (NULL != spa) | 227 | if (NULL != spa) |
229 | { | 228 | { |
230 | clean (spa); | 229 | clean(spa); |
231 | spa = NULL; | 230 | spa = NULL; |
232 | GNUNET_break (0); | 231 | GNUNET_break(0); |
233 | } | 232 | } |
234 | 233 | ||
235 | spa = http_split_address ("http://"); | 234 | spa = http_split_address("http://"); |
236 | if (NULL != spa) | 235 | if (NULL != spa) |
237 | { | 236 | { |
238 | clean (spa); | 237 | clean(spa); |
239 | GNUNET_break (0); | 238 | GNUNET_break(0); |
240 | } | 239 | } |
241 | 240 | ||
242 | spa = http_split_address ("://"); | 241 | spa = http_split_address("://"); |
243 | if (NULL != spa) | 242 | if (NULL != spa) |
244 | { | 243 | { |
245 | clean (spa); | 244 | clean(spa); |
246 | GNUNET_break (0); | 245 | GNUNET_break(0); |
247 | } | 246 | } |
248 | 247 | ||
249 | test_pass_hostname (); | 248 | test_pass_hostname(); |
250 | test_pass_ipv4 (); | 249 | test_pass_ipv4(); |
251 | test_fail_ipv6 (); | 250 | test_fail_ipv6(); |
252 | test_fail (); | 251 | test_fail(); |
253 | 252 | ||
254 | return ret; | 253 | return ret; |
255 | } | 254 | } |