Skip to content

Commit

Permalink
Add tests for set_validate_certificates(false).
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal committed Aug 1, 2018
1 parent 3d5cb46 commit 074590c
Showing 1 changed file with 72 additions and 20 deletions.
92 changes: 72 additions & 20 deletions Release/tests/functional/http/client/outside_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST_FIXTURE(uri_address, outside_wikipedia_compressed_http_response)

auto s = response.extract_utf8string().get();
VERIFY_IS_FALSE(s.empty());

utility::string_t encoding;
VERIFY_IS_TRUE(response.headers().match(web::http::header_names::content_encoding, encoding));

Expand All @@ -93,14 +93,14 @@ TEST_FIXTURE(uri_address, outside_google_dot_com)
VERIFY_ARE_EQUAL(status_codes::OK, response.status_code());
}
}

TEST_FIXTURE(uri_address, multiple_https_requests)
{
handle_timeout([&]
{
// Use code.google.com instead of www.google.com, which redirects
http_client client(U("https://code.google.com"));

http_response response;
for(int i = 0; i < 5; ++i)
{
Expand Down Expand Up @@ -155,38 +155,90 @@ TEST_FIXTURE(uri_address, no_transfer_encoding_content_length)
// https://www.ssllabs.com/ssltest/
// http://www.internetsociety.org/deploy360/resources/dane-test-sites/
// https://onlinessl.netlock.hu/#
TEST(server_selfsigned_cert)
static void test_failed_ssl_cert(const uri& base_uri)
{
handle_timeout([]
handle_timeout([&base_uri]
{
http_client client(U("https://self-signed.badssl.com/"));
http_client client(base_uri);
auto requestTask = client.request(methods::GET);
VERIFY_THROWS(requestTask.get(), http_exception);
});
}

TEST(server_hostname_mismatch)
#if !defined(__cplusplus_winrt)
static void test_ignored_ssl_cert(const uri& base_uri)
{
handle_timeout([]
handle_timeout([&base_uri]
{
http_client client(U("https://wrong.host.badssl.com/"));
auto requestTask = client.request(methods::GET);
VERIFY_THROWS(requestTask.get(), http_exception);
http_client_config config;
config.set_validate_certificates(false);
http_client client(base_uri, config);
auto request = client.request(methods::GET).get();
VERIFY_ARE_EQUAL(status_codes::OK, request.status_code());
});
}
#endif // !defined(__cplusplus_winrt)

TEST(server_selfsigned_cert)
{
test_failed_ssl_cert(U("https://self-signed.badssl.com/"));
}

#if !defined(__cplusplus_winrt)
TEST(server_selfsigned_cert_ignored)
{
test_ignored_ssl_cert(U("https://self-signed.badssl.com/"));
}
#endif // !defined(__cplusplus_winrt)

TEST(server_hostname_mismatch)
{
test_failed_ssl_cert(U("https://wrong.host.badssl.com/"));
}

#if !defined(__cplusplus_winrt)
TEST(server_hostname_mismatch_ignored)
{
test_ignored_ssl_cert(U("https://wrong.host.badssl.com/"));
}
#endif // !defined(__cplusplus_winrt)

TEST(server_cert_expired)
{
handle_timeout([]
{
http_client_config config;
config.set_timeout(std::chrono::seconds(1));
http_client client(U("https://expired.badssl.com/"), config);
auto requestTask = client.request(methods::GET);
VERIFY_THROWS(requestTask.get(), http_exception);
});
test_failed_ssl_cert(U("https://expired.badssl.com/"));
}

#if !defined(__cplusplus_winrt)
TEST(server_cert_expired_ignored)
{
test_ignored_ssl_cert(U("https://expired.badssl.com/"));
}
#endif // !defined(__cplusplus_winrt)

TEST(server_cert_revoked)
{
test_failed_ssl_cert(U("https://revoked.badssl.com/"));
}

#if !defined(__cplusplus_winrt)
TEST(server_cert_revoked_ignored)
{
test_ignored_ssl_cert(U("https://revoked.badssl.com/"));
}
#endif // !defined(__cplusplus_winrt)

TEST(server_cert_untrusted)
{
test_failed_ssl_cert(U("https://untrusted-root.badssl.com/"));
}

#if !defined(__cplusplus_winrt)
TEST(server_cert_untrusted_ignored)
{
test_ignored_ssl_cert(U("https://untrusted-root.badssl.com/"));
}
#endif // !defined(__cplusplus_winrt)

#if !defined(__cplusplus_winrt)
TEST(ignore_server_cert_invalid,
"Ignore:Android", "229",
Expand All @@ -204,7 +256,7 @@ TEST(ignore_server_cert_invalid,
VERIFY_ARE_EQUAL(status_codes::OK, request.status_code());
});
}
#endif
#endif // !defined(__cplusplus_winrt)

TEST_FIXTURE(uri_address, outside_ssl_json)
{
Expand Down

0 comments on commit 074590c

Please sign in to comment.