From 9dfaa67f2b74a11d7cc2a58d28961547b19462fc Mon Sep 17 00:00:00 2001 From: Bertrand Paquet Date: Sat, 7 Jul 2012 22:14:12 +0200 Subject: [PATCH] Check host on url with hostname:port --- test.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/test.c b/test.c index 6d8c004..23bcf5d 100644 --- a/test.c +++ b/test.c @@ -50,6 +50,7 @@ struct message { char query_string[MAX_ELEMENT_SIZE]; char body[MAX_ELEMENT_SIZE]; size_t body_size; + const char *host; uint16_t port; int num_headers; enum { NONE=0, FIELD, VALUE } last_header_element; @@ -649,6 +650,7 @@ const struct message requests[] = ,.fragment= "" ,.request_path= "" ,.request_url= "http://hypnotoad.org:1234?hail=all" + ,.host= "hypnotoad.org" ,.port= 1234 ,.num_headers= 0 ,.headers= { } @@ -669,6 +671,7 @@ const struct message requests[] = ,.fragment= "" ,.request_path= "" ,.request_url= "http://hypnotoad.org:1234" + ,.host= "hypnotoad.org" ,.port= 1234 ,.num_headers= 0 ,.headers= { } @@ -1794,6 +1797,10 @@ message_eq (int index, const struct message *expected) abort(); } + if (expected->host) { + MESSAGE_CHECK_URL_EQ(&u, expected, m, host, UF_HOST); + } + m->port = (u.field_set & (1 << UF_PORT)) ? u.port : 0; @@ -1971,6 +1978,24 @@ const struct url_test url_tests[] = ,.rv=0 } +, {.name="proxy request with port" + ,.url="http://hostname:444/" + ,.is_connect=0 + ,.u= + {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH) + ,.port=444 + ,.field_data= + {{ 0, 4 } /* UF_SCHEMA */ + ,{ 7, 8 } /* UF_HOST */ + ,{ 16, 3 } /* UF_PORT */ + ,{ 19, 1 } /* UF_PATH */ + ,{ 0, 0 } /* UF_QUERY */ + ,{ 0, 0 } /* UF_FRAGMENT */ + } + } + ,.rv=0 + } + , {.name="CONNECT request" ,.url="hostname:443" ,.is_connect=1 @@ -2007,6 +2032,24 @@ const struct url_test url_tests[] = ,.rv=0 } +, {.name="proxy ipv6 request with port" + ,.url="http://[1:2::3:4]:67/" + ,.is_connect=0 + ,.u= + {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH) + ,.port=67 + ,.field_data= + {{ 0, 4 } /* UF_SCHEMA */ + ,{ 8, 8 } /* UF_HOST */ + ,{ 18, 2 } /* UF_PORT */ + ,{ 20, 1 } /* UF_PATH */ + ,{ 0, 0 } /* UF_QUERY */ + ,{ 0, 0 } /* UF_FRAGMENT */ + } + } + ,.rv=0 + } + , {.name="CONNECT ipv6 address" ,.url="[1:2::3:4]:443" ,.is_connect=1 @@ -2043,6 +2086,79 @@ const struct url_test url_tests[] = ,.rv=0 } +, {.name="space URL encoded" + ,.url="/toto.html?toto=a%20b" + ,.is_connect=0 + ,.u= + {.field_set= (1<