Skip to content

Commit 4c3d6ca

Browse files
committed
Fix: windows' failing tests
1 parent 9cd89c5 commit 4c3d6ca

File tree

3 files changed

+42
-56
lines changed

3 files changed

+42
-56
lines changed

lib/mysqlx/connection.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import logging
4040
import uuid
4141
import platform
42+
import os
4243

4344
from functools import wraps
4445

@@ -172,13 +173,27 @@ def set_ssl(self, ssl_mode, ssl_ca, ssl_crl, ssl_cert, ssl_key):
172173

173174
self._socket = context.wrap_socket(self._socket)
174175
if ssl_mode == SSLMode.VERIFY_IDENTITY:
175-
try:
176-
hostname = socket.gethostbyaddr(self._host)
177-
ssl.match_hostname(self._socket.getpeercert(), hostname[0])
178-
except ssl.CertificateError as err:
176+
hostnames = []
177+
# Windows does not return loopback aliases on gethostbyaddr
178+
if os.name == 'nt' and (self._host == 'localhost' or \
179+
self._host == '127.0.0.1'):
180+
hostnames = ['localhost', '127.0.0.1']
181+
aliases = socket.gethostbyaddr(self._host)
182+
hostnames.extend([aliases[0]] + aliases[1])
183+
match_found = False
184+
errs = []
185+
for hostname in hostnames:
186+
try:
187+
ssl.match_hostname(self._socket.getpeercert(), hostname)
188+
except ssl.CertificateError as err:
189+
errs.append(err)
190+
else:
191+
match_found = True
192+
break
193+
if not match_found:
179194
self.close()
180195
raise InterfaceError("Unable to verify server identity: {}"
181-
"".format(err))
196+
"".format(", ".join(errs)))
182197
self._is_ssl = True
183198

184199
def is_ssl(self):

tests/test_bugs.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,16 +1795,11 @@ def test_load_csv(self):
17951795
cur.execute(sql, (self.data_file,))
17961796
cur.execute("SELECT * FROM local_data")
17971797

1798-
if os.name != 'nt':
1799-
exp = [
1800-
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1801-
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1802-
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
1803-
else:
1804-
exp = [
1805-
(1, 'c1_1', 'c2_1\r'), (2, 'c1_2', 'c2_2\r'),
1806-
(3, 'c1_3', 'c2_3\r'), (4, 'c1_4', 'c2_4\r'),
1807-
(5, 'c1_5', 'c2_5\r'), (6, 'c1_6', 'c2_6')]
1798+
exp = [
1799+
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1800+
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1801+
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
1802+
18081803
self.assertEqual(exp, cur.fetchall())
18091804

18101805
@cnx_config(compress=True)
@@ -1816,16 +1811,10 @@ def test_load_csv_with_compress(self):
18161811
cur.execute(sql, (self.data_file,))
18171812
cur.execute("SELECT * FROM local_data")
18181813

1819-
if os.name != 'nt':
1820-
exp = [
1821-
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1822-
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1823-
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
1824-
else:
1825-
exp = [
1826-
(1, 'c1_1', 'c2_1\r'), (2, 'c1_2', 'c2_2\r'),
1827-
(3, 'c1_3', 'c2_3\r'), (4, 'c1_4', 'c2_4\r'),
1828-
(5, 'c1_5', 'c2_5\r'), (6, 'c1_6', 'c2_6')]
1814+
exp = [
1815+
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1816+
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1817+
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
18291818
self.assertEqual(exp, cur.fetchall())
18301819

18311820
@foreach_cnx()

tests/test_connection.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -297,27 +297,15 @@ def test__handle_result(self):
297297
'status_flag': 1, 'affected_rows': 6}
298298
self.assertEqual(exp, self.cnx._handle_result(packet))
299299

300-
if os.name != 'nt':
301-
exp = [
302-
bytearray(b'\x47\x00\x00\x04\x31\x09\x63\x31\x5f\x31\x09\x63\x32'
303-
b'\x5f\x31\x0a\x32\x09\x63\x31\x5f\x32\x09\x63\x32\x5f'
304-
b'\x32\x0a\x33\x09\x63\x31\x5f\x33\x09\x63\x32\x5f\x33'
305-
b'\x0a\x34\x09\x63\x31\x5f\x34\x09\x63\x32\x5f\x34\x0a'
306-
b'\x35\x09\x63\x31\x5f\x35\x09\x63\x32\x5f\x35\x0a\x36'
307-
b'\x09\x63\x31\x5f\x36\x09\x63\x32\x5f\x36'),
308-
bytearray(b'\x00\x00\x00\x05')
309-
]
310-
else:
311-
exp = [
312-
bytearray(b'\x4c\x00\x00\x04\x31\x09\x63\x31\x5f\x31\x09\x63'
313-
b'\x32\x5f\x31\x0d\x0a\x32\x09\x63\x31\x5f\x32\x09'
314-
b'\x63\x32\x5f\x32\x0d\x0a\x33\x09\x63\x31\x5f\x33'
315-
b'\x09\x63\x32\x5f\x33\x0d\x0a\x34\x09\x63\x31\x5f'
316-
b'\x34\x09\x63\x32\x5f\x34\x0d\x0a\x35\x09\x63\x31'
317-
b'\x5f\x35\x09\x63\x32\x5f\x35\x0d\x0a\x36\x09\x63'
318-
b'\x31\x5f\x36\x09\x63\x32\x5f\x36'),
319-
bytearray(b'\x00\x00\x00\x05')
320-
]
300+
exp = [
301+
bytearray(b'\x47\x00\x00\x04\x31\x09\x63\x31\x5f\x31\x09\x63\x32'
302+
b'\x5f\x31\x0a\x32\x09\x63\x31\x5f\x32\x09\x63\x32\x5f'
303+
b'\x32\x0a\x33\x09\x63\x31\x5f\x33\x09\x63\x32\x5f\x33'
304+
b'\x0a\x34\x09\x63\x31\x5f\x34\x09\x63\x32\x5f\x34\x0a'
305+
b'\x35\x09\x63\x31\x5f\x35\x09\x63\x32\x5f\x35\x0a\x36'
306+
b'\x09\x63\x31\x5f\x36\x09\x63\x32\x5f\x36'),
307+
bytearray(b'\x00\x00\x00\x05')
308+
]
321309
self.assertEqual(exp, self.cnx._socket.sock._client_sends)
322310

323311
# Column count is invalid ( more than 4096)
@@ -1788,16 +1776,10 @@ def test_load_local_infile(self):
17881776
self.cur.execute(sql, (self.data_file, ))
17891777
self.cur.execute("SELECT * FROM local_data")
17901778

1791-
if os.name != 'nt':
1792-
exp = [
1793-
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1794-
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1795-
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
1796-
else:
1797-
exp = [
1798-
(1, 'c1_1', 'c2_1\r'), (2, 'c1_2', 'c2_2\r'),
1799-
(3, 'c1_3', 'c2_3\r'), (4, 'c1_4', 'c2_4\r'),
1800-
(5, 'c1_5', 'c2_5\r'), (6, 'c1_6', 'c2_6')]
1779+
exp = [
1780+
(1, 'c1_1', 'c2_1'), (2, 'c1_2', 'c2_2'),
1781+
(3, 'c1_3', 'c2_3'), (4, 'c1_4', 'c2_4'),
1782+
(5, 'c1_5', 'c2_5'), (6, 'c1_6', 'c2_6')]
18011783
self.assertEqual(exp, self.cur.fetchall())
18021784

18031785
def test_without_load_local_infile(self):

0 commit comments

Comments
 (0)