(backend) fix test suites relying on boto3

In a5b2c2d0bc, we mocked `socket.getaddrinfo`
module but this one is also used by boto3 under the hood, so the mock brokes
all tests using boto3.
This commit is contained in:
jbpenrath
2026-04-20 14:58:49 +02:00
parent 9a44d2cf69
commit 7a0f6fba80
3 changed files with 15 additions and 15 deletions

View File

@@ -2,7 +2,6 @@
# pylint: disable=redefined-outer-name, unused-argument, no-value-for-parameter, too-many-lines
import datetime
import socket
from unittest.mock import patch
from django.core.files.storage import storages
@@ -27,14 +26,14 @@ def _mock_ssrf_dns():
The IMAP endpoint validates the server hostname via
``core.services.ssrf.validate_hostname``; tests use unresolvable fixtures
like ``imap.example.com`` so we return a public IP to reach the mocked
IMAP task code.
like ``imap.example.com`` so we bypass validation to reach the mocked IMAP
task code. We patch the symbol imported into
``core.services.importer.imap`` rather than ``socket.getaddrinfo``, which
would also break real DNS lookups (e.g. boto3 reaching the S3 bucket).
"""
with patch(
"core.services.ssrf.socket.getaddrinfo",
return_value=[
(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", 0))
],
"core.services.importer.imap.validate_hostname",
return_value=["93.184.216.34"],
):
yield

View File

@@ -1,6 +1,5 @@
"""Shared fixtures for importer tests."""
import socket
from unittest import mock
import pytest
@@ -11,14 +10,14 @@ def _mock_ssrf_dns():
"""Short-circuit SSRF DNS validation for IMAP tests.
The IMAP import path validates the server hostname via
``core.services.ssrf.validate_hostname`` which calls ``socket.getaddrinfo``.
Test fixtures use unresolvable hostnames like ``imap.example.com``, so we
return a valid public IP here to let tests reach the mocked IMAP code.
``core.services.ssrf.validate_hostname``. Test fixtures use unresolvable
hostnames like ``imap.example.com``, so we bypass validation here to let
tests reach the mocked IMAP code. We patch the symbol imported into
``core.services.importer.imap`` rather than ``socket.getaddrinfo``, which
would also break real DNS lookups (e.g. boto3 reaching the S3 bucket).
"""
with mock.patch(
"core.services.ssrf.socket.getaddrinfo",
return_value=[
(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", 0))
],
"core.services.importer.imap.validate_hostname",
return_value=["93.184.216.34"],
):
yield

View File

@@ -1239,6 +1239,8 @@ class Test(Base):
# Add a test encryption key for django-fernet-encrypted-fields
SALT_KEY = ["test-salt-for-development-only"]
FEATURE_MAILBOX_ADMIN_CHANNELS = ["api_key", "widget"]
SCHEMA_CUSTOM_ATTRIBUTES_USER = {}
SCHEMA_CUSTOM_ATTRIBUTES_MAILDOMAIN = {}