diff --git a/src/openjd/adaptor_runtime/_http/sockets.py b/src/openjd/adaptor_runtime/_http/sockets.py index 7f821f8..01454d0 100644 --- a/src/openjd/adaptor_runtime/_http/sockets.py +++ b/src/openjd/adaptor_runtime/_http/sockets.py @@ -112,7 +112,7 @@ def gen_socket_path(dir: str, base_name: str): return os.path.join(dir, name) if not base_dir: - socket_dir = tempfile.gettempdir() + socket_dir = os.path.realpath(tempfile.gettempdir()) # Check that the sticky bit is set on the temp dir if not os.stat(socket_dir).st_mode & stat.S_ISVTX: raise NoSocketPathFoundException( @@ -120,7 +120,7 @@ def gen_socket_path(dir: str, base_name: str): "sticky bit (restricted deletion flag) set" ) else: - socket_dir = base_dir + socket_dir = os.path.realpath(base_dir) if namespace: socket_dir = os.path.join(socket_dir, namespace) diff --git a/test/openjd/adaptor_runtime/conftest.py b/test/openjd/adaptor_runtime/conftest.py index 83e282a..642d94a 100644 --- a/test/openjd/adaptor_runtime/conftest.py +++ b/test/openjd/adaptor_runtime/conftest.py @@ -1,12 +1,15 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. import platform +import random +import string from typing import Generator +from unittest.mock import MagicMock, patch -from openjd.adaptor_runtime._osname import OSName -import string -import random import pytest +from openjd.adaptor_runtime._osname import OSName +from openjd.adaptor_runtime._http import sockets + if OSName.is_windows(): import win32net import win32netcon @@ -92,3 +95,13 @@ def delete_user() -> None: yield username, password # Delete the user after test completes delete_user() + + +@pytest.fixture(scope="session", autouse=OSName().is_macos()) +def mock_sockets_py_tempfile_gettempdir_to_slash_tmp() -> Generator[MagicMock, None, None]: + """ + Mock that is automatically used on Mac to override the tempfile.gettempdir() usages in sockets.py + because the folder returned by it on Mac is too long for the socket name to fit (max 104 bytes, see sockets.py) + """ + with patch.object(sockets.tempfile, "gettempdir", return_value="/tmp") as m: + yield m diff --git a/test/openjd/adaptor_runtime/unit/http/test_sockets.py b/test/openjd/adaptor_runtime/unit/http/test_sockets.py index 23632c3..1157145 100644 --- a/test/openjd/adaptor_runtime/unit/http/test_sockets.py +++ b/test/openjd/adaptor_runtime/unit/http/test_sockets.py @@ -193,7 +193,7 @@ def test_handles_socket_name_collisions( # THEN assert result.endswith(expected_sock_name) - mock_exists.call_count == len(existing_sock_names) + 1 + assert mock_exists.call_count == (len(existing_sock_names) + 1) class TestLinuxSocketPaths: