@@ -186,6 +186,10 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str_invalid)
186186 LT_CHECK_THROW(http::ip_representation(" 192.168.5.5.5" ));
187187LT_END_AUTO_TEST (ip_representation4_str_invalid)
188188
189+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str_beyond255)
190+ LT_CHECK_THROW(http::ip_representation(" 192.168.256.5" ));
191+ LT_END_AUTO_TEST (ip_representation4_str_beyond255)
192+
189193LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str)
190194 http::ip_representation test_ip(" 2001:db8:8714:3a90::12" );
191195
@@ -203,12 +207,198 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str)
203207 LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
204208 LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
205209 LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
206- LT_CHECK_EQ (test_ip.pieces[12 ], 18 );
210+ LT_CHECK_EQ (test_ip.pieces[12 ], 0 );
207211 LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
208212 LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
209- LT_CHECK_EQ (test_ip.pieces[15 ], 0 );
213+ LT_CHECK_EQ (test_ip.pieces[15 ], 18 );
214+
215+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
210216LT_END_AUTO_TEST (ip_representation6_str)
211217
218+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_mask)
219+ http::ip_representation test_ip(" 2001:db8:8714:3a90:*:*" );
220+
221+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
222+
223+ LT_CHECK_EQ (test_ip.pieces[0 ], 32 );
224+ LT_CHECK_EQ (test_ip.pieces[1 ], 1 );
225+ LT_CHECK_EQ (test_ip.pieces[2 ], 13 );
226+ LT_CHECK_EQ (test_ip.pieces[3 ], 184 );
227+ LT_CHECK_EQ (test_ip.pieces[4 ], 135 );
228+ LT_CHECK_EQ (test_ip.pieces[5 ], 20 );
229+ LT_CHECK_EQ (test_ip.pieces[6 ], 58 );
230+ LT_CHECK_EQ (test_ip.pieces[7 ], 144 );
231+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
232+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
233+ LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
234+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
235+ LT_CHECK_EQ (test_ip.pieces[12 ], 0 );
236+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
237+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
238+ LT_CHECK_EQ (test_ip.pieces[15 ], 0 );
239+
240+ LT_CHECK_EQ (test_ip.mask, 0xFCFF );
241+ LT_END_AUTO_TEST (ip_representation6_str_mask)
242+
243+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_nested)
244+ http::ip_representation test_ip(" ::ffff:192.0.2.128" );
245+
246+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
247+
248+ LT_CHECK_EQ (test_ip.pieces[0 ], 0 );
249+ LT_CHECK_EQ (test_ip.pieces[1 ], 0 );
250+ LT_CHECK_EQ (test_ip.pieces[2 ], 0 );
251+ LT_CHECK_EQ (test_ip.pieces[3 ], 0 );
252+ LT_CHECK_EQ (test_ip.pieces[4 ], 0 );
253+ LT_CHECK_EQ (test_ip.pieces[5 ], 0 );
254+ LT_CHECK_EQ (test_ip.pieces[6 ], 0 );
255+ LT_CHECK_EQ (test_ip.pieces[7 ], 0 );
256+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
257+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
258+ LT_CHECK_EQ (test_ip.pieces[10 ], 255 );
259+ LT_CHECK_EQ (test_ip.pieces[11 ], 255 );
260+ LT_CHECK_EQ (test_ip.pieces[12 ], 192 );
261+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
262+ LT_CHECK_EQ (test_ip.pieces[14 ], 2 );
263+ LT_CHECK_EQ (test_ip.pieces[15 ], 128 );
264+
265+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
266+ LT_END_AUTO_TEST (ip_representation6_str_nested)
267+
268+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_nested_deprecated)
269+ LT_CHECK_NOTHROW(http::ip_representation(" ::192.0.2.128" ));
270+ http::ip_representation test_ip (" ::192.0.2.128" );
271+
272+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
273+
274+ LT_CHECK_EQ (test_ip.pieces[0 ], 0 );
275+ LT_CHECK_EQ (test_ip.pieces[1 ], 0 );
276+ LT_CHECK_EQ (test_ip.pieces[2 ], 0 );
277+ LT_CHECK_EQ (test_ip.pieces[3 ], 0 );
278+ LT_CHECK_EQ (test_ip.pieces[4 ], 0 );
279+ LT_CHECK_EQ (test_ip.pieces[5 ], 0 );
280+ LT_CHECK_EQ (test_ip.pieces[6 ], 0 );
281+ LT_CHECK_EQ (test_ip.pieces[7 ], 0 );
282+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
283+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
284+ LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
285+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
286+ LT_CHECK_EQ (test_ip.pieces[12 ], 192 );
287+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
288+ LT_CHECK_EQ (test_ip.pieces[14 ], 2 );
289+ LT_CHECK_EQ (test_ip.pieces[15 ], 128 );
290+
291+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
292+ LT_END_AUTO_TEST (ip_representation6_str_nested_deprecated)
293+
294+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_ipv4_mask)
295+ http::ip_representation test_ip(" ::ffff:192.0.*.*" );
296+
297+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
298+
299+ LT_CHECK_EQ (test_ip.pieces[0 ], 0 );
300+ LT_CHECK_EQ (test_ip.pieces[1 ], 0 );
301+ LT_CHECK_EQ (test_ip.pieces[2 ], 0 );
302+ LT_CHECK_EQ (test_ip.pieces[3 ], 0 );
303+ LT_CHECK_EQ (test_ip.pieces[4 ], 0 );
304+ LT_CHECK_EQ (test_ip.pieces[5 ], 0 );
305+ LT_CHECK_EQ (test_ip.pieces[6 ], 0 );
306+ LT_CHECK_EQ (test_ip.pieces[7 ], 0 );
307+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
308+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
309+ LT_CHECK_EQ (test_ip.pieces[10 ], 255 );
310+ LT_CHECK_EQ (test_ip.pieces[11 ], 255 );
311+ LT_CHECK_EQ (test_ip.pieces[12 ], 192 );
312+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
313+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
314+ LT_CHECK_EQ (test_ip.pieces[15 ], 0 );
315+
316+ LT_CHECK_EQ (test_ip.mask, 0x3FFF );
317+ LT_END_AUTO_TEST (ip_representation6_str_ipv4_mask)
318+
319+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_clustered_middle)
320+ http::ip_representation test_ip(" 2001:db8::ff00:42:8329" );
321+
322+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
323+
324+ LT_CHECK_EQ (test_ip.pieces[0 ], 32 );
325+ LT_CHECK_EQ (test_ip.pieces[1 ], 1 );
326+ LT_CHECK_EQ (test_ip.pieces[2 ], 13 );
327+ LT_CHECK_EQ (test_ip.pieces[3 ], 184 );
328+ LT_CHECK_EQ (test_ip.pieces[4 ], 0 );
329+ LT_CHECK_EQ (test_ip.pieces[5 ], 0 );
330+ LT_CHECK_EQ (test_ip.pieces[6 ], 0 );
331+ LT_CHECK_EQ (test_ip.pieces[7 ], 0 );
332+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
333+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
334+ LT_CHECK_EQ (test_ip.pieces[10 ], 255 );
335+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
336+ LT_CHECK_EQ (test_ip.pieces[12 ], 0 );
337+ LT_CHECK_EQ (test_ip.pieces[13 ], 66 );
338+ LT_CHECK_EQ (test_ip.pieces[14 ], 131 );
339+ LT_CHECK_EQ (test_ip.pieces[15 ], 41 );
340+
341+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
342+ LT_END_AUTO_TEST (ip_representation6_str_clustered_middle)
343+
344+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_loopback)
345+ http::ip_representation test_ip(" ::1" );
346+
347+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
348+
349+ LT_CHECK_EQ (test_ip.pieces[0 ], 0 );
350+ LT_CHECK_EQ (test_ip.pieces[1 ], 0 );
351+ LT_CHECK_EQ (test_ip.pieces[2 ], 0 );
352+ LT_CHECK_EQ (test_ip.pieces[3 ], 0 );
353+ LT_CHECK_EQ (test_ip.pieces[4 ], 0 );
354+ LT_CHECK_EQ (test_ip.pieces[5 ], 0 );
355+ LT_CHECK_EQ (test_ip.pieces[6 ], 0 );
356+ LT_CHECK_EQ (test_ip.pieces[7 ], 0 );
357+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
358+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
359+ LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
360+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
361+ LT_CHECK_EQ (test_ip.pieces[12 ], 0 );
362+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
363+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
364+ LT_CHECK_EQ (test_ip.pieces[15 ], 1 );
365+
366+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
367+ LT_END_AUTO_TEST (ip_representation6_str_loopback)
368+
369+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid)
370+ LT_CHECK_THROW(http::ip_representation(" 2001:db8:8714:3a90::12:4:4:4" ));
371+ LT_END_AUTO_TEST (ip_representation6_str_invalid)
372+
373+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_block_too_long)
374+ LT_CHECK_THROW(http::ip_representation(" 2001:db8:87214:3a90::12:4:4" ));
375+ LT_END_AUTO_TEST (ip_representation6_str_block_too_long)
376+
377+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_multiple_clusters)
378+ LT_CHECK_THROW(http::ip_representation(" 2001::3a90::12:4:4" ));
379+ LT_END_AUTO_TEST (ip_representation6_str_invalid_multiple_clusters)
380+
381+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_too_long_before_nested)
382+ LT_CHECK_THROW(http::ip_representation(" 2001:db8:8714:3a90:13:12:13:192.0.2.128" ));
383+ LT_END_AUTO_TEST (ip_representation6_str_invalid_too_long_before_nested)
384+
385+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_nested_beyond255)
386+ LT_CHECK_THROW(http::ip_representation(" ::ffff:192.0.256.128" ));
387+ LT_END_AUTO_TEST (ip_representation6_str_invalid_nested_beyond255)
388+
389+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_nested_not_at_end)
390+ LT_CHECK_THROW(http::ip_representation(" ::ffff:192.0.256.128:ffff" ));
391+ LT_END_AUTO_TEST (ip_representation6_str_invalid_nested_not_at_end)
392+
393+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_nested_starting_non_zero)
394+ LT_CHECK_THROW(http::ip_representation(" 0:0:1::ffff:192.0.5.128" ));
395+ LT_END_AUTO_TEST (ip_representation6_str_invalid_nested_starting_non_zero)
396+
397+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_nested_starting_wrong_prefix)
398+ LT_CHECK_THROW(http::ip_representation(" ::ffcc:192.0.5.128" ));
399+ LT_CHECK_THROW (http::ip_representation(" ::ccff:192.0.5.128" ));
400+ LT_END_AUTO_TEST (ip_representation6_str_invalid_nested_starting_wrong_prefix)
401+
212402LT_BEGIN_AUTO_TEST_ENV()
213403 AUTORUN_TESTS()
214404LT_END_AUTO_TEST_ENV()
0 commit comments