From d1a6c75c69538ed52f603a45b1b0e086c61c3369 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 10 Apr 2023 22:10:09 -0700 Subject: [PATCH 1/6] Make more tests port configurable. --- test/integ/basic.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index 4746423c4..c64c31d13 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -418,7 +418,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints) string s; CURL *curl = curl_easy_init(); CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/bar/"); + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/bar/"); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); @@ -436,7 +436,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints) string s; CURL *curl = curl_easy_init(); CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/bar/"); + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/bar/"); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); @@ -1267,7 +1267,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, non_family_url_with_regex_like_pieces) string s; CURL *curl = curl_easy_init(); CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/settings/{}"); + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/settings/{}"); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); @@ -1290,7 +1290,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, regex_url_exact_match) string s; CURL *curl = curl_easy_init(); CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/a/bar/"); + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/a/bar/"); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); @@ -1309,7 +1309,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, regex_url_exact_match) string s; CURL *curl = curl_easy_init(); CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/{v|[a-z]}/bar/"); + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/{v|[a-z]}/bar/"); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); From 41e0c125c7c626db303f3c7ff1e1c4b0bbdff0f6 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 10 Apr 2023 22:17:22 -0700 Subject: [PATCH 2/6] Add test of current state for how registuring family resources works. --- test/integ/basic.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index c64c31d13..12f2eb578 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -406,6 +406,100 @@ LT_BEGIN_AUTO_TEST(basic_suite, duplicate_endpoints) #endif LT_END_AUTO_TEST(duplicate_endpoints) +LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) + static_resource ok1("1"), ok2("2"); + LT_CHECK_EQ(true, ws->register_resource("OK", &ok1)); + LT_CHECK_EQ(false, ws->register_resource("OK", &ok2, true)); + + curl_global_init(CURL_GLOBAL_ALL); + + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + curl_easy_cleanup(curl); + } + + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + curl_easy_cleanup(curl); + } + + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/go"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "Not Found"); // Not registured. + curl_easy_cleanup(curl); + } + +#ifdef CASE_INSENSITIVE + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + curl_easy_cleanup(curl); + } + + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + curl_easy_cleanup(curl); + } + + { + string s; + CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/go"); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + res = curl_easy_perform(curl); + LT_ASSERT_EQ(res, 0); + LT_CHECK_EQ(s, "Not Found"); // Not registured. + curl_easy_cleanup(curl); + } +#endif +LT_END_AUTO_TEST(family_endpoints) + LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints) // Setup two different resources that can both match the same URL. static_resource ok1("1"), ok2("2"); From c686aeb6dfd256680fe949f5148491129331449f Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 2 Apr 2023 15:16:10 -0700 Subject: [PATCH 3/6] Consider family_url in ordering of http_endpoint. This will allow calling register_resource independently for a path as a family and non-family. --- src/details/http_endpoint.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/details/http_endpoint.cpp b/src/details/http_endpoint.cpp index 3bccea6d7..8133f6aac 100644 --- a/src/details/http_endpoint.cpp +++ b/src/details/http_endpoint.cpp @@ -142,6 +142,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h) { } bool http_endpoint::operator <(const http_endpoint& b) const { + if (family_url != b.family_url) return family_url; COMPARATOR(url_normalized, b.url_normalized, std::toupper); } From 6281490444427abd3a7635851e6bd191561980d3 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:05:40 -0700 Subject: [PATCH 4/6] Don't put family patterns in registered_resources_str. --- src/webserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webserver.cpp b/src/webserver.cpp index 2e77ac212..f0d458dc7 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -198,7 +198,7 @@ bool webserver::register_resource(const std::string& resource, http_resource* hr pair::iterator, bool> result = registered_resources.insert(map::value_type(idx, hrm)); - if (result.second) { + if (!family && result.second) { registered_resources_str.insert(pair(idx.get_url_complete(), result.first->second)); } From f7dc3af4f93e1533f7a26196d90326324df3a995 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 10 Apr 2023 22:19:52 -0700 Subject: [PATCH 5/6] Update test to match. --- test/integ/basic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index 12f2eb578..e3fdef72f 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -394,7 +394,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, duplicate_endpoints) LT_CHECK_EQ(false, ws->register_resource("OK/", &ok2)); // Check how family interacts. - LT_CHECK_EQ(false, ws->register_resource("OK", &ok2, true)); + LT_CHECK_EQ(true, ws->register_resource("OK", &ok2, true)); // Check that switched case does the right thing, whatever that is here. #ifdef CASE_INSENSITIVE @@ -409,7 +409,7 @@ LT_END_AUTO_TEST(duplicate_endpoints) LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) static_resource ok1("1"), ok2("2"); LT_CHECK_EQ(true, ws->register_resource("OK", &ok1)); - LT_CHECK_EQ(false, ws->register_resource("OK", &ok2, true)); + LT_CHECK_EQ(true, ws->register_resource("OK", &ok2, true)); curl_global_init(CURL_GLOBAL_ALL); @@ -451,7 +451,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "Not Found"); // Not registured. + LT_CHECK_EQ(s, "2"); curl_easy_cleanup(curl); } @@ -494,7 +494,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "Not Found"); // Not registured. + LT_CHECK_EQ(s, "2"); curl_easy_cleanup(curl); } #endif From 68e03e3ccb8f3fbced16d0e936cf68e4679a308e Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Tue, 11 Apr 2023 16:37:09 -0700 Subject: [PATCH 6/6] Remove some comments that got copy/pasted in error. --- test/integ/basic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index e3fdef72f..75fd4d6e3 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -423,7 +423,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + LT_CHECK_EQ(s, "1"); curl_easy_cleanup(curl); } @@ -437,7 +437,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + LT_CHECK_EQ(s, "1"); curl_easy_cleanup(curl); } @@ -466,7 +466,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + LT_CHECK_EQ(s, "1"); curl_easy_cleanup(curl); } @@ -480,7 +480,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); LT_ASSERT_EQ(res, 0); - LT_CHECK_EQ(s, "1"); // Not sure why regex wins, but it does... + LT_CHECK_EQ(s, "1"); curl_easy_cleanup(curl); }