Mercurial > dovecot > core-2.2
changeset 16600:1ab7d7dd3087
lib-http: Updated test-http-response-parser
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 11 Jul 2013 10:17:49 +0300 |
parents | feac6ec9fa6e |
children | dbda2f84aeaa |
files | src/lib-http/test-http-response-parser.c |
diffstat | 1 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/test-http-response-parser.c Thu Jul 11 09:33:13 2013 +0300 +++ b/src/lib-http/test-http-response-parser.c Thu Jul 11 10:17:49 2013 +0300 @@ -173,20 +173,25 @@ "Cache-Control: private\n\r" }; +static unsigned char invalid_response_with_nuls[] = + "HTTP/1.1 200 OK\r\n" + "Server: text\0server\r\n" + "\r\n"; + unsigned int invalid_response_parse_test_count = N_ELEMENTS(invalid_response_parse_tests); static void test_http_response_parse_invalid(void) { + struct http_response_parser *parser; + struct http_response *response; + const char *response_text, *error; + struct istream *input; + int ret; unsigned int i; for (i = 0; i < invalid_response_parse_test_count; i++) T_BEGIN { - struct istream *input; const char *test; - struct http_response_parser *parser; - struct http_response *response; - const char *response_text, *error; - int ret; test = invalid_response_parse_tests[i]; response_text = test; @@ -197,10 +202,20 @@ while ((ret=http_response_parse_next(parser, FALSE, &response, &error)) > 0); - test_out("parse failure", ret < 0); + test_assert(ret < 0); test_end(); http_response_parser_deinit(&parser); } T_END; + + /* parse failure guarantees http_response_header.size equals + strlen(http_response_header.value) */ + test_begin("http response with NULs"); + input = i_stream_create_from_data(invalid_response_with_nuls, + sizeof(invalid_response_with_nuls)-1); + parser = http_response_parser_init(input); + while ((ret=http_response_parse_next(parser, FALSE, &response, &error)) > 0); + test_assert(ret < 0); + test_end(); } int main(void)