|
1 | 1 | import unittest
|
| 2 | +import warnings |
2 | 3 | from test import support
|
3 | 4 | from test.support import (
|
4 |
| - is_apple, os_helper, refleak_helper, socket_helper, threading_helper |
| 5 | + is_apple, os_helper, refleak_helper, socket_helper, threading_helper, |
5 | 6 | )
|
6 | 7 | import _thread as thread
|
7 | 8 | import array
|
@@ -198,6 +199,24 @@ def socket_setdefaulttimeout(timeout):
|
198 | 199 | socket.setdefaulttimeout(old_timeout)
|
199 | 200 |
|
200 | 201 |
|
| 202 | +@contextlib.contextmanager |
| 203 | +def downgrade_malformed_data_warning(): |
| 204 | + # This warning happens on macos and win, but does not always happen on linux. |
| 205 | + if sys.platform not in {"win32", "darwin"}: |
| 206 | + yield |
| 207 | + return |
| 208 | + |
| 209 | + with warnings.catch_warnings(): |
| 210 | + # TODO: gh-110012, we should investigate why this warning is happening |
| 211 | + # and fix it properly. |
| 212 | + warnings.filterwarnings( |
| 213 | + action="always", |
| 214 | + message=r"received malformed or improperly-truncated ancillary data", |
| 215 | + category=RuntimeWarning, |
| 216 | + ) |
| 217 | + yield |
| 218 | + |
| 219 | + |
201 | 220 | HAVE_SOCKET_CAN = _have_socket_can()
|
202 | 221 |
|
203 | 222 | HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
|
@@ -3946,8 +3965,9 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
|
3946 | 3965 | # mindata and maxdata bytes when received with buffer size
|
3947 | 3966 | # ancbuf, and that any complete file descriptor numbers are
|
3948 | 3967 | # valid.
|
3949 |
| - msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
3950 |
| - len(MSG), ancbuf) |
| 3968 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 3969 | + msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
| 3970 | + len(MSG), ancbuf) |
3951 | 3971 | self.assertEqual(msg, MSG)
|
3952 | 3972 | self.checkRecvmsgAddress(addr, self.cli_addr)
|
3953 | 3973 | self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC)
|
@@ -4298,8 +4318,9 @@ def testSingleCmsgTruncInData(self):
|
4298 | 4318 | self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
|
4299 | 4319 | socket.IPV6_RECVHOPLIMIT, 1)
|
4300 | 4320 | self.misc_event.set()
|
4301 |
| - msg, ancdata, flags, addr = self.doRecvmsg( |
4302 |
| - self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) |
| 4321 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 4322 | + msg, ancdata, flags, addr = self.doRecvmsg( |
| 4323 | + self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) |
4303 | 4324 |
|
4304 | 4325 | self.assertEqual(msg, MSG)
|
4305 | 4326 | self.checkRecvmsgAddress(addr, self.cli_addr)
|
@@ -4402,9 +4423,10 @@ def testSecondCmsgTruncInData(self):
|
4402 | 4423 | self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
|
4403 | 4424 | socket.IPV6_RECVTCLASS, 1)
|
4404 | 4425 | self.misc_event.set()
|
4405 |
| - msg, ancdata, flags, addr = self.doRecvmsg( |
4406 |
| - self.serv_sock, len(MSG), |
4407 |
| - socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) |
| 4426 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 4427 | + msg, ancdata, flags, addr = self.doRecvmsg( |
| 4428 | + self.serv_sock, len(MSG), |
| 4429 | + socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) |
4408 | 4430 |
|
4409 | 4431 | self.assertEqual(msg, MSG)
|
4410 | 4432 | self.checkRecvmsgAddress(addr, self.cli_addr)
|
|
0 commit comments