/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include "http-url.h"
#include "test-common.h"
struct valid_http_url_test {
const char *url;
};
/* Valid HTTP URL tests */
/* Generic tests */
{
.url = "http://localhost",
.url_parsed = {
},{
.url_parsed = {
},{
.url_parsed = {
.port = 8080 }
},{
.url = "http://127.0.0.1",
.url_parsed = {
.host = {
.name = "127.0.0.1",
},{
.url = "http://[::1]",
.url_parsed = {
.host = {
.name = "[::1]",
},{
.url = "http://[::1]:8080",
.url_parsed = {
.host = {
.name = "[::1]",
.port = 8080 }
},{
.url_parsed = {
.user = "user" }
},{
.url_parsed = {
},{
.url_parsed = {
},{
"?question=What%20are%20you%20doing%3f&answer=Nothing.",
.url_parsed = {
.path = "/",
.enc_query = "question=What%20are%20you%20doing%3f&answer=Nothing." }
},{
/* These next 2 URLs don't follow the recommendations in
http://tools.ietf.org/html/rfc1034#section-3.5 and
However they satisfy the grammar in
http://tools.ietf.org/html/rfc1123#section-2 and
so we should parse them.
*/
.url_parsed = {
}
},{
.url_parsed = {
}
},{
.url = "http://www.example.com/#Status%20of%20development",
.url_parsed = {
.path = "/",
.enc_fragment = "Status%20of%20development" }
/* RFC 3986, Section 5.4. Reference Resolution Examples
*
* Within a representation with a well defined base URI of
*
*
* a relative reference is transformed to its target URI as follows.
*
* 5.4.1. Normal Examples
*/
},{ // "g" = "http://a/b/c/g"
.url = "g",
},{ // "./g" = "http://a/b/c/g"
.url = "./g",
},{ // "g/" = "http://a/b/c/g/"
.url = "g/",
},{ // "/g" = "http://a/g"
.url = "/g",
},{ // "//g" = "http://g"
.url = "//g",
},{ // "?y" = "http://a/b/c/d;p?y"
.url = "?y",
},{ // "g?y" = "http://a/b/c/g?y"
.url = "g?y",
},{ // "#s" = "http://a/b/c/d;p?q#s"
.url = "#s",
.enc_fragment = "s" }
},{ // "g#s" = "http://a/b/c/g#s"
.url = "g#s",
},{ // "g?y#s" = "http://a/b/c/g?y#s"
.url = "g?y#s",
.enc_fragment = "s" }
},{ // ";x" = "http://a/b/c/;x"
.url = ";x",
},{ // "g;x" = "http://a/b/c/g;x"
.url = "g;x",
},{ // "g;x?y#s" = "http://a/b/c/g;x?y#s"
.url = "g;x?y#s",
.enc_fragment = "s" }
},{ // "" = "http://a/b/c/d;p?q"
.url = "",
},{ // "." = "http://a/b/c/"
.url = ".",
},{ // "./" = "http://a/b/c/"
.url = "./",
},{ // ".." = "http://a/b/"
.url = "..",
},{ // "../" = "http://a/b/"
.url = "../",
},{ // "../g" = "http://a/b/g"
.url = "../g",
},{ // "../.." = "http://a/"
.url = "../..",
},{ // "../../" = "http://a/"
.url = "../../",
},{ // "../../g" = "http://a/g"
.url = "../../g",
/* 5.4.2. Abnormal Examples
*/
},{ // "../../../g" = "http://a/g"
.url = "../../../g",
},{ // "../../../../g" = "http://a/g"
.url = "../../../../g",
},{ // "/./g" = "http://a/g"
.url = "/./g",
},{ // "/../g" = "http://a/g"
.url = "/../g",
},{ // "g." = "http://a/b/c/g."
.url = "g.",
},{ // ".g" = "http://a/b/c/.g"
.url = ".g",
},{ // "g.." = "http://a/b/c/g.."
.url = "g..",
},{ // "..g" = "http://a/b/c/..g"
.url = "..g",
},{ // "./../g" = "http://a/b/g"
.url = "./../g",
},{ // "./g/." = "http://a/b/c/g/"
.url = "./g/.",
},{ // "g/./h" = "http://a/b/c/g/h"
.url = "g/./h",
},{ // "g/../h" = "http://a/b/c/h"
.url = "g/../h",
},{ // "g;x=1/./y" = "http://a/b/c/g;x=1/y"
.url = "g;x=1/./y",
},{ // "g;x=1/../y" = "http://a/b/c/y"
.url = "g;x=1/../y",
},{ // "g?y/./x" = "http://a/b/c/g?y/./x"
.url = "g?y/./x",
},{ // "g?y/../x" = "http://a/b/c/g?y/../x"
.url = "g?y/../x",
},{ // "g#s/./x" = "http://a/b/c/g#s/./x"
.url = "g#s/./x",
.url_parsed =
},{ // "g#s/../x" = "http://a/b/c/g#s/../x"
.url = "g#s/../x",
.url_parsed =
}
};
static void test_http_url_valid(void)
{
unsigned int i;
for (i = 0; i < valid_url_test_count; i++) T_BEGIN {
} else {
}
} else {
}
} else {
}
} else {
}
} else {
}
} else {
}
}
test_end();
} T_END;
}
struct invalid_http_url_test {
const char *url;
};
{
.url = "imap://example.com/INBOX"
},{
.url = "http:/www.example.com"
},{
.url = ""
},{
.url = "/index.html"
},{
},{
.url = "http:///dovecot.org"
},{
.url = "http://[]/index.html"
},{
.url = "http://[v08.234:232:234:234:2221]/index.html"
},{
.url = "http://[1::34a:34:234::6]/index.html"
},{
},{
},{
},{
},{
},{
},{
},{
},{
},{
.url = "http://www.example.com/network.html#IMAP_Server"
},{
.url = "http://example.com/#%00",
}
};
static void test_http_url_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_url_test_count; i++) T_BEGIN {
test_end();
} T_END;
}
static const char *parse_create_url_tests[] = {
"http://[::1]/",
"http://www.example.com/network.html#IMAP%20Server",
};
static unsigned int
static void test_http_url_parse_create(void)
{
unsigned int i;
for (i = 0; i < parse_create_url_test_count; i++) T_BEGIN {
if (http_url_parse
}
test_end();
} T_END;
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}