Mercurial > dovecot > core-2.2
annotate src/lib-http/test-http-response-parser.c @ 23017:c1d36f2575c7 default tip
lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author | Timo Sirainen <timo.sirainen@open-xchange.com> |
---|---|
date | Thu, 29 Aug 2019 09:55:25 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22481
diff
changeset
|
1 /* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
2 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
3 #include "test-lib.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
4 #include "buffer.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
5 #include "str.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
6 #include "str-sanitize.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
7 #include "istream.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
8 #include "ostream.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
9 #include "test-common.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
10 #include "http-response-parser.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
11 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
12 #include <time.h> |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
13 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
14 struct valid_parse_test_response { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
15 unsigned char version_major; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
16 unsigned char version_minor; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
17 unsigned int status; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
18 uoff_t content_length; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
19 const char *payload; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
20 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
21 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
22 struct valid_parse_test { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
23 const char *input; |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
24 enum http_response_parse_flags flags; |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
25 |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
26 const struct valid_parse_test_response *responses; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
27 unsigned int responses_count; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
28 }; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
29 |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
30 /* Valid response tests */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
31 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
32 static const struct valid_parse_test_response valid_responses1[] = { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
33 { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
34 .status = 200, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
35 .payload = "This is a piece of stupid text.\r\n" |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
36 } |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
37 }; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
38 |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
39 static const struct valid_parse_test_response valid_responses2[] = { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
40 { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
41 .status = 200, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
42 .payload = "This is a piece of stupid text.\r\n" |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
43 },{ |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
44 .status = 200, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
45 .payload = "This is a piece of even more stupid text.\r\n" |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
46 } |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
47 }; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
48 |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
49 static const struct valid_parse_test_response valid_responses3[] = { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
50 { |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
51 .status = 401, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
52 .payload = "Frop!" |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
53 } |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
54 }; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
55 |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
56 static const struct valid_parse_test_response valid_responses4[] = { |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
57 { |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
58 .status = 200, |
22481
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
59 .payload = "Invalid date header" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
60 } |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
61 }; |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
62 |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
63 static const struct valid_parse_test_response valid_responses5[] = { |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
64 { |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
65 .status = 200, |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
66 .payload = "Duplicate headers" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
67 } |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
68 }; |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
69 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
70 static const struct valid_parse_test |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
71 valid_response_parse_tests[] = { |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
72 { .input = |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
73 "HTTP/1.1 200 OK\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
74 "Date: Sun, 07 Oct 2012 13:02:27 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
75 "Server: Apache/2.2.16 (Debian)\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
76 "Last-Modified: Tue, 18 Sep 2012 19:31:41 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
77 "Etag: \"2a8400c-10751f-4c9fef0858140\"\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
78 "Accept-Ranges: bytes\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
79 "Content-Length: 33\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
80 "Keep-Alive: timeout=15, max=100\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
81 "Connection: Keep-Alive\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
82 "Content-Type: text/plain\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
83 "\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
84 "This is a piece of stupid text.\r\n", |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
85 .responses = valid_responses1, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
86 .responses_count = N_ELEMENTS(valid_responses1) |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
87 },{ |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
88 .input = |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
89 "HTTP/1.1 200 OK\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
90 "Date: Sun, 07 Oct 2012 13:02:27 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
91 "Server: Apache/2.2.16 (Debian)\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
92 "Last-Modified: Tue, 18 Sep 2012 19:31:41 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
93 "Etag: \"2a8400c-10751f-4c9fef0858140\"\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
94 "Accept-Ranges: bytes\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
95 "Content-Length: 33\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
96 "Keep-Alive: timeout=15, max=100\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
97 "Connection: Keep-Alive\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
98 "Content-Type: text/plain\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
99 "\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
100 "This is a piece of stupid text.\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
101 "HTTP/1.1 200 OK\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
102 "Date: Sun, 07 Oct 2012 13:02:27 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
103 "Server: Apache/2.2.16 (Debian)\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
104 "Last-Modified: Tue, 18 Sep 2012 19:31:41 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
105 "Etag: \"2a8400c-10751f-4c9fef0858140\"\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
106 "Accept-Ranges: bytes\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
107 "Content-Length: 43\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
108 "Keep-Alive: timeout=15, max=100\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
109 "Connection: Keep-Alive\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
110 "Content-Type: text/plain\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
111 "\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
112 "This is a piece of even more stupid text.\r\n", |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
113 .responses = valid_responses2, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
114 .responses_count = N_ELEMENTS(valid_responses2) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
115 },{ |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
116 .input = |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
117 "HTTP/1.1 401 Authorization Required\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
118 "Date: Sun, 07 Oct 2012 19:52:03 GMT\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
119 "Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
120 "WWW-Authenticate: Basic realm=\"Munin\"\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
121 "Vary: Accept-Encoding\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
122 "Content-Encoding: gzip\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
123 "Content-Length: 5\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
124 "Keep-Alive: timeout=15, max=99\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
125 "Connection: Keep-Alive\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
126 "Content-Type: text/html; charset=iso-8859-1\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
127 "\r\n" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
128 "Frop!", |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
129 .responses = valid_responses3, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
130 .responses_count = N_ELEMENTS(valid_responses3) |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
131 },{ |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
132 .input = |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
133 "HTTP/1.1 200 OK\r\n" |
22481
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
134 "Date: Sun, 07 Ocu 2012 19:52:03 GMT\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
135 "Content-Length: 19\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
136 "Keep-Alive: timeout=15, max=99\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
137 "Connection: Keep-Alive\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
138 "Date: Sun, 13 Oct 2013 13:13:13 GMT\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
139 "\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
140 "Invalid date header", |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
141 .responses = valid_responses4, |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
142 .responses_count = N_ELEMENTS(valid_responses4) |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
143 },{ |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
144 .input = |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
145 "HTTP/1.1 200 OK\r\n" |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
146 "Date: Sun, 07 Oct 2012 19:52:03 GMT\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
147 "Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
148 "Content-Length: 17\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
149 "Keep-Alive: timeout=15, max=99\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
150 "Connection: Keep-Alive\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
151 "Content-Type: text/html; charset=iso-8859-1\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
152 "Date: Sun, 13 Oct 2013 13:13:13 GMT\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
153 "\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
154 "Duplicate headers", |
22481
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
155 .responses = valid_responses5, |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
156 .responses_count = N_ELEMENTS(valid_responses5) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
157 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
158 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
159 |
17399
d410e5ab6dd8
lib-http: trivial sparse cleanups - statics and explicit NULLs
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
160 static const unsigned int valid_response_parse_test_count = |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
161 N_ELEMENTS(valid_response_parse_tests); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
162 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
163 static void test_http_response_parse_valid(void) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
164 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
165 unsigned int i; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
166 buffer_t *payload_buffer = buffer_create_dynamic(default_pool, 1024); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
167 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
168 for (i = 0; i < valid_response_parse_test_count; i++) T_BEGIN { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
169 struct istream *input; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
170 struct ostream *output; |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
171 const struct valid_parse_test *test; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
172 const struct valid_parse_test_response *tresponse; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
173 struct http_response_parser *parser; |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
174 struct http_response presponse; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
175 const char *input_text, *payload, *error; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
176 unsigned int j, pos, input_text_len; |
16597
07fb7d4665c6
lib-http: Fixed handling responses whose header arrives in smaller pieces.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
177 int ret = 0; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
178 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
179 i_zero(&presponse); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
180 test = &valid_response_parse_tests[i]; |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
181 input_text = test->input; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
182 input_text_len = strlen(input_text); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
183 input = test_istream_create_data(input_text, input_text_len); |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
184 parser = http_response_parser_init(input, NULL, |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
185 valid_response_parse_tests[i].flags); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
186 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
187 test_begin(t_strdup_printf("http response valid [%d]", i)); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
188 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
189 payload = NULL; |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
190 for (pos = 0; pos < input_text_len && ret == 0; pos++) { |
16598
55ae488349d2
lib-http: Fixed previous test-http-response-parser change.
Timo Sirainen <tss@iki.fi>
parents:
16597
diff
changeset
|
191 test_istream_set_size(input, pos); |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
192 ret = http_response_parse_next(parser, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
193 HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED, &presponse, &error); |
16597
07fb7d4665c6
lib-http: Fixed handling responses whose header arrives in smaller pieces.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
194 } |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
195 test_istream_set_size(input, input_text_len); |
19360
f049fe9e7799
lib-http: free resources used in the tests
Phil Carmody <phil@dovecot.fi>
parents:
18137
diff
changeset
|
196 i_stream_unref(&input); |
f049fe9e7799
lib-http: free resources used in the tests
Phil Carmody <phil@dovecot.fi>
parents:
18137
diff
changeset
|
197 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
198 j = 0; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
199 test_out("parse success", ret > 0); |
16597
07fb7d4665c6
lib-http: Fixed handling responses whose header arrives in smaller pieces.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
200 while (ret > 0) { |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
201 if (presponse.payload != NULL) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
202 buffer_set_used_size(payload_buffer, 0); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
203 output = o_stream_create_buffer(payload_buffer); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
204 test_out("payload receive", |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
205 o_stream_send_istream(output, presponse.payload)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
206 o_stream_destroy(&output); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
207 payload = str_c(payload_buffer); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
208 } else { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
209 payload = NULL; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
210 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
211 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
212 test_assert(j < test->responses_count); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
213 if (j >= test->responses_count) |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
214 break; |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
215 tresponse = &test->responses[j]; |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
216 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
217 /* verify last response only */ |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
218 test_out(t_strdup_printf("response->status = %d", |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
219 tresponse->status), |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
220 presponse.status == tresponse->status); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
221 if (payload == NULL || tresponse->payload == NULL) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
222 test_out(t_strdup_printf("response->payload = %s", |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
223 str_sanitize(payload, 80)), |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
224 payload == tresponse->payload); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
225 } else { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
226 test_out(t_strdup_printf("response->payload = %s", |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
227 str_sanitize(payload, 80)), |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
228 strcmp(payload, tresponse->payload) == 0); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
229 } |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
230 |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
231 ret = http_response_parse_next(parser, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
232 HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED, &presponse, &error); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
233 if (++j == test->responses_count) |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
234 test_out("parse end", ret == 0); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
235 else |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
236 test_out("parse success", ret > 0); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
237 } |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
238 |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
239 test_assert(ret == 0); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
240 test_end(); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
241 http_response_parser_deinit(&parser); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
242 } T_END; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
243 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
244 buffer_free(&payload_buffer); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
245 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
246 |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
247 /* |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
248 * Invalid response tests |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
249 */ |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
250 |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
251 struct invalid_parse_test { |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
252 const char *input; |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
253 enum http_response_parse_flags flags; |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
254 }; |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
255 |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
256 static struct invalid_parse_test invalid_response_parse_tests[] = { |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
257 { |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
258 .input = |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
259 "XMPP/1.0 302 Found\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
260 "Location: http://www.example.nl/\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
261 "Cache-Control: private\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
262 },{ |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
263 .input = |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
264 "HTTP/1.1 302 Found\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
265 "Location: http://www.example.nl/\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
266 "Cache-Control: private\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
267 },{ |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
268 .input = |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
269 "HTTP/1.1 ABC Found\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
270 "Location: http://www.example.nl/\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
271 "Cache-Control: private\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
272 },{ |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
273 .input = |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
274 "HTTP/1.1 302 \177\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
275 "Location: http://www.example.nl/\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
276 "Cache-Control: private\r\n" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
277 },{ |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
278 .input = |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
279 "HTTP/1.1 302 Found\n\r" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
280 "Location: http://www.example.nl/\n\r" |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
281 "Cache-Control: private\n\r" |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
282 },{ |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
283 .input = |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
284 "HTTP/1.1 200 OK\r\n" |
22481
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
285 "Date: Sun, 07 Ocu 2012 19:52:03 GMT\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
286 "Content-Length: 19\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
287 "Keep-Alive: timeout=15, max=99\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
288 "Connection: Keep-Alive\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
289 "\r\n" |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
290 "Invalid date header", |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
291 .flags = HTTP_RESPONSE_PARSE_FLAG_STRICT |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
292 },{ |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
293 .input = |
658e239267b2
lib-http: message parser: Reject messages with invalid Date header when HTTP_MESSAGE_PARSE_FLAG_STRICT flag is enabled.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22479
diff
changeset
|
294 "HTTP/1.1 200 OK\r\n" |
22390
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
295 "Date: Sun, 07 Oct 2012 19:52:03 GMT\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
296 "Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
297 "Content-Length: 17\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
298 "Keep-Alive: timeout=15, max=99\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
299 "Connection: Keep-Alive\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
300 "Content-Type: text/html; charset=iso-8859-1\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
301 "Date: Sun, 13 Oct 2013 13:13:13 GMT\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
302 "\r\n" |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
303 "Duplicate headers", |
110cf7691bba
lib-http: message parser: Allow duplicate date header if HTTP_MESSAGE_PARSE_FLAG_STRICT is not set.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22389
diff
changeset
|
304 .flags = HTTP_RESPONSE_PARSE_FLAG_STRICT |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
305 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
306 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
307 |
17399
d410e5ab6dd8
lib-http: trivial sparse cleanups - statics and explicit NULLs
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
308 static const unsigned int invalid_response_parse_test_count = |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
309 N_ELEMENTS(invalid_response_parse_tests); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
310 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
311 static void test_http_response_parse_invalid(void) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
312 { |
16600
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
313 struct http_response_parser *parser; |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16658
diff
changeset
|
314 struct http_response response; |
16600
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
315 const char *response_text, *error; |
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
316 struct istream *input; |
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
317 int ret; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
318 unsigned int i; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
319 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
320 for (i = 0; i < invalid_response_parse_test_count; i++) T_BEGIN { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
321 const char *test; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
322 |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
323 test = invalid_response_parse_tests[i].input; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
324 response_text = test; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
325 input = i_stream_create_from_data(response_text, strlen(response_text)); |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
326 parser = http_response_parser_init(input, NULL, |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
327 invalid_response_parse_tests[i].flags); |
19360
f049fe9e7799
lib-http: free resources used in the tests
Phil Carmody <phil@dovecot.fi>
parents:
18137
diff
changeset
|
328 i_stream_unref(&input); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
329 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
330 test_begin(t_strdup_printf("http response invalid [%d]", i)); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
331 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
332 while ((ret=http_response_parse_next(parser, FALSE, &response, &error)) > 0); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
333 |
22479
90957875c55b
lib-http: test-http-response-parser: Show error message for tests of invalid responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22390
diff
changeset
|
334 test_out_reason("parse failure", ret < 0, error); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
335 test_end(); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
336 http_response_parser_deinit(&parser); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
337 } T_END; |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
338 } |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
339 |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
340 /* |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
341 * Bad response tests |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
342 */ |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
343 |
17399
d410e5ab6dd8
lib-http: trivial sparse cleanups - statics and explicit NULLs
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
344 static const unsigned char bad_response_with_nuls[] = |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
345 "HTTP/1.1 200 OK\r\n" |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
346 "Server: text\0server\r\n" |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
347 "\r\n"; |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
348 |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
349 static void test_http_response_parse_bad(void) |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
350 { |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
351 struct http_response_parser *parser; |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
352 struct http_response response; |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
353 const char *header, *error; |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
354 struct istream *input; |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
355 int ret; |
16600
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
356 |
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
357 /* parse failure guarantees http_response_header.size equals |
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
358 strlen(http_response_header.value) */ |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
359 |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
360 test_begin("http response with NULs (strict)"); |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
361 input = i_stream_create_from_data(bad_response_with_nuls, |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
362 sizeof(bad_response_with_nuls)-1); |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
363 parser = http_response_parser_init(input, NULL, |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
364 HTTP_RESPONSE_PARSE_FLAG_STRICT); |
19360
f049fe9e7799
lib-http: free resources used in the tests
Phil Carmody <phil@dovecot.fi>
parents:
18137
diff
changeset
|
365 i_stream_unref(&input); |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
366 |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
367 while ((ret=http_response_parse_next(parser, |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
368 HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED, &response, &error)) > 0); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
369 test_assert(ret < 0); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
370 http_response_parser_deinit(&parser); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
371 test_end(); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
372 |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
373 /* even when lenient, bad characters like NUL must not be returned */ |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
374 test_begin("http response with NULs (lenient)"); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
375 input = i_stream_create_from_data(bad_response_with_nuls, |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
376 sizeof(bad_response_with_nuls)-1); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
377 parser = http_response_parser_init(input, NULL, 0); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
378 i_stream_unref(&input); |
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
379 |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
380 ret = http_response_parse_next(parser, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
381 HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED, &response, &error); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
382 test_out("parse success", ret > 0); |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
383 header = http_response_header_get(&response, "server"); |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
384 test_out("header present", header != NULL); |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
385 if (header != NULL) { |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
386 test_out(t_strdup_printf("header Server: %s", header), |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
387 strcmp(header, "textserver") == 0); |
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
388 } |
21608
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
389 ret = http_response_parse_next(parser, |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
390 HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED, &response, &error); |
62897d9f1e85
lib-http: test-http-response-parse: Properly test multiple sequential responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
391 test_out("parse end", ret == 0); |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21608
diff
changeset
|
392 http_response_parser_deinit(&parser); |
16600
1ab7d7dd3087
lib-http: Updated test-http-response-parser
Timo Sirainen <tss@iki.fi>
parents:
16598
diff
changeset
|
393 test_end(); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
394 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
395 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
396 int main(void) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
397 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
398 static void (*test_functions[])(void) = { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
399 test_http_response_parse_valid, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
400 test_http_response_parse_invalid, |
17094
4650bfc057fb
lib-http: Added option to the header parser to make it lenient towards illegal characters in header field content.
Stephan Bosch <stephan@rename-it.nl>
parents:
16928
diff
changeset
|
401 test_http_response_parse_bad, |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
402 NULL |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
403 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
404 return test_run(test_functions); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
405 } |