diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-09-03 13:32:56 +0200 |
---|---|---|
committer | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-09-08 15:36:24 +0200 |
commit | d7fcee3b3b5fae674f107c736f8d53610212ce4e (patch) | |
tree | b70c2afaf2fc49d5bd36102385584b3d0c72ae66 /test | |
parent | 8d6481f532ab8c502de2ad17e09f688abb675a71 (diff) | |
download | openssl-new-d7fcee3b3b5fae674f107c736f8d53610212ce4e.tar.gz |
OSSL_HTTP_parse_url(): add optional port number return parameter and strengthen documentation
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12786)
Diffstat (limited to 'test')
-rw-r--r-- | test/http_test.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/http_test.c b/test/http_test.c index f0b12a7dd0..f073dcd7ff 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -151,6 +151,72 @@ static int test_http_x509(int do_get) return res; } +static int test_http_url_ok(const char *url, const char *exp_host, int exp_ssl) +{ + char *host, *port, *path; + int num, ssl; + int res; + + res = TEST_true(OSSL_HTTP_parse_url(url, &host, &port, &num, &path, &ssl)) + && TEST_str_eq(host, exp_host) + && TEST_str_eq(port, "65535") + && TEST_int_eq(num, 65535) + && TEST_str_eq(path, "/pkix") + && TEST_int_eq(ssl, exp_ssl); + OPENSSL_free(host); + OPENSSL_free(port); + OPENSSL_free(path); + return res; +} + +static int test_http_url_dns(void) +{ + return test_http_url_ok("server:65535/pkix", "server", 0); +} + +static int test_http_url_ipv4(void) +{ + return test_http_url_ok("https://1.2.3.4:65535/pkix", "1.2.3.4", 1); +} + +static int test_http_url_ipv6(void) +{ + return test_http_url_ok("http://[FF01::101]:65535/pkix", "FF01::101", 0); +} + +static int test_http_url_invalid(const char *url) +{ + char *host = "1", *port = "1", *path = "1"; + int num = 1, ssl = 1; + int res; + + res = TEST_false(OSSL_HTTP_parse_url(url, &host, &port, &num, &path, &ssl)) + && TEST_ptr_null(host) + && TEST_ptr_null(port) + && TEST_ptr_null(path); + if (!res) { + OPENSSL_free(host); + OPENSSL_free(port); + OPENSSL_free(path); + } + return res; +} + +static int test_http_url_invalid_prefix(void) +{ + return test_http_url_invalid("htttps://1.2.3.4:65535/pkix"); +} + +static int test_http_url_invalid_port(void) +{ + return test_http_url_invalid("https://1.2.3.4:65536/pkix"); +} + +static int test_http_url_invalid_path(void) +{ + return test_http_url_invalid("https://[FF01::101]pkix"); +} + static int test_http_get_x509(void) { return test_http_x509(1); @@ -177,6 +243,12 @@ int setup_tests(void) if (!TEST_ptr((x509 = load_pem_cert(test_get_argument(0))))) return 1; + ADD_TEST(test_http_url_dns); + ADD_TEST(test_http_url_ipv4); + ADD_TEST(test_http_url_ipv6); + ADD_TEST(test_http_url_invalid_prefix); + ADD_TEST(test_http_url_invalid_port); + ADD_TEST(test_http_url_invalid_path); ADD_TEST(test_http_get_x509); ADD_TEST(test_http_post_x509); return 1; |