|
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 |
@@ -199,6 +200,24 @@ def socket_setdefaulttimeout(timeout): |
199 | 200 | socket.setdefaulttimeout(old_timeout) |
200 | 201 |
|
201 | 202 |
|
| 203 | +@contextlib.contextmanager |
| 204 | +def downgrade_malformed_data_warning(): |
| 205 | + # This warning happens on macos and win, but does not always happen on linux. |
| 206 | + if sys.platform not in {"win32", "darwin"}: |
| 207 | + yield |
| 208 | + return |
| 209 | + |
| 210 | + with warnings.catch_warnings(): |
| 211 | + # TODO: gh-110012, we should investigate why this warning is happening |
| 212 | + # and fix it properly. |
| 213 | + warnings.filterwarnings( |
| 214 | + action="always", |
| 215 | + message=r"received malformed or improperly-truncated ancillary data", |
| 216 | + category=RuntimeWarning, |
| 217 | + ) |
| 218 | + yield |
| 219 | + |
| 220 | + |
202 | 221 | HAVE_SOCKET_CAN = _have_socket_can() |
203 | 222 |
|
204 | 223 | HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp() |
@@ -3941,8 +3960,9 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0): |
3941 | 3960 | # mindata and maxdata bytes when received with buffer size |
3942 | 3961 | # ancbuf, and that any complete file descriptor numbers are |
3943 | 3962 | # valid. |
3944 | | - msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
3945 | | - len(MSG), ancbuf) |
| 3963 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 3964 | + msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
| 3965 | + len(MSG), ancbuf) |
3946 | 3966 | self.assertEqual(msg, MSG) |
3947 | 3967 | self.checkRecvmsgAddress(addr, self.cli_addr) |
3948 | 3968 | self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) |
@@ -4293,8 +4313,9 @@ def testSingleCmsgTruncInData(self): |
4293 | 4313 | self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
4294 | 4314 | socket.IPV6_RECVHOPLIMIT, 1) |
4295 | 4315 | self.misc_event.set() |
4296 | | - msg, ancdata, flags, addr = self.doRecvmsg( |
4297 | | - self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) |
| 4316 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 4317 | + msg, ancdata, flags, addr = self.doRecvmsg( |
| 4318 | + self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) |
4298 | 4319 |
|
4299 | 4320 | self.assertEqual(msg, MSG) |
4300 | 4321 | self.checkRecvmsgAddress(addr, self.cli_addr) |
@@ -4397,9 +4418,10 @@ def testSecondCmsgTruncInData(self): |
4397 | 4418 | self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
4398 | 4419 | socket.IPV6_RECVTCLASS, 1) |
4399 | 4420 | self.misc_event.set() |
4400 | | - msg, ancdata, flags, addr = self.doRecvmsg( |
4401 | | - self.serv_sock, len(MSG), |
4402 | | - socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) |
| 4421 | + with downgrade_malformed_data_warning(): # TODO: gh-110012 |
| 4422 | + msg, ancdata, flags, addr = self.doRecvmsg( |
| 4423 | + self.serv_sock, len(MSG), |
| 4424 | + socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) |
4403 | 4425 |
|
4404 | 4426 | self.assertEqual(msg, MSG) |
4405 | 4427 | self.checkRecvmsgAddress(addr, self.cli_addr) |
|
0 commit comments