Skip to content

Commit 1ab10c9

Browse files
committed
Merge branch 'xqp-feature/get_human_readable_ssl_errors'
2 parents 1a5e734 + 8b186cb commit 1ab10c9

File tree

7 files changed

+334
-271
lines changed

7 files changed

+334
-271
lines changed

Release/src/http/client/http_client_winhttp.cpp

Lines changed: 311 additions & 253 deletions
Large diffs are not rendered by default.

Release/src/pch/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#include <exception>
8989
#include <assert.h>
9090
#include <streambuf>
91+
#include <atomic>
9192
#include <mutex>
9293
#include <array>
9394
#include <vector>

Release/tests/functional/http/client/authentication_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ TEST_FIXTURE(uri_address, failed_authentication_attempt, "Ignore:Linux", "89", "
646646
void auth_test_impl(bool fail)
647647
{
648648
std::string user("user1"), password("user1");
649-
auto return_code = status_codes::NotFound; // return 404 if successful auth
649+
auto return_code = status_codes::OK;
650650

651651
if (fail)
652652
{
@@ -657,7 +657,7 @@ void auth_test_impl(bool fail)
657657
http_client_config client_config;
658658
web::credentials cred(U(user), U(password));
659659
client_config.set_credentials(cred);
660-
http_client client(U("http://test.webdav.org/auth-basic/"), client_config);
660+
http_client client(U("http://httpbin.org/basic-auth/user1/user1"), client_config);
661661

662662
http_response response = client.request(methods::GET).get();
663663
VERIFY_ARE_EQUAL(return_code, response.status_code());

Release/tests/functional/http/client/connections_and_errors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TEST_FIXTURE(uri_address, server_doesnt_exist)
9191
http_client_config config;
9292
config.set_timeout(std::chrono::seconds(1));
9393
http_client client(m_uri, config);
94-
VERIFY_THROWS_HTTP_ERROR_CODE(client.request(methods::GET).wait(), std::errc::host_unreachable);
94+
VERIFY_THROWS(client.request(methods::GET).wait(), web::http::http_exception);
9595
}
9696

9797
TEST_FIXTURE(uri_address, open_failure)
@@ -125,7 +125,7 @@ TEST_FIXTURE(uri_address, server_close_without_responding)
125125
VERIFY_THROWS_HTTP_ERROR_CODE(response.wait(), std::errc::connection_aborted);
126126

127127
// Try sending another request.
128-
VERIFY_THROWS_HTTP_ERROR_CODE(client.request(methods::GET).wait(), std::errc::host_unreachable);
128+
VERIFY_THROWS(client.request(methods::GET).wait(), web::http::http_exception);
129129
}
130130

131131
TEST_FIXTURE(uri_address, request_timeout)

Release/tests/functional/http/client/outside_tests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,25 @@ TEST_FIXTURE(uri_address, no_transfer_encoding_content_length)
151151
}
152152

153153
// Note additional sites for testing can be found at:
154+
// https://badssl.com/
154155
// https://www.ssllabs.com/ssltest/
155156
// http://www.internetsociety.org/deploy360/resources/dane-test-sites/
156157
// https://onlinessl.netlock.hu/#
157158
TEST(server_selfsigned_cert)
158159
{
159160
handle_timeout([]
160161
{
161-
http_client client(U("https://www.pcwebshop.co.uk/"));
162+
http_client client(U("https://self-signed.badssl.com/"));
162163
auto requestTask = client.request(methods::GET);
163164
VERIFY_THROWS(requestTask.get(), http_exception);
164165
});
165166
}
166167

167-
TEST(server_hostname_mismatch, "Ignore", "Site fixed certificate. Improve test (new site or alternate method).")
168+
TEST(server_hostname_mismatch)
168169
{
169170
handle_timeout([]
170171
{
171-
http_client client(U("https://swordsoftruth.com/"));
172+
http_client client(U("https://wrong.host.badssl.com/"));
172173
auto requestTask = client.request(methods::GET);
173174
VERIFY_THROWS(requestTask.get(), http_exception);
174175
});
@@ -180,7 +181,7 @@ TEST(server_cert_expired)
180181
{
181182
http_client_config config;
182183
config.set_timeout(std::chrono::seconds(1));
183-
http_client client(U("https://tv.eurosport.com/"), config);
184+
http_client client(U("https://expired.badssl.com/"), config);
184185
auto requestTask = client.request(methods::GET);
185186
VERIFY_THROWS(requestTask.get(), http_exception);
186187
});

Release/tests/functional/http/utilities/include/http_asserts.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class http_asserts
202202
#define HTTP_ERROR_CHECK_IMPL(__code) VERIFY_ARE_EQUAL(static_cast<int>(__code), _exc.error_code().default_error_condition().value());
203203
#endif
204204
#else
205-
#define HTTP_ERROR_CHECK_IMPL(__code) if(__code != _exc.error_code()) { VERIFY_IS_TRUE(false, "Unexpected error code encountered."); }
205+
#define HTTP_ERROR_CHECK_IMPL(__code) VERIFY_ARE_EQUAL(_exc.error_code(), __code, "Unexpected error code encountered.")
206206
#endif
207207

208208

@@ -212,17 +212,20 @@ class http_asserts
212212
try \
213213
{ \
214214
__expression; \
215-
VERIFY_IS_TRUE(false, "Expected http_exception not thrown"); \
215+
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"web::http::http_exception\" not thrown"); \
216216
} \
217217
catch (const web::http::http_exception& _exc) \
218218
{ \
219219
VERIFY_IS_TRUE(std::string(_exc.what()).size() > 0); \
220220
HTTP_ERROR_CHECK_IMPL(__code); \
221-
} \
222-
catch(...) \
223-
{ \
224-
VERIFY_IS_TRUE(false, "Exception other than http_exception thrown"); \
225-
} \
221+
} catch(const std::exception & _exc) { \
222+
std::string _msg("(" #__expression ") threw exception: "); \
223+
_msg.append(_exc.what()); \
224+
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), _msg.c_str()); \
225+
} catch (...) { \
226+
std::string _msg("(" #__expression ") threw exception: <...>"); \
227+
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), _msg.c_str()); \
228+
} \
226229
UNITTEST_MULTILINE_MACRO_END
227230

228231
}}}}

Release/tests/functional/websockets/client/authentication_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ void handshake_error_test_impl(const ::utility::string_t &host)
219219

220220
TEST(self_signed_cert)
221221
{
222-
handshake_error_test_impl(U("wss://www.pcwebshop.co.uk/"));
222+
handshake_error_test_impl(U("wss://self-signed.badssl.com/"));
223223
}
224224

225225
TEST(hostname_mismatch)
226226
{
227-
handshake_error_test_impl(U("wss://jabbr.net"));
227+
handshake_error_test_impl(U("wss://wrong.host.badssl.com/"));
228228
}
229229

230230
TEST(cert_expired)
231231
{
232-
handshake_error_test_impl(U("wss://tv.eurosport.com/"));
232+
handshake_error_test_impl(U("wss://expired.badssl.com/"));
233233
}
234234

235235
#endif

0 commit comments

Comments
 (0)