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

tests: fix ipv4 override test #175

Merged
merged 2 commits into from
Mar 14, 2024
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
1 change: 1 addition & 0 deletions src/aioftp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ftp client/server for asyncio"""

# flake8: noqa

import importlib.metadata
Expand Down
1 change: 1 addition & 0 deletions src/aioftp/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Simple aioftp-based server with one user (anonymous or not)"""

import argparse
import asyncio
import contextlib
Expand Down
24 changes: 14 additions & 10 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,37 @@ async def test_pasv_connection_port_reused(


@pytest.mark.asyncio
async def test_pasv_connection_pasv_forced_response_address(
pair_factory,
Server,
unused_tcp_port,
):
async def test_pasv_connection_pasv_forced_response_address(pair_factory, Server):
def ipv4_used():
try:
ipaddress.IPv4Address(pair.host)
return True
except ValueError:
return False

# using TEST-NET-1 address
ipv4_address = "192.0.2.1"
async with pair_factory(
server=Server(ipv4_pasv_forced_response_address="127.0.0.2"),
server=Server(ipv4_pasv_forced_response_address=ipv4_address),
) as pair:
assert pair.server.ipv4_pasv_forced_response_address == "127.0.0.2"
assert pair.server.ipv4_pasv_forced_response_address == ipv4_address

if ipv4_used():
# The connection fails here because the server starts to listen for
# The connection should fail here because the server starts to listen for
# the passive connections on the host (IPv4 address) that is used
# by the control channel. In reality, if the server is behind NAT,
# the server is reached with the defined external IPv4 address,
# i.e. we can check that the connection to
# pair.server.ipv4_pasv_forced_response_address failed to know that
# the server returned correct external IP
with pytest.raises(OSError):
await pair.client.get_passive_connection(commands=["pasv"])
# ...
# but we can't use check like this:
# with pytest.raises(OSError):
# await pair.client.get_passive_connection(commands=["pasv"])
# because there is no such ipv4 which will be non-routable, so
# we can only check `PASV` response
ip, _ = await pair.client._do_pasv()
assert ip == ipv4_address

# With epsv the connection should open as that does not use the
# external IPv4 address but just tells the client the port to connect
Expand Down
Loading