aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_http_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_http_common.c')
-rw-r--r--src/transport/test_http_common.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c
index d7a203336..c97ae1745 100644
--- a/src/transport/test_http_common.c
+++ b/src/transport/test_http_common.c
@@ -112,7 +112,7 @@ check (struct SplittedHTTPAddress *addr,
112 return GNUNET_OK; 112 return GNUNET_OK;
113} 113}
114 114
115void 115int
116check_pass (char *src, 116check_pass (char *src,
117 char * protocol, 117 char * protocol,
118 char * host, 118 char * host,
@@ -124,33 +124,55 @@ check_pass (char *src,
124 if (NULL == spa) 124 if (NULL == spa)
125 { 125 {
126 GNUNET_break (0); 126 GNUNET_break (0);
127 return GNUNET_SYSERR;
127 } 128 }
128 else 129 else
129 { 130 {
130 if (GNUNET_OK != check(spa, protocol, host, port, path)) 131 if (GNUNET_OK != check(spa, protocol, host, port, path))
131 { 132 {
133 clean (spa);
132 GNUNET_break (0); 134 GNUNET_break (0);
135 return GNUNET_SYSERR;
133 } 136 }
134 clean (spa); 137 clean (spa);
135 } 138 }
139 return GNUNET_OK;
140}
141
142int
143check_fail (char *src)
144{
145 struct SplittedHTTPAddress * spa;
146 spa = http_split_address (src);
147 if (NULL != spa)
148 {
149 GNUNET_break (0);
150 clean (spa);
151 return GNUNET_SYSERR;
152 }
153 return GNUNET_OK;
136} 154}
137 155
156
138void 157void
139test_hostname () 158test_pass_hostname ()
140{ 159{
141 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); 160 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
142 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); 161 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/");
143 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path"); 162 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path");
144 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/"); 163 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/");
164 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more");
145 check_pass("http://test.local:81", "http", "test.local", 81, ""); 165 check_pass("http://test.local:81", "http", "test.local", 81, "");
146 check_pass("http://test.local:81/", "http", "test.local", 81, "/"); 166 check_pass("http://test.local:81/", "http", "test.local", 81, "/");
147 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); 167 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
148 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); 168 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
169 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
149 170
150} 171}
151 172
173
152void 174void
153test_ipv4 () 175test_pass_ipv4 ()
154{ 176{
155 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); 177 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
156 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); 178 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
@@ -160,10 +182,11 @@ test_ipv4 ()
160 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); 182 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
161 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); 183 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
162 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); 184 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
185 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
163} 186}
164 187
165void 188void
166test_ipv6 () 189test_fail_ipv6 ()
167{ 190{
168 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); 191 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
169 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); 192 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
@@ -173,9 +196,34 @@ test_ipv6 ()
173 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/"); 196 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/");
174 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path"); 197 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path");
175 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); 198 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
199 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
176} 200}
177 201
178 202
203void
204test_fail ()
205{
206 if (GNUNET_SYSERR == check_fail (""))
207 GNUNET_break (0);
208 if (GNUNET_SYSERR == check_fail ("http"))
209 GNUNET_break (0);
210 if (GNUNET_SYSERR == check_fail ("://"))
211 GNUNET_break (0);
212 if (GNUNET_SYSERR == check_fail ("http://"))
213 GNUNET_break (0);
214 if (GNUNET_SYSERR == check_fail ("//localhost"))
215 GNUNET_break (0);
216 if (GNUNET_SYSERR == check_fail ("//:80"))
217 GNUNET_break (0);
218 if (GNUNET_SYSERR == check_fail ("//:80/"))
219 GNUNET_break (0);
220 if (GNUNET_SYSERR == check_fail ("//:80:"))
221 GNUNET_break (0);
222 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
223 GNUNET_break (0);
224 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
225 GNUNET_break (0);
226}
179 227
180int 228int
181main (int argc, char *argv[]) 229main (int argc, char *argv[])
@@ -205,9 +253,10 @@ main (int argc, char *argv[])
205 GNUNET_break (0); 253 GNUNET_break (0);
206 } 254 }
207 255
208 test_hostname (); 256 test_pass_hostname ();
209 test_ipv4 (); 257 test_pass_ipv4 ();
210 test_ipv6 (); 258 test_fail_ipv6 ();
259 test_fail ();
211 260
212 return ret; 261 return ret;
213} 262}