Skip to content

Commit

Permalink
Merge pull request #1399 from lewoudar/open-unix-socket-fix
Browse files Browse the repository at this point in the history
Update function open_unix_socket to check the type of filename argument
  • Loading branch information
pquentin authored Feb 12, 2020
2 parents edd4d80 + e8659ac commit 84694d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 1 addition & 4 deletions trio/_highlevel_open_unix_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ async def open_unix_socket(filename,):
if not has_unix:
raise RuntimeError("Unix sockets are not supported on this platform")

if filename is None:
raise ValueError("Filename cannot be None")

# much more simplified logic vs tcp sockets - one socket type and only one
# possible location to connect to
sock = socket(AF_UNIX, SOCK_STREAM)
with close_on_error(sock):
await sock.connect(filename)
await sock.connect(trio._util.fspath(filename))

return trio.SocketStream(sock)
6 changes: 6 additions & 0 deletions trio/tests/test_highlevel_open_unix_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def close(self):
assert c.closed


@pytest.mark.parametrize('filename', [4, 4.5])
async def test_open_with_bad_filename_type(filename):
with pytest.raises(TypeError):
await open_unix_socket(filename)


async def test_open_bad_socket():
# mktemp is marked as insecure, but that's okay, we don't want the file to
# exist
Expand Down

0 comments on commit 84694d9

Please sign in to comment.