OWASP / OWASP/Nettacker

test: `test_ssl.py` and `test_socket.py` fail under Python 3.12 due to `ssl.wrap_socket` deprecation

Open
#1,747 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
1.2k
Avg merge
1d 21h
Merged PRs (30d)
16

Description

Environment Information
  • OS: Linux (Ubuntu 24.04 LTS)
  • Python Version: 3.12.3
  • Test Suite Result: 354 passed, 2 failed, 6 skipped, 2 xfailed in 33.99s
Description

When running poetry run pytest on Python 3.12.3, the test suite encounters 2 unit test failures in tests/unit/core/lib/test_ssl.py and tests/unit/core/lib/test_socket.py.

Failure Traceback

The 2 failing tests fail during mock setup with an AttributeError:

1. tests/unit/core/lib/test_ssl.py::TestSslMethod::test_create_tcp_socket

FAILED tests/unit/core/lib/test_ssl.py::TestSslMethod::test_create_tcp_socket - AttributeError: <module 'ssl' from '/usr/lib/python3.12/ssl.py'> does not have the attribute 'wrap_socket'

2. tests/unit/core/lib/test_socket.py::TestSocketMethod::test_create_tcp_socket

FAILED tests/unit/core/lib/test_socket.py::TestSocketMethod::test_create_tcp_socket - AttributeError: <module 'ssl' from '/usr/lib/python3.12/ssl.py'> does not have the attribute 'wrap_socket'
Root Cause

Both affected unit tests attempt to patch @patch("ssl.wrap_socket"). In Python 3.12, ssl.wrap_socket() was permanently removed from standard library ssl, causing @patch("ssl.wrap_socket") to raise an AttributeError before the test function executes.

Proposed Solution

The unit test mock patches in test_ssl.py and test_socket.py (and corresponding helper logic in nettacker/core/lib/ssl.py) need to be updated to use Python 3.12 compatible SSLContext.wrap_socket.

I have reproduced this issue locally and verified all 354 passing tests. I would like to be assigned to this issue to prepare a clean PR with passing tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/unit/core/lib/test_ssl.py and tests/unit/core/lib/test_socket.py, focusing on the failing TestSslMethod::test_create_tcp_socket and TestSocketMethod::test_create_tcp_socket cases. Then inspect nettacker/core/lib/ssl.py and run the affected tests under Python 3.12. Done means the mocks and helper logic work with the available SSL API and the full pytest suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
security, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.