dovecot-2.2: lib-http: Updated test-http-response-parser

dovecot at dovecot.org dovecot at dovecot.org
Thu Jul 11 10:18:03 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/1ab7d7dd3087
changeset: 16600:1ab7d7dd3087
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jul 11 10:17:49 2013 +0300
description:
lib-http: Updated test-http-response-parser

diffstat:

 src/lib-http/test-http-response-parser.c |  27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r feac6ec9fa6e -r 1ab7d7dd3087 src/lib-http/test-http-response-parser.c
--- 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)


More information about the dovecot-cvs mailing list