bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#include "lib.h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#include "net.h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#include "http-url.h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#include "test-common.h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstruct valid_http_url_test {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *url;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch enum http_url_parse_flags flags;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url url_base;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url url_parsed;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Valid HTTP URL tests */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic struct valid_http_url_test valid_url_tests[] = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* Generic tests */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://localhost",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "localhost" } }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.%65%78%61%6d%70%6c%65.com",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "www.example.com" } }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.dovecot.org:8080",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "www.dovecot.org" },
f883bf3eff62f5d27df5ee9ee664edc38a77937fStephan Bosch .port = 8080 }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://127.0.0.1",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .name = "127.0.0.1",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .ip = { .family = AF_INET } } }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://[::1]",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .name = "[::1]",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .ip = { .family = AF_INET6 } } }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://[::1]:8080",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .name = "[::1]",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .ip = { .family = AF_INET6 } },
f883bf3eff62f5d27df5ee9ee664edc38a77937fStephan Bosch .port = 8080 }
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch },{
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url = "http://user@api.dovecot.org",
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .flags = HTTP_URL_ALLOW_USERINFO_PART,
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "api.dovecot.org" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .user = "user" }
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch },{
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url = "http://userid:secret@api.dovecot.org",
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .flags = HTTP_URL_ALLOW_USERINFO_PART,
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "api.dovecot.org" },
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .user = "userid", .password = "secret" }
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch },{
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url = "http://su%3auserid:secret@api.dovecot.org",
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .flags = HTTP_URL_ALLOW_USERINFO_PART,
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .url_parsed = {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "api.dovecot.org" },
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch .user = "su:userid", .password = "secret" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.example.com/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "?question=What%20are%20you%20doing%3f&answer=Nothing.",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .path = "/",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "www.example.com" },
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .enc_query = "question=What%20are%20you%20doing%3f&answer=Nothing." }
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody },{
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody /* These next 2 URLs don't follow the recommendations in
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody http://tools.ietf.org/html/rfc1034#section-3.5 and
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody http://tools.ietf.org/html/rfc3696
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody However they satisfy the grammar in
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody http://tools.ietf.org/html/rfc1123#section-2 and
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody http://tools.ietf.org/html/rfc952
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody so we should parse them.
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody */
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .url = "http://256.0.0.1/that/reverts/to/DNS",
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .url_parsed = {
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .path = "/that/reverts/to/DNS",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "256.0.0.1" }
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody }
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody },{
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .url = "http://127.0.0.284/this/also/reverts/to/DNS",
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .url_parsed = {
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody .path = "/this/also/reverts/to/DNS",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "127.0.0.284" }
bf3dbfd29e4d65f485b963bb5598b653e65b5f82Phil Carmody }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.example.com/#Status%20of%20development",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .path = "/",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .host = { .name = "www.example.com" },
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .enc_fragment = "Status%20of%20development" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* RFC 3986, Section 5.4. Reference Resolution Examples
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch *
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * Within a representation with a well defined base URI of
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch *
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * http://a/b/c/d;p?q
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch *
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * a relative reference is transformed to its target URI as follows.
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch *
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * 5.4.1. Normal Examples
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g" = "http://a/b/c/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "./g" = "http://a/b/c/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "./g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g/" = "http://a/b/c/g/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g/",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "/g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "/g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "//g" = "http://g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "//g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "g"} }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "?y" = "http://a/b/c/d;p?y"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "?y",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "y" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g?y" = "http://a/b/c/g?y"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g?y",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "#s" = "http://a/b/c/d;p?q#s"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "#s",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .enc_fragment = "s" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g#s" = "http://a/b/c/g#s"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g#s",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g?y#s" = "http://a/b/c/g?y#s"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g?y#s",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .enc_fragment = "s" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // ";x" = "http://a/b/c/;x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = ";x",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/;x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g;x" = "http://a/b/c/g;x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g;x",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g;x?y#s" = "http://a/b/c/g;x?y#s"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g;x?y#s",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x", .enc_query = "y",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .enc_fragment = "s" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "" = "http://a/b/c/d;p?q"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "." = "http://a/b/c/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = ".",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "./" = "http://a/b/c/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "./",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // ".." = "http://a/b/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "..",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../" = "http://a/b/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../g" = "http://a/b/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../.." = "http://a/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../..",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../../" = "http://a/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../../",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../../g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* 5.4.2. Abnormal Examples
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../../../g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../../../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "../../../../g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "../../../../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "/./g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "/./g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "/../g" = "http://a/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "/../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g." = "http://a/b/c/g."
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g.",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g." }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // ".g" = "http://a/b/c/.g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = ".g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/.g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g.." = "http://a/b/c/g.."
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g..",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g.." }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "..g" = "http://a/b/c/..g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "..g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/..g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "./../g" = "http://a/b/g"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "./../g",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/g" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "./g/." = "http://a/b/c/g/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "./g/.",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g/./h" = "http://a/b/c/g/h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g/./h",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/h" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g/../h" = "http://a/b/c/h"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g/../h",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/h" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g;x=1/./y" = "http://a/b/c/g;x=1/y"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g;x=1/./y",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x=1/y" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g;x=1/../y" = "http://a/b/c/y"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g;x=1/../y",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/y" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g?y/./x" = "http://a/b/c/g?y/./x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g?y/./x",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y/./x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g?y/../x" = "http://a/b/c/g?y/../x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g?y/../x",
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y/../x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g#s/./x" = "http://a/b/c/g#s/./x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g#s/./x",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed =
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s/./x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{ // "g#s/../x" = "http://a/b/c/g#s/../x"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "g#s/../x",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url_parsed =
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s/../x" }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic unsigned int valid_url_test_count = N_ELEMENTS(valid_url_tests);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic void test_http_url_valid(void)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch unsigned int i;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch for (i = 0; i < valid_url_test_count; i++) T_BEGIN {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *url = valid_url_tests[i].url;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch enum http_url_parse_flags flags = valid_url_tests[i].flags;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlt = &valid_url_tests[i].url_parsed;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlb = &valid_url_tests[i].url_base;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlp;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *error = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_begin(t_strdup_printf("http url valid [%d]", i));
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch if (urlb->host.name == NULL) urlb = NULL;
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen if (http_url_parse(url, urlb, flags, pool_datastack_create(), &urlp, &error) < 0)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch urlp = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_out_reason(t_strdup_printf("http_url_parse(%s)",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch valid_url_tests[i].url), urlp != NULL, error);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (urlp != NULL) {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch if (urlp->host.name == NULL || urlt->host.name == NULL) {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch test_assert(urlp->host.name == urlt->host.name);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } else {
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch test_assert(strcmp(urlp->host.name, urlt->host.name) == 0);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
f883bf3eff62f5d27df5ee9ee664edc38a77937fStephan Bosch test_assert(urlp->port == urlt->port);
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch test_assert(urlp->host.ip.family == urlt->host.ip.family);
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch if (urlp->user == NULL || urlt->user == NULL) {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(urlp->user == urlt->user);
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch } else {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(strcmp(urlp->user, urlt->user) == 0);
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch }
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch if (urlp->password == NULL || urlt->password == NULL) {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(urlp->password == urlt->password);
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch } else {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(strcmp(urlp->password, urlt->password) == 0);
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (urlp->path == NULL || urlt->path == NULL) {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(urlp->path == urlt->path);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } else {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(strcmp(urlp->path, urlt->path) == 0);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (urlp->enc_query == NULL || urlt->enc_query == NULL) {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(urlp->enc_query == urlt->enc_query);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } else {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(strcmp(urlp->enc_query, urlt->enc_query) == 0);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (urlp->enc_fragment == NULL || urlt->enc_fragment == NULL) {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(urlp->enc_fragment == urlt->enc_fragment);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } else {
29ba46818861793cc016013ce2c30e3f3d2a7d11Timo Sirainen test_assert(strcmp(urlp->enc_fragment, urlt->enc_fragment) == 0);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_end();
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } T_END;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch}
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstruct invalid_http_url_test {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *url;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch enum http_url_parse_flags flags;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url url_base;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic struct invalid_http_url_test invalid_url_tests[] = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "imap://example.com/INBOX"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http:/www.example.com"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = ""
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.example.com/index.html\""
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http:///dovecot.org"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://[]/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://[v08.234:232:234:234:2221]/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://[1::34a:34:234::6]/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example%a.com/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com%/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example%00.com/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
ffb2949c6cc3a72b4193c47a2f7fd8ddc7fd69e7Phil Carmody .url = "http://example.com:65536/index.html"
ffb2949c6cc3a72b4193c47a2f7fd8ddc7fd69e7Phil Carmody },{
ffb2949c6cc3a72b4193c47a2f7fd8ddc7fd69e7Phil Carmody .url = "http://example.com:72817/index.html"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com/settings/%00/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com/settings/%0r/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com/settings/misc/%/"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com/?%00"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://www.example.com/network.html#IMAP_Server"
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch },{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .url = "http://example.com/#%00",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch .flags = HTTP_URL_ALLOW_FRAGMENT_PART
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic unsigned int invalid_url_test_count = N_ELEMENTS(invalid_url_tests);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic void test_http_url_invalid(void)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch unsigned int i;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch for (i = 0; i < invalid_url_test_count; i++) T_BEGIN {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *url = invalid_url_tests[i].url;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch enum http_url_parse_flags flags = invalid_url_tests[i].flags;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlb = &invalid_url_tests[i].url_base;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlp;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *error = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch if (urlb->host.name == NULL)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch urlb = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_begin(t_strdup_printf("http url invalid [%d]", i));
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen if (http_url_parse(url, urlb, flags,
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen pool_datastack_create(), &urlp, &error) < 0)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch urlp = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_out_reason(t_strdup_printf("parse %s", url), urlp == NULL, error);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_end();
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } T_END;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch}
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic const char *parse_create_url_tests[] = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://10.0.0.1/",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://[::1]/",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com:993/",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/index.html",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/settings/index.html",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/%23shared/news",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/query.php?name=Hendrik%20Visser",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch "http://www.example.com/network.html#IMAP%20Server",
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic unsigned int
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschparse_create_url_test_count = N_ELEMENTS(parse_create_url_tests);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstatic void test_http_url_parse_create(void)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch{
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch unsigned int i;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch for (i = 0; i < parse_create_url_test_count; i++) T_BEGIN {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *url = parse_create_url_tests[i];
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url *urlp;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *error = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_begin(t_strdup_printf("http url parse/create [%d]", i));
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (http_url_parse
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen (url, NULL, HTTP_URL_ALLOW_FRAGMENT_PART,
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen pool_datastack_create(), &urlp, &error) < 0)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch urlp = NULL;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_out_reason(t_strdup_printf("parse %s", url), urlp != NULL, error);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch if (urlp != NULL) {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *urlnew = http_url_create(urlp);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_out(t_strdup_printf
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch ("create %s", urlnew), strcmp(url, urlnew) == 0);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch }
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_end();
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch } T_END;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch}
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschint main(void)
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch{
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_http_url_valid,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_http_url_invalid,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch test_http_url_parse_create,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch NULL
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch };
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch return test_run(test_functions);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch}
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch