summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-03-01 22:54:09 +0100
committerJoel Klinghed <the_jk@yahoo.com>2017-03-01 22:54:09 +0100
commit719d90a40e83e870be19f8d46cc55caed618aa35 (patch)
tree10bc226c44aff6cfa3c53e5d837a32720c9bf836 /test
parent537ed164ae1875a8d38e06dbc214ef4f91bc4642 (diff)
Add support for CONNECT
Diffstat (limited to 'test')
-rw-r--r--test/test-url.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test-url.cc b/test/test-url.cc
index 79e6564..41c41e8 100644
--- a/test/test-url.cc
+++ b/test/test-url.cc
@@ -170,6 +170,39 @@ bool relative(std::string const& url, std::string const& base,
return true;
}
+bool good_authority(std::string const& str,
+ std::string const& host,
+ uint16_t port) {
+ std::string h;
+ uint16_t p;
+ if (!Url::parse_authority(str, &h, &p)) {
+ std::cerr << "good_authority:" << str << ": Invalid authority" << std::endl;
+ return false;
+ }
+ if (host != h) {
+ std::cerr << "good_authority:" << str << ":host: Expected " << host
+ << " got " << h << std::endl;
+ return false;
+ }
+ if (port != p) {
+ std::cerr << "good_authority:" << str << ":port: Expected " << port
+ << " got " << p << std::endl;
+ return false;
+ }
+ return true;
+}
+
+bool bad_authority(std::string const& str) {
+ std::string h;
+ uint16_t p;
+ if (Url::parse_authority(str, &h, &p)) {
+ std::cerr << "bad_authority:" << str << ": Expected invalid autority got "
+ << h << ':' << p << std::endl;
+ return false;
+ }
+ return true;
+}
+
} // namespace
int main() {
@@ -208,5 +241,13 @@ int main() {
RUN(relative("foo#c", "http://host/#b", "http://host/foo#c"));
RUN(relative("foo#c", "http://host/?b", "http://host/foo#c"));
RUN(relative("foo", "http://host/?b", "http://host/foo"));
+ RUN(good_authority("www.example.org", "www.example.org", 0));
+ RUN(good_authority("www.example.org:80", "www.example.org", 80));
+ RUN(good_authority("localhost:5678", "localhost", 5678));
+ RUN(good_authority("[::1]:5678", "::1", 5678));
+ RUN(good_authority("::1:5678", "::1", 5678));
+ RUN(bad_authority("foo@localhost"));
+ RUN(bad_authority(""));
+ RUN(bad_authority(":500"));
AFTER;
}