Skip to content

Commit 1092c68

Browse files
committed
Merge branch 'copilot/fix-failing-github-actions-job' of github.com:mindflayer/python-mocket into copilot/fix-failing-github-actions-job
2 parents a667969 + 05ee3ff commit 1092c68

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

mocket/socket.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,13 @@ def recv(self, buffersize: int, flags: int | None = None) -> bytes:
621621
r_fd, _ = Mocket.get_pair(address)
622622
if r_fd and Mocket.pipe_uses_data(address):
623623
try:
624-
return os.read(r_fd, buffersize)
624+
pipe_data = os.read(r_fd, buffersize)
625625
except BlockingIOError:
626-
pass
626+
pipe_data = b""
627+
if pipe_data:
628+
# Keep in-memory buffer position in sync with bytes drained from the pipe.
629+
self.io.seek(self.io.tell() + len(pipe_data))
630+
return pipe_data
627631

628632
pending = Mocket.get_pending_readables(address)
629633
if r_fd and self._buffered_bytes() and pending == 0:

mocket/ssl/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def getpeercert(self, binary_form: bool = False) -> _PeerCertRetDictType:
8080
Returns:
8181
Mock certificate dictionary
8282
"""
83-
if not (self._host and self._port):
83+
if self._host is None or self._port is None:
8484
self._address = self._host, self._port = Mocket._address
8585

8686
now = datetime.now()

tests/test_socket.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ def test_wrap_bio_uses_current_mocket_address(
149149
assert ssl_obj._address == (expected_host, 443)
150150

151151

152+
def test_wrap_bio_preserves_empty_server_hostname_on_getpeercert(monkeypatch):
153+
monkeypatch.setattr(Mocket, "_address", ("httpbin.local", 443))
154+
ssl_obj = MocketSSLContext().wrap_bio(
155+
incoming=None,
156+
outgoing=None,
157+
server_hostname="",
158+
)
159+
160+
ssl_obj.getpeercert()
161+
162+
assert ssl_obj._host == ""
163+
assert ssl_obj._address == ("", 443)
164+
165+
152166
def test_recvfrom_into():
153167
sock = MocketSocket(socket.AF_INET, socket.SOCK_STREAM)
154168
test_data = b"abc123"

0 commit comments

Comments
 (0)