summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.9] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-129171) (GH-129440) ↵Miss Islington (bot)2025-02-191-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#130075) Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host address or the "any" address, use the local communication address (loopback): VMADDR_CID_LOCAL. On Linux 6.9, apparently, the /dev/vsock device is now available but get_cid() returns VMADDR_CID_ANY (-1). (cherry picked from commit 45db419c3104a14007ea9efbc4bff03aef8ed10c) (cherry picked from commit e94dbe4ed83460f18bd72563c5f09f6cdc71f604) (cherry picked from commit c750061047ee520d8299334df4b112fd983d7e48) (cherry picked from commit cbfe3023e46b544b80ea1a38a8c900c6fb881554) --- Restore the skipUnless removed by GH-119465. This test can only pass on virtual machines, not actual machines. Actual machines see: ``` self.cli.connect((cid, VSOCKPORT)) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ OSError: [Errno 19] No such device ``` Reproduced on (Linux) Ubuntu 24.04.1 running 6.8.0-52-generic. (cherry picked from commit 2bd9f9b0547f6ffe40cd1dd964459ce11b58144d) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* [3.9] gh-109396: Fix test_socket.test_hmac_sha1() in FIPS mode (GH-109423) ↵Miss Islington (bot)2024-11-041-3/+7
| | | | | | | | | | | | (GH-125107) Use a longer key: FIPS mode requires at least of at least 112 bits. The previous key was only 32 bits. (cherry picked from commit e091b9f20fa8e409003af79f3c468b8225e6dcd3) (cherry picked from commit f7bfac4b3dd30920f97a542fd78c355ce62aa267) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* [3.9] gh-122133: Rework pure Python socketpair tests to avoid use of ↵Miss Islington (bot)2024-08-021-14/+6
| | | | | | | | importlib.reload. (GH-122493) (GH-122508) (cherry picked from commit f071f01b7b7e19d7d6b3a4b0ec62f820ecb14660) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* [3.9] gh-122133: Authenticate socket connection for `socket.socketpair()` ↵Miss Islington (bot)2024-07-301-3/+125
| | | | | | | | | | fallback (GH-122134) (#122428) Authenticate socket connection for `socket.socketpair()` fallback when the platform does not have a native `socketpair` C API. We authenticate in-process using `getsocketname` and `getpeername` (thanks to Nathaniel J Smith for that suggestion). (cherry picked from commit 78df1043dbdce5c989600616f9f87b4ee72944e5) Co-authored-by: Seth Michael Larson <seth@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* [3.9] bpo-37013: Fix the error handling in socket.if_indextoname() ↵Miss Islington (bot)2024-01-171-0/+13
| | | | | | | | | (GH-13503) (GH-112600) * Fix a crash when pass UINT_MAX. * Fix an integer overflow on 64-bit non-Windows platforms. (cherry picked from commit 0daf555c6fb3feba77989382135a58215e1d70a5) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* gh-94821: Fix autobind of empty unix domain address (GH-94826) (GH-94875)Miss Islington (bot)2022-07-261-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When binding a unix socket to an empty address on Linux, the socket is automatically bound to an available address in the abstract namespace. >>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) >>> s.bind("") >>> s.getsockname() b'\x0075499' Since python 3.9, the socket is bound to the one address: >>> s.getsockname() b'\x00' And trying to bind multiple sockets will fail with: Traceback (most recent call last): File "/home/nsoffer/src/cpython/Lib/test/test_socket.py", line 5553, in testAutobind s2.bind("") OSError: [Errno 98] Address already in use Added 2 tests: - Auto binding empty address on Linux - Failing to bind an empty address on other platforms Fixes f6b3a07b7df6 (bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866) (cherry picked from commit c22f134211743cd5ad14cec1dd4f527bee542b4c) Co-authored-by: Nir Soffer <nsoffer@redhat.com>
* bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest ↵Miss Islington (bot)2021-09-171-9/+3
| | | | | | | | (GH-28422) (GH-28424) (cherry picked from commit 51ebb7f4f5e9bdcf8279a1d91be9569706f6bead) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.9] bpo-45187: Collect test_socket tests using unittest (GH-28317) (GH-28413)Łukasz Langa2021-09-171-78/+5
| | | | | | | | | Previously, test classes ISOTPTest, J1939Test, BasicUDPLITETest and UDPLITETimeoutTest were not included in the list of tests and were not run by regrtest.. (cherry picked from commit 0361335b80b435ca3694981b41f8269e390eb892) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.9] bpo-45212: Fix dangling threads in skipped tests in test_socket ↵Serhiy Storchaka2021-09-171-11/+8
| | | | | | | | | (GH-28361) (GH-28408) tearDown() is not called if setUp() raises an exception (including SkipTest). addCleanup() should be used for guaranteed execution of the cleanup code. (cherry picked from commit 7dacb70485a0910eb298c24b4d051720ca56fb91)
* [3.9] bpo-25130: Add calls of gc.collect() in tests to support PyPy ↵Serhiy Storchaka2021-08-291-0/+1
| | | | | | (GH-28005). (GH-28028) (cherry picked from commit 2a8127cafe1d196f858a3ecabf5f1df3eebf9a12)
* bpo-40297: Fix test_socket.CANTest.testSendFrame (GH-19548)Miss Islington (bot)2021-05-041-2/+1
| | | | | | | | | | | | | The address tuple for CAN_RAW no longer returns the address family after the introduction of CAN ISO-TP support in a30f6d45ac3. However, updating test_socket.CANTest.testSendFrame was missed as part of the change, so the test incorrectly attempts to index past the last tuple item to retrieve the address family. This removes the now-redundant check for equality against socket.AF_CAN, as the tuple will not contain the address family. (cherry picked from commit 355bae88822bee4de6092b63d69c5a5dad393a16) Co-authored-by: karl ding <karlding@users.noreply.github.com>
* bpo-35569: Expose RFC 3542 IPv6 socket options on macOS (GH-19526)Erlend Egeberg Aasland2020-05-171-0/+31
|
* bpo-40291: Add support for CAN_J1939 sockets (GH-19538)karl ding2020-04-291-0/+74
| | | | Add support for CAN_J1939 sockets that wrap SAE J1939 protocol functionality provided by Linux 5.4+ kernels.
* bpo-40275: Move transient_internet from test.support to socket_helper (GH-19711)Serhiy Storchaka2020-04-291-1/+1
|
* bpo-40275: Avoid importing socket in test.support (GH-19603)Serhiy Storchaka2020-04-251-57/+58
| | | | | | * Move socket related functions from test.support to socket_helper. * Import socket, nntplib and urllib.error lazily in transient_internet(). * Remove importing multiprocess.
* Handle when IOCTL_VM_SOCKETS_GET_LOCAL_CID does not exist in "socket" (GH-19270)Pablo Galindo2020-04-011-0/+2
| | | | | | | Running `test_socket` or anything that depends on it (like python -m test.pythoninfo) crashes if IOCTL_VM_SOCKETS_GET_LOCAL_CID does not exist in the socket module. Automerge-Triggered-By: @pablogsal
* bpo-38614: Use support timeout constants (GH-17572)masterVictor Stinner2019-12-111-6/+14
|
* bpo-38614: Add timeout constants to test.support (GH-16964)Victor Stinner2019-10-301-9/+7
| | | | | | | | Add timeout constants to test.support: * LOOPBACK_TIMEOUT * INTERNET_TIMEOUT * SHORT_TIMEOUT * LONG_TIMEOUT
* closes bpo-37405: Make socket.getsockname() always return a tuple for ↵bggardner2019-09-121-1/+3
| | | | | AF_CAN. (GH-14392) This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.
* bpo-28724: Add methods send_fds and recv_fds to the socket module (GH-12889)Joannah Nanjekye2019-09-111-1/+44
| | | | | | | The socket module now has the socket.send_fds() and socket.recv.fds() functions. Contributed by Joannah Nanjekye, Shinya Okano (original patch) and Victor Stinner. Co-Authored-By: Victor Stinner <vstinner@redhat.com>
* bpo-15999: Always pass bool instead of int to socket.setblocking(). (GH-15621)Serhiy Storchaka2019-09-011-5/+5
|
* bpo-36590: Add Bluetooth RFCOMM and support for Windows. (GH-12767)Greg Bowser2019-08-021-0/+55
| | | | | | | | | | | Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros being defined. Winsock only supports RFCOMM, even though it has a BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not necessarily work. This also adds some basic unittests for constants (all of which existed prior to this commit, just not on windows) and creating sockets. pair: Nate Duarte <slacknate@gmail.com>
* bpo-37085: Expose SocketCAN bcm_msg_head flags (#13646)karl ding2019-07-311-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | Expose the CAN_BCM SocketCAN constants used in the bcm_msg_head struct flags (provided by <linux/can/bcm.h>) under the socket library. This adds the following constants with a CAN_BCM prefix: * SETTIMER * STARTTIMER * TX_COUNTEVT * TX_ANNOUNCE * TX_CP_CAN_ID * RX_FILTER_ID * RX_CHECK_DLC * RX_NO_AUTOTIMER * RX_ANNOUNCE_RESUME * TX_RESET_MULTI_IDX * RX_RTR_FRAME * CAN_FD_FRAME The CAN_FD_FRAME flag was introduced in the 4.8 kernel, while the other ones were present since SocketCAN drivers were mainlined in 2.6.25. As such, it is probably unnecessary to guard against these constants being missing.
* bpo-37553: SendfileUsingSendTest tests timeout too short for Windows ARM32 ↵Paul Monson2019-07-141-1/+2
| | | | (GH-14716)
* bpo-37199: Fix test failures when IPv6 is unavailable or disabled (#14480)Zackery Spytz2019-06-301-1/+8
|
* bpo-37345: Add formal UDPLITE support (GH-14258)Gabe Appleton2019-06-241-0/+183
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment you can definitely use UDPLITE sockets on Linux systems, but it would be good if this support were formalized such that you can detect support at runtime easily. At the moment, to make and use a UDPLITE socket requires something like the following code: ``` >>> import socket >>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136) >>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136) >>> a.bind(('localhost', 44444)) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 16) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 32) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 64) >>> b.sendto(b'test'*256, ('localhost', 44444)) ``` If you look at this through Wireshark, you can see that the packets are different in that the checksums and checksum coverages change. With the pull request that I am submitting momentarily, you could do the following code instead: ``` >>> import socket >>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE) >>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE) >>> a.bind(('localhost', 44444)) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(16) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(32) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(64) >>> b.sendto(b'test'*256, ('localhost', 44444)) ``` One can also detect support for UDPLITE just by checking ``` >>> hasattr(socket, 'IPPROTO_UDPLITE') ``` https://bugs.python.org/issue37345
* bpo-37007: Implement socket.if_nametoindex(), if_indextoname() and ↵Zackery Spytz2019-05-291-13/+11
| | | | if_nameindex() on Windows (GH-13522)
* bpo-36341: Fix tests calling bind() on AF_UNIX sockets (GH-12399)xdegaye2019-05-031-2/+7
| | | | | | | Those tests may fail with PermissionError. https://bugs.python.org/issue36341
* bpo-36629: Add support.get_socket_conn_refused_errs() (GH-12834)Victor Stinner2019-04-151-8/+1
| | | | Fix test_imap4_host_default_value() of test_imaplib: catch also errno.ENETUNREACH error.
* bpo-35934: Add socket.create_server() utility function (GH-11784)Giampaolo Rodola2019-04-081-1/+125
|
* bpo-29515: add missing socket.IPPROTO_* constants on Windows (GH-12183)Giampaolo Rodola2019-03-281-0/+19
|
* bpo-22831: Use "with" to avoid possible fd leaks in tests (part 1). (GH-10928)Serhiy Storchaka2019-03-051-24/+19
|
* bpo-36123: Fix test_socket.testWithTimeoutTriggeredSend() race condition ↵Joannah Nanjekye2019-02-261-2/+3
| | | | | | (GH-12053) Use longer timeout for accept() in the server and block on accept in the client. The client now only sets the timeout once the socket is connected.
* Make sure file object is close if socket.create_connection fails (GH-11334)Pablo Galindo2018-12-291-5/+4
| | | The problem affects _testWithTimeoutTriggeredSend in test_socket.py.
* bpo-11192: Skip unsupported cases in test_socket on AIX (GH-8954)Michael Felt2018-12-261-9/+15
| | | | | | * use platform.system() as runtime test, rather than sys.platform() build-time test * IPv6 zone id support on AIX is limited to inet_pton6_zone(), so skip related getaddrinfo() and getnameinfo() tests as not supported
* bpo-35415: validate fileno argument to socket.socket (GH-10917)Dima Tisnek2018-12-171-5/+44
| | | https://bugs.python.org/issue35415
* bpo-35050: AF_ALG length check off-by-one error (GH-10058)Christian Heimes2018-12-101-0/+18
| | | | | | | | The length check for AF_ALG salg_name and salg_type had a off-by-one error. The code assumed that both values are not necessarily NULL terminated. However the Kernel code for alg_bind() ensures that the last byte of both strings are NULL terminated. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-35347: Cleanup test_socket.NonBlockingTCPTests (GH-10818)Victor Stinner2018-11-301-89/+74
| | | | | | | | | | | | | | | | * Replace testInheritFlags() with two tests: testInheritFlagsBlocking() and testInheritFlagsTimeout() to test different default socket timeout. Moreover, the test now checks sock.gettimeout() rather than a functional test on recv(). * Replace time.time() with time.monotonic() * Add socket_setdefaulttimeout() context manager to restore the default timeout when the test completes. * Remove testConnect(): accept() wasn't blocking and testAccept() already tests non-blocking accept(). * Remove accept() functional test from testInitNonBlocking(): already tested by testAccept() * Rewrite testSetBlocking() with a new assert_sock_timeout() method * Use addCleanup() and context manager to close sockets * Replace assertTrue(x < y) with assertLess(x, y)
* bpo-35347: Fix test_socket.NonBlockingTCPTests (GH-10791)Victor Stinner2018-11-301-25/+39
| | | | | | | | | | | | | | | testAccept() and testRecv() of test_socket.NonBlockingTCPTests have a race condition: time.sleep() is used as a weak synchronization primitive and the tests fail randomly on slow buildbots. Use a reliable threading.Event to fix these tests. Other changes: * Replace send() with sendall() * Expect specific BlockingIOError rather than generic OSError * Add a timeout to select() in testAccept() and testRecv() * Use addCleanup() to close sockets * Use assertRaises()
* Fix tests in test_socket to use correctly CMSG_LEN (GH-9594)Pablo Galindo2018-09-271-2/+3
| | | | | | | | | | | | | After some failures in AMD64 FreeBSD CURRENT Debug 3.x buildbots regarding tests in test_socket that are using testFDPassSeparateMinSpace(), FreeBDS revision 337423 was pointed out to be the reason the test started to fail. A close examination of the manpage for cmsg_space(3) reveals that the number of file descriptors needs to be taken into account when using CMSG_LEN(). This commit fixes tests in test_socket to use correctly CMSG_LEN, taking into account the number of FDs.
* bpo-31425: Expose AF_QIPCRTR in socket module (GH-3706)Bjorn Andersson2018-09-261-0/+41
| | | | | | The AF_QIPCRTR address family was introduced in Linux v4.7. Co-authored-by: Bjorn Andersson <bjorn.andersson@linaro.org>
* bpo-33937: Catch ENOMEM error in test_socket (#9557)Victor Stinner2018-09-251-2/+13
| | | | | Fix test_socket.SendmsgSCTPStreamTest: catch ENOMEM error. testSendmsgTimeout() and testSendmsgDontWait() randomly fail on Travis CI with: "OSError: [Errno 12] Cannot allocate memory".
* bpo-34587, test_socket: remove RDSTest.testCongestion() (GH-9277)Victor Stinner2018-09-171-27/+0
| | | | | | | | | The test tries to fill the receiver's socket buffer and expects an error. But the RDS protocol doesn't require that. Moreover, the Linux implementation of RDS expects that the producer of the messages reduces its rate, it's not the role of the receiver to trigger an error. The test fails on Fedora 28 by design, so remove it.
* Fixed several assertTrue() that were intended to be assertEqual(). (GH-8191)Sergey Fedoseev2018-07-091-1/+1
| | | Fixed also testing the "always" warning filter.
* Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" (GH-7919)Victor Stinner2018-06-261-1/+1
| | | This reverts commit 8fbbdf0c3107c3052659e166f73990b466eacbb0.
* bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)Victor Stinner2018-06-221-1/+1
| | | | | | | | * Add support.MS_WINDOWS: True if Python is running on Microsoft Windows. * Add support.MACOS: True if Python is running on Apple macOS. * Replace support.is_android with support.ANDROID * Replace support.is_jython with support.JYTHON * Cleanup code to initialize unix_shell
* Provide a little better debug output (#6940)Barry Warsaw2018-05-171-1/+1
|
* Spelling fixes to docs, docstrings, and comments (GH-6374)Ville Skyttä2018-04-201-1/+1
|
* bpo-32394: Remove some TCP options on old version Windows. (GH-5523)animalize2018-02-261-0/+22
|
* bpo-32221: makeipaddr(): remove interface part + speedup (GH-5449) (#5449)Коренберг Марк2018-02-121-0/+66
|