Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function open_unix_socket to check the type of filename argument #1399

Merged
merged 3 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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