diff --git a/setup.py b/setup.py index bb97a94..83a6ae8 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def stamp_api_version(): setup( name="science-synapse", - version="2.8.3", + version="2.8.4", description="Client library and CLI for the Synapse API", author="Science Team", author_email="team@science.xyz", diff --git a/synapse/cli/__main__.py b/synapse/cli/__main__.py index 99554aa..01236f8 100755 --- a/synapse/cli/__main__.py +++ b/synapse/cli/__main__.py @@ -38,7 +38,8 @@ def setup_device_uri(args): if not args.uri: # User doesn't want to use something that needs a uri return args - if not is_valid_ip(args.uri): + # Device accepts ip:port, so only the host part decides name vs address. + if not (is_valid_ip(args.uri) or is_valid_ip(args.uri.rsplit(":", 1)[0])): # User passed in a name console = Console() device_ip = find_device_by_name(args.uri, console, False, 60) diff --git a/synapse/tests/cli/test_uri.py b/synapse/tests/cli/test_uri.py new file mode 100644 index 0000000..f37219c --- /dev/null +++ b/synapse/tests/cli/test_uri.py @@ -0,0 +1,21 @@ +import importlib.util +from argparse import Namespace +from pathlib import Path + +import synapse.cli + +# conftest.py stubs synapse.cli.__main__, so load the real file under another name. +_spec = importlib.util.spec_from_file_location( + "synapse_cli_main_for_test", Path(synapse.cli.__file__).with_name("__main__.py") +) +cli_main = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(cli_main) + + +def test_ip_with_port_skips_name_lookup(monkeypatch): + def fail(*a, **k): + raise AssertionError("name lookup should not run") + + monkeypatch.setattr(cli_main, "find_device_by_name", fail) + for uri in ["127.0.0.1", "127.0.0.1:50051", "::1"]: + assert cli_main.setup_device_uri(Namespace(uri=uri)).uri == uri