summaryrefslogtreecommitdiff
path: root/test/other_tools/utils/curl_url.test.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-06 17:44:48 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-14 13:35:01 +0100
commitaf2409ef15993d97df342115b34799cc56558015 (patch)
tree7f78a954cc1b0dfdf210acb7b5d9f507386ae0a8 /test/other_tools/utils/curl_url.test.cpp
parent8d656639aa07a9677a7c4c1ce8ce0a68287d99e5 (diff)
downloadjustbuild-af2409ef15993d97df342115b34799cc56558015.tar.gz
curl_url_handle: Add method to replace the hostname of a URL
Also adds a section in the curl_url test suite.
Diffstat (limited to 'test/other_tools/utils/curl_url.test.cpp')
-rw-r--r--test/other_tools/utils/curl_url.test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/other_tools/utils/curl_url.test.cpp b/test/other_tools/utils/curl_url.test.cpp
index 61c979af..210092e3 100644
--- a/test/other_tools/utils/curl_url.test.cpp
+++ b/test/other_tools/utils/curl_url.test.cpp
@@ -135,6 +135,30 @@ TEST_CASE("Curl URL handle basics", "[curl_url_handle_basics]") {
CHECK(key_h.value()->port.value() == "80"); // default http port
CHECK(key_h.value()->path.string() == "/foo/bar?query#fragment/");
}
+
+ SECTION("Replace hostname") {
+ // full syntax check
+ auto new_url_full = CurlURLHandle::ReplaceHostname(
+ "https://user:pass@example.com:50000/some/"
+ "pa.th?what=what&who=who#fragment",
+ "example.org");
+ CHECK(new_url_full);
+ CHECK(*new_url_full ==
+ "https://user:pass@example.org:50000/some/"
+ "pa.th?what=what&who=who#fragment");
+
+ // non-supported scheme, path not normalized, spaces allowed
+ auto new_url_special = CurlURLHandle::ReplaceHostname(
+ "socks5://example.com/f oo/. ./ba r # b oo", "example.org");
+ REQUIRE(new_url_special);
+ CHECK(*new_url_special == "socks5://example.org/f oo/. ./ba r # b oo");
+
+ // missing scheme does not fail, but new URL does contain default https
+ auto new_url_default_scheme =
+ CurlURLHandle::ReplaceHostname("192.0.2.1", "192.0.2.10");
+ REQUIRE(new_url_default_scheme);
+ CHECK(*new_url_default_scheme == "https://192.0.2.10/");
+ }
}
TEST_CASE("Curl URL match config key", "[curl_url_match_config_key]") {