summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] bpo-37013: Fix the error handling in socket.if_indextoname() ↵Miss Islington (bot)2023-12-251-0/+13
| | | | | | | | | (GH-13503) (GH-112598) * 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>
* [3.11] bpo-35191: Fix unexpected integer truncation in socket.setblocking() ↵Alexey Izbyshev2023-12-011-2/+2
| | | | | | | | | (GH-10415) On platforms with 64-bit long, socket.setblocking(x) treated all x which lower 32 bits are zero as False due to integer truncation. Reported by ubsan.
* [3.11] gh-76106: Remove the cleanup lock in test_socket (GH-110539) (GH-110700)Miss Islington (bot)2023-10-111-24/+2
| | | | | | | It does not already work (because it locks only addCleanup(), not doCleanups()), and it is no longer needed since the clean up procedure waits for all test threads to join. (cherry picked from commit f27b83090701b9c215e0d65f1f924fb9330cb649) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-110167: Fix test_socket deadlock in doCleanups() (GH-110416) (#110424)Miss Islington (bot)2023-10-051-5/+7
| | | | | | | | | | | | | | | | | | gh-110167: Fix test_socket deadlock in doCleanups() (GH-110416) Fix a deadlock in test_socket when server fails with a timeout but the client is still running in its thread. Don't hold a lock to call cleanup functions in doCleanups(). One of the cleanup function waits until the client completes, whereas the client could deadlock if it called addCleanup() in such situation. doCleanups() is called when the server completed, but the client can still be running in its thread especially if the server failed with a timeout. Don't put a lock on doCleanups() to prevent deadlock between addCleanup() called in the client and doCleanups() waiting for self.done.wait of ThreadableTest._setUp(). (cherry picked from commit 318f5df27109ff8d2519edefa771920a0ec62b92) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.11] gh-110391: socket NetworkConnectionAttributesTest always declare cli ↵Miss Islington (bot)2023-10-051-1/+3
| | | | | | | | | | | (GH-110401) (#110406) gh-110391: socket NetworkConnectionAttributesTest always declare cli (GH-110401) NetworkConnectionAttributesTest of test_socket now always declare the 'cli' attribute, so clientTearDown() cannot fail with AttributeError. (cherry picked from commit e37d4557c3de0476e76ca4b8a1cc8d2566b86c79) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.11] gh-109396: Fix test_socket.test_hmac_sha1() in FIPS mode (GH-109423) ↵Miss Islington (bot)2023-09-141-3/+7
| | | | | | | | | | | (#109427) gh-109396: Fix test_socket.test_hmac_sha1() in FIPS mode (GH-109423) 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) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.11] gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016) ↵Victor Stinner2023-09-071-0/+2
| | | | | | | | | | (#109042) gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016) Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP blackhole is enabled (net.inet.tcp.blackhole=2). (cherry picked from commit a52a3509770f29f940cda9307704908949912276)
* gh-100374: Fixed a bug in socket.getfqdn() (gh-100375)Miss Islington (bot)2022-12-211-0/+4
| | | | | (cherry picked from commit 12be23cf3c1301be2c6b8fd4cb2cd35a567d2ea2) Co-authored-by: Dominic Socular <BBH@awsl.rip>
* gh-95243: Mitigate the race condition in testSockName (GH-96173)Miss Islington (bot)2022-08-251-2/+13
| | | | | | | | | | | find_unused_port() has an inherent race condition, but we can't use bind_port() as that uses .getsockname() which this test is exercising. Try binding to unused ports a few times before failing. Signed-off-by: Ross Burton <ross.burton@arm.com> (cherry picked from commit df110126971d0271a977ce10779083b3e335b4da) Co-authored-by: Ross Burton <ross.burton@arm.com>
* [3.11] gh-95174: WASI: skip missing sockets functions (GH-95179) (GH-95308)Christian Heimes2022-07-311-0/+13
| | | | Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-94821: Fix autobind of empty unix domain address (GH-94826)Miss Islington (bot)2022-07-171-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>
* Remove the execution bit to some socket-related files. (GH-93368)Miss Islington (bot)2022-06-011-0/+0
| | | | | (cherry picked from commit 5247389369ac3da35c44f7c0d8f4facc0300883a) Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
* bpo-45046: Support context managers in unittest (GH-28045)Miss Islington (bot)2022-05-081-3/+1
| | | | | | | | Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext(). (cherry picked from commit 086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-74166: Add option to get all errors from socket.create_connection (GH-91586)Irit Katriel2022-04-181-0/+18
|
* bpo-40280: Skip socket, fork, subprocess tests on Emscripten (GH-31986)Christian Heimes2022-03-221-0/+2
| | | | | | | | | | | - Add requires_fork and requires_subprocess to more tests - Skip extension import tests if dlopen is not available - Don't assume that _testcapi is a shared extension - Skip a lot of socket tests that don't work on Emscripten - Skip mmap tests, mmap emulation is incomplete - venv does not work yet - Cannot get libc from executable The "entire" test suite is now passing on Emscripten with EMSDK from git head (91 suites are skipped).
* bpo-40066: [Enum] fix tests (GH-30643)Ethan Furman2022-01-171-8/+8
| | | | | - skip doctest that changes depending on target system - skip doctest that only fails on CI - substitute in values that change depending on target system
* bpo-40066: [Enum] skip failing doc test (GH-30637)Kumar Aditya2022-01-171-4/+8
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-171-8/+4
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-161-4/+8
| | | | | | | | | | | | | | | Undo rejected PEP-663 changes: - restore `repr()` to its 3.10 status - restore `str()` to its 3.10 status New changes: - `IntEnum` and `IntFlag` now leave `__str__` as the original `int.__str__` so that str() and format() return the same result - zero-valued flags without a name have a slightly changed repr(), e.g. `repr(Color(0)) == '<Color: 0>'` - update `dir()` for mixed-in types to return all the methods and attributes of the mixed-in type - added `_numeric_repr_` to `Flag` to control display of unnamed values - enums without doc strings have a more comprehensive doc string added - `ReprEnum` added -- inheriting from this makes it so only `__repr__` is replaced, not `__str__` nor `__format__`; `IntEnum`, `IntFlag`, and `StrEnum` all inherit from `ReprEnum`
* Add a comment about how to fix bogus test_host_resolution_bad_address ↵Barry Warsaw2021-10-201-2/+4
| | | | failures (#29085)
* bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest ↵Serhiy Storchaka2021-09-171-9/+3
| | | | (GH-28422)
* bpo-45212: Add a comment for time.sleep() in tests (GH-28414)Serhiy Storchaka2021-09-171-0/+1
| | | | Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-45187: Collect test_socket tests using unittest (GH-28317)Serhiy Storchaka2021-09-171-79/+5
| | | | | Previously, test classes ISOTPTest, J1939Test, BasicUDPLITETest and UDPLITETimeoutTest were not included in the list of tests and were not run by regrtest.
* bpo-45212: Fix dangling threads in skipped tests in test_socket (GH-28361)Serhiy Storchaka2021-09-161-11/+8
| | | | | | tearDown() is not called if setUp() raises an exception (including SkipTest). addCleanup() should be used for guaranteed execution of the cleanup code.
* bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005)Serhiy Storchaka2021-08-291-0/+1
|
* bpo-34932: Add socket.TCP_KEEPALIVE for macOS (GH-25079)Shane Harvey2021-07-141-0/+7
|
* bpo-40297: Fix test_socket.CANTest.testSendFrame (GH-19548)karl ding2021-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.
* bpo-43651: PEP 597: Fix `socket.makefile()` (GH-25645)Inada Naoki2021-04-271-3/+4
|
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: * `_simple_enum` decorator to transform a normal class into an enum * `_test_simple_enum` function to compare * `_old_convert_` to enable checking `_convert_` generated enums `_simple_enum` takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 `_old_convert_` works much like` _convert_` does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) `_test_simple_enum` takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)Ethan Furman2021-04-201-35/+0
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: _simple_enum decorator to transform a normal class into an enum _test_simple_enum function to compare _old_convert_ to enable checking _convert_ generated enums _simple_enum takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 _old_convert_ works much like _convert_ does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) test_simple_enum takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* bpo-40066: Enum: modify `repr()` and `str()` (GH-22392)Ethan Furman2021-03-311-4/+4
| | | | | | | | | * Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
* bpo-42393: Raise OverflowError iso. DeprecationWarning on overflow in ↵Erlend Egeberg Aasland2020-12-311-6/+5
| | | | socket.ntohs and socket.htons (GH-23980)
* skip test_getaddrinfo_ipv6_scopeid_symbolic and ↵pxinwr2020-11-281-0/+2
| | | | test_getnameinfo_ipv6_scopeid_symbolic on VxWorks (GH-23518)
* bpo-42413: socket.timeout is now an alias of TimeoutError (GH-23413)Christian Heimes2020-11-201-17/+19
| | | Signed-off-by: Christian Heimes <christian@python.org>
* bpo-42172: Correct typo for test_socket.py (GH-23013)Akashkumar D Khunt2020-10-301-3/+3
|
* bpo-40275: Use new test.support helper submodules in tests (GH-21317)Hai Shi2020-07-061-28/+29
|
* bpo-40275: Adding threading_helper submodule in test.support (GH-20263)Hai Shi2020-05-271-3/+4
|
* bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)Serhiy Storchaka2020-05-261-4/+2
| | | | Only __index__ should be used to make integer conversions lossless.
* 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>