1
1
/* **
2
2
* ==++==
3
3
*
4
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
8
* http://www.apache.org/licenses/LICENSE-2.0
9
- *
9
+ *
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,7 +44,7 @@ void auth_helper(test_websocket_server& server, const utility::string_t &usernam
44
44
server.set_http_handler ([username, password](test_http_request request)
45
45
{
46
46
test_http_response resp;
47
- if (request->username ().empty ()) // No credentials -> challenge the request
47
+ if (request->username ().empty ()) // No credentials -> challenge the request
48
48
{
49
49
resp.set_status_code (401 ); // Unauthorized.
50
50
resp.set_realm (" My Realm" );
@@ -86,6 +86,19 @@ TEST_FIXTURE(uri_address, auth_with_credentials, "Ignore", "245")
86
86
}
87
87
#endif
88
88
89
+ // helper function to check if failure is due to timeout.
90
+ bool is_timeout (const std::string &msg)
91
+ {
92
+ if (msg.find (" set_fail_handler" ) != std::string::npos)
93
+ {
94
+ if (msg.find (" TLS handshake timed out" ) != std::string::npos || msg.find (" Timer Expired" ) != std::string::npos)
95
+ {
96
+ return true ;
97
+ }
98
+ }
99
+ return false ;
100
+ }
101
+
89
102
TEST (ssl_test)
90
103
{
91
104
websocket_client client;
@@ -112,15 +125,11 @@ TEST(ssl_test)
112
125
}
113
126
catch (const websocket_exception &e)
114
127
{
115
- const auto msg = std::string (e.what ());
116
- if (msg.find (" set_fail_handler" ) != std::string::npos)
128
+ if (is_timeout (e.what ())
117
129
{
118
- if (msg.find (" TLS handshake timed out" ) != std::string::npos || msg.find (" Timer Expired" ) != std::string::npos)
119
- {
120
- // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
121
- // especially on our build machines.
122
- return ;
123
- }
130
+ // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
131
+ // especially on our build machines.
132
+ return ;
124
133
}
125
134
throw ;
126
135
}
@@ -139,6 +148,12 @@ void handshake_error_test_impl(const ::utility::string_t &host)
139
148
}
140
149
catch (const websocket_exception &e)
141
150
{
151
+ if (is_timeout (e.what ()))
152
+ {
153
+ // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
154
+ // especially on our build machines.
155
+ return ;
156
+ }
142
157
VERIFY_ARE_EQUAL (" TLS handshake failed" , e.error_code ().message ());
143
158
}
144
159
}
0 commit comments