From a5669298f9c87fed00235aefea02d8b84b455570 Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Tue, 4 Mar 2014 10:10:15 -0700 Subject: [openssl] Support wildcard hostname verification Most of this code comes from version Curl 7.35. --- tests/CMakeLists.txt | 5 ++++ tests/test_hostcheck.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/test_hostcheck.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7ebf545..7554794 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,3 +16,8 @@ add_executable(test_tables test_tables.c) target_link_libraries(test_tables ${RMQ_LIBRARY_TARGET}) add_test(tables test_tables) configure_file(test_tables.expected ${CMAKE_CURRENT_BINARY_DIR}/tests/test_tables.expected COPY_ONLY) + +add_executable(test_hostcheck + test_hostcheck.c + ../librabbitmq/amqp_hostcheck.c) +add_test(hostcheck test_hostcheck) diff --git a/tests/test_hostcheck.c b/tests/test_hostcheck.c new file mode 100644 index 0000000..8d562e6 --- /dev/null +++ b/tests/test_hostcheck.c @@ -0,0 +1,78 @@ +/* vim:set ft=c ts=2 sw=2 sts=2 et cindent: */ +/* + * Copyright 2014 Michael Steinert + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "amqp_hostcheck.h" + +#include +#include + +static void +hostcheck_success(const char *match_pattern, const char *url) +{ + int ok; + + ok = amqp_hostcheck(match_pattern, url); + if (! ok) { + fprintf(stderr, "Expected hostname check to pass, but didn't: %s (%s)\n", + url, match_pattern); + abort(); + } + + fprintf(stdout, "ok: [success] %s, %s\n", url, match_pattern); +} + +static void +hostcheck_fail(const char *match_pattern, const char *url) +{ + int ok; + + ok = amqp_hostcheck(match_pattern, url); + if (ok) { + fprintf(stderr, "Expected hostname check to fail, but didn't: %s (%s)\n", + url, match_pattern); + abort(); + } + + fprintf(stdout, "ok: [fail] %s, %s\n", url, match_pattern); +} + +int +main(void) +{ + hostcheck_success("www.rabbitmq.com", "www.rabbitmq.com"); + hostcheck_success("www.rabbitmq.com", "wWw.RaBbItMq.CoM"); + hostcheck_success("*.rabbitmq.com", "wWw.RaBbItMq.CoM"); + hostcheck_fail("rabbitmq.com", "www.rabbitmq.com"); + hostcheck_success("*.rabbitmq.com", "www.rabbitmq.com"); + hostcheck_fail("*.com", "www.rabbitmq.com"); + hostcheck_fail("*.rabbitmq.com", "long.url.rabbitmq.com"); + hostcheck_success("*.url.rabbitmq.com", "long.url.rabbitmq.com"); + + return 0; +} -- cgit v1.2.1