Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

Tests fail on Python 3.12: `ssl.wrap_socket` removed

Open kwei-zhang opened this issue 9 months ago • 5 comments

Two tests fail on Python 3.12 because they patch ssl.wrap_socket, which was removed in Python 3.12:

  • tests/core/lib/test_ssl.py::TestSslMethod::test_create_tcp_socket
  • tests/core/lib/test_socket.py::TestSocketMethod::test_create_tcp_socket

Error message:

AttributeError: <module 'ssl' from '.../python3.12/ssl.py'> does not have the attribute 'wrap_socket'

I believe this is mainly because Python 3.12 removed the deprecated ssl.wrap_socket() API (deprecated since 3.7).

Environment: Python 3.12.8 Project supports Python 3.10–3.12 per pyproject.toml (python = "^3.10, <3.13") and docs

kwei-zhang avatar Feb 23 '26 01:02 kwei-zhang

I will try to fix this issue with recommanded ssl.SSLContext

kwei-zhang avatar Feb 23 '26 02:02 kwei-zhang

Hi @kwei-zhang , I would like to work on this issue if it is not already in progress. Please let me know if I can proceed.

yashasvi290906 avatar Feb 23 '26 15:02 yashasvi290906

Hi @yashasvi290906 , I would like to mention that the best way to learn and contribute to this project is to use this tool and then try to contribute in aspects which could have been better as per your experience .

Aarush289 avatar Feb 23 '26 15:02 Aarush289

I’ve gone through this issue and understand the problem related to ssl.wrap_socket removal in Python 3.12. I would like to work on fixing this by updating the tests for compatibility.

Sunuz-078 avatar Feb 24 '26 06:02 Sunuz-078

Hello! I'am a GSoC 2026 participant and posting my first ever comment on an open source issue and after brief thought and investigation here i am posting for this issue.

Investigation Process:

  1. cloned the repo and reproduced the issue locally on my machine using python 3.12.3 running on WSL2 (Ubuntu 24.04) and confirmed the issues mentioned previously by fellow contributors given below :

-tests/core/lib/test_ssl.py::TestSslMethod::test_create_tcp_socket -tests/core/lib/test_socket.py::TestSocketMethod::test_create_tcp_socket

2.Traced the root cause through the codebase:

-nettacker/core/lib/socket.py:29 → ssl.wrap_socket() -nettacker/core/lib/ssl.py:120 → ssl.wrap_socket()

3.Researched the Python 3.12 changelog and Stack Overflow to understand the removal:

  • Deprecated since Python 3.7
  • Fully removed in Python 3.12 due to CWE-295 (Improper Certificate Validation)
  • Modern replacement: ssl.SSLContext().wrap_socket() as previously mentioned by the contributors above.
  1. While Searching existing issues i found related issue #1190 covering the same root cause.

  2. Found PR #1177 which addresses both the main code and test mocks. Local test results after applying PR #1177's changes on WSL2 (Ubuntu 24.04, Python 3.12.3): make test:

    • Before: 285 passed, 2 failed ❌
    • After: 287 passed, 0 failed ✅

Conclusion:

PR #1177 fully resolves this issue. However, I noticed it currently has some failing CI checks that may need attention before it is ready to merge.

Could maintainers update PR #1177 to also reference Fixes #1302 so this issue gets automatically closed on merge?

Happy to participate. I Hope this resolves the issue.

hemant795 avatar Mar 22 '26 21:03 hemant795