/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "str-sanitize.h"
#include "istream.h"
#include "test-common.h"
#include "http-response.h"
#include "http-header-parser.h"
#include <time.h>
struct http_header_parse_result {
const char *name;
const char *value;
};
struct http_header_parse_test {
const char *header;
};
/* Valid header tests */
{ "Date", "Sat, 06 Oct 2012 16:01:44 GMT" },
{ "Server", "Apache/2.2.16 (Debian)" },
{ "Last-Modified", "Mon, 30 Jul 2012 11:09:28 GMT" },
{ "Etag", "\"3d24677-3261-4c60a1863aa00\"" },
{ "Accept-Ranges", "bytes" },
{ "Vary", "Accept-Encoding" },
{ "Content-Encoding", "gzip" },
{ "Content-Length", "4092" },
{ "Keep-Alive", "timeout=15, max=100" },
{ "Connection", "Keep-Alive" },
};
{ "Host", "p5-lrqzb4yavu4l7nagydw-428649-i2-v6exp3-ds.metric.example.com" },
{ "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0)" },
{ "Accept-Language", "en-us,en;q=0.5" },
{ "Accept-Encoding", "gzip, deflate" },
{ "DNT", "1" },
{ "Connection", "keep-alive" },
{ "Referer", "http://www.example.nl/" },
};
{ "Date", "Sat, 06 Oct 2012 17:12:37 GMT" },
{ "Server", "Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14 with"
" Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.6"
{ "WWW-Authenticate", "Basic realm=\"Munin\"" },
{ "Vary", "Accept-Encoding" },
{ "Content-Encoding", "gzip" },
{ "Content-Length", "445" },
{ "Keep-Alive", "timeout=15, max=98" },
{ "Connection", "Keep-Alive" },
};
{ "Age", "58" },
{ "Date", "Sun, 04 Aug 2013 09:33:09 GMT" },
{ "Expires", "Sun, 04 Aug 2013 09:34:08 GMT" },
{ "Cache-Control", "max-age=60" },
{ "Content-Length", "17336" },
{ "Connection", "Keep-Alive" },
{ "Via", "NS-CACHE-9.3" },
{ "Server", "Apache" },
{ "Vary", "Host" },
{ "Last-Modified", "Sun, 04 Aug 2013 09:33:07 GMT" },
{ "Content-Encoding", "gzip" },
};
};
{ "X-Frop", "This text\x80 contains obs-text\x81 characters" },
};
{ "X-Frop", "This text contains invalid characters" },
};
{ .header =
"Date: Sat, 06 Oct 2012 16:01:44 GMT\r\n"
"Server: Apache/2.2.16 (Debian)\r\n"
"Last-Modified: Mon, 30 Jul 2012 11:09:28 GMT\r\n"
"Etag: \"3d24677-3261-4c60a1863aa00\"\r\n"
"Accept-Ranges: bytes\r\n"
"Vary: Accept-Encoding\r\n"
"Content-Encoding: gzip\r\n"
"Content-Length: 4092\r\n"
"Keep-Alive: timeout=15, max=100\r\n"
"Connection: Keep-Alive\r\n"
"\r\n",
},{
.header =
"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0)\n"
"Accept-Language:\ten-us,en;q=0.5\n"
"Accept-Encoding: \t\tgzip, deflate\n"
"DNT: 1\n"
"Connection: \t\tkeep-alive\n"
"Referer: http://www.example.nl/\n"
"\n",
},{
.header =
"Date: Sat, 06 Oct 2012 17:12:37 GMT\r\n"
"Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14 with\r\n"
" Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.6\r\n"
"WWW-Authenticate: Basic realm=\"Munin\"\r\n"
"Vary: Accept-Encoding\r\n"
"Content-Encoding: gzip\r\n"
"Content-Length: 445\r\n"
"Keep-Alive: timeout=15, max=98\r\n"
"Connection: Keep-Alive\r\n"
"\r\n",
},{
.header =
"Age: 58 \r\n"
"Date: Sun, 04 Aug 2013 09:33:09 GMT\r\n"
"Expires: Sun, 04 Aug 2013 09:34:08 GMT\r\n"
"Cache-Control: max-age=60 \r\n"
"Content-Length: 17336 \r\n"
"Connection: Keep-Alive\r\n"
"Via: NS-CACHE-9.3\r\n"
"Server: Apache\r\n"
"Vary: Host\r\n"
"Last-Modified: Sun, 04 Aug 2013 09:33:07 GMT\r\n"
"Content-Encoding: gzip\r\n"
"\r\n",
.limits = {
.max_size = 340,
.max_field_size = 46,
.max_fields = 12
}
},{
.header =
"\r\n",
},{
.header =
"X-Frop: This text\x80 contains obs-text\x81 characters\r\n"
"\r\n",
},{
.header =
"X-Frop: This text\x01 contains invalid\x7f characters\r\n"
"\r\n",
}
};
static void test_http_header_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_header_parse_test_count; i++) T_BEGIN {
const unsigned char *field_data;
int ret;
while ((ret=http_header_parse_next_field
const char *field_value;
if (ret == 0) {
if (pos == header_len)
break;
continue;
}
if (field_name == NULL) break;
break;
}
test_out_reason("valid",
j++;
}
test_end();
} T_END;
}
{
.header =
"Date: Sat, 06 Oct 2012 16:01:44 GMT\r\n"
"Server : Apache/2.2.16 (Debian)\r\n"
"Last-Modified: Mon, 30 Jul 2012 11:09:28 GMT\r\n"
"\r\n"
},{
.header =
"Date: Sat, 06 Oct 2012 17:18:22 GMT\r\n"
"Server: Apache/2.2.3 (CentOS)\r\n"
"X Powered By: PHP/5.3.6\r\n"
"\r\n"
},{
.header =
"Host: www.example.com\n\r"
"Accept-Language: en-us,en;q=0.5\n\r"
"Accept-Encoding: gzip, deflate\n\r"
"\n\r"
},{
.header =
"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0)\n"
"\n",
},{
.header =
"Date: Sat, 06 Oct 2012 17:18:22 GMT\r\n"
"Server: Apache/2.2.3\177 (CentOS)\r\n"
"\r\n",
},{
.header =
"Date: Sat, 06 Oct 2012 17:12:37 GMT\r\n"
"Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14 with\r\n"
"Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.6\r\n"
"\r\n"
},{
.header =
"Date: Sat, 06 Oct 2012 17:12:37 GMT\r\n"
},{
.header =
"Age: 58 \r\n"
"Date: Sun, 04 Aug 2013 09:33:09 GMT\r\n"
"Expires: Sun, 04 Aug 2013 09:34:08 GMT\r\n"
"Cache-Control: max-age=60 \r\n"
"Content-Length: 17336 \r\n"
"Connection: Keep-Alive\r\n"
"Via: NS-CACHE-9.3\r\n"
"Server: Apache\r\n"
"Vary: Host\r\n"
"Last-Modified: Sun, 04 Aug 2013 09:33:07 GMT\r\n"
"Content-Encoding: gzip\r\n"
"\r\n",
},{
.header =
"Age: 58 \r\n"
"Date: Sun, 04 Aug 2013 09:33:09 GMT\r\n"
"Expires: Sun, 04 Aug 2013 09:34:08 GMT\r\n"
"Cache-Control: max-age=60 \r\n"
"Content-Length: 17336 \r\n"
"Connection: Keep-Alive\r\n"
"Via: NS-CACHE-9.3\r\n"
"Server: Apache\r\n"
"Vary: Host\r\n"
"Last-Modified: Sun, 04 Aug 2013 09:33:07 GMT\r\n"
"Content-Encoding: gzip\r\n"
"\r\n",
},{
.header =
"Age: 58 \r\n"
"Date: Sun, 04 Aug 2013 09:33:09 GMT\r\n"
"Expires: Sun, 04 Aug 2013 09:34:08 GMT\r\n"
"Cache-Control: max-age=60 \r\n"
"Content-Length: 17336 \r\n"
"Connection: Keep-Alive\r\n"
"Via: NS-CACHE-9.3\r\n"
"Server: Apache\r\n"
"Vary: Host\r\n"
"Last-Modified: Sun, 04 Aug 2013 09:33:07 GMT\r\n"
"Content-Encoding: gzip\r\n"
"\r\n",
}
};
static void test_http_header_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_header_parse_test_count; i++) T_BEGIN {
const unsigned char *field_data;
int ret;
while ((ret=http_header_parse_next_field
if (field_name == NULL) break;
}
test_end();
} T_END;
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}