From 32091915927893cb22ce144ff40cb7e1e18265e9 Mon Sep 17 00:00:00 2001 From: Anton Fetisov <a.fetisov@picodata.io> Date: Thu, 6 Feb 2025 14:20:06 +0300 Subject: [PATCH] test: specify explicit non-numeric hosts in tests All-numeric domains are now considered invalid, since they introduce confusion: one can assume that an all-numeric domain is a port, and the server should bind to `localhost` with that port. The specific change to domain parsing happens in a future commit. This commit fixes the tests in preparation for it. Note that all-numeric top-level domains are considered invalid according to RFC 952 and RFC 1123. In fact, the top-level domain label must be alphabetic, but we do not place that restriction, since local domains could have arbitrary format. --- src/address.rs | 20 ++++++-------------- src/config.rs | 10 +++++----- test/int/test_cli_connect.py | 12 ++++++------ test/int/test_expelling.py | 2 +- test/int/test_uninitialized.py | 2 +- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/address.rs b/src/address.rs index 5914231d7f..04b8cc06e2 100644 --- a/src/address.rs +++ b/src/address.rs @@ -302,21 +302,13 @@ mod tests { // assert_eq!( - "1234".parse(), + "test1234".parse(), Ok(IprotoAddress { user: None, - host: "1234".into(), + host: "test1234".into(), port: "3301".into() }) ); - assert_eq!( - ":1234".parse(), - Ok(IprotoAddress { - user: None, - host: "127.0.0.1".into(), - port: "1234".into() - }) - ); assert_eq!( "example".parse(), Ok(IprotoAddress { @@ -351,20 +343,20 @@ mod tests { ); assert_eq!( - "user@host:port".parse(), + "user@host:4321".parse(), Ok(IprotoAddress { user: Some("user".into()), host: "host".into(), - port: "port".into() + port: "4321".into() }) ); assert_eq!( - "user@:port".parse(), + "user@127.0.0.1:4321".parse(), Ok(IprotoAddress { user: Some("user".into()), host: "127.0.0.1".into(), - port: "port".into() + port: "4321".into() }) ); diff --git a/src/config.rs b/src/config.rs index 11731d32d3..f2866b01bc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2114,12 +2114,12 @@ instance: let yaml = r###" instance: - iproto_listen: kevin-> :spacey # <- some more trailing space + iproto_listen: kevin-> :4000 # <- some more trailing space "###; let config = PicodataConfig::read_yaml_contents(&yaml.trim_start()).unwrap(); let listen = config.instance.iproto_listen.unwrap(); assert_eq!(listen.host, "kevin-> "); - assert_eq!(listen.port, "spacey"); + assert_eq!(listen.port, "4000"); let yaml = r###" instance: @@ -2317,7 +2317,7 @@ instance: // command line > env let config = setup_for_tests(Some(yaml), &["run", "--peer", "one:1", - "--peer", "two:2, <- same problem here,:3,4" + "--peer", "two:2, <- same problem here,localhost:3,test4" ]).unwrap(); assert_eq!( @@ -2340,12 +2340,12 @@ instance: }, IprotoAddress { user: None, - host: "127.0.0.1".into(), + host: "localhost".into(), port: "3".into(), }, IprotoAddress { user: None, - host: "4".into(), + host: "test4".into(), port: "3301".into(), } ] diff --git a/test/int/test_cli_connect.py b/test/int/test_cli_connect.py index 3a945614d4..bb8e6e8423 100644 --- a/test/int/test_cli_connect.py +++ b/test/int/test_cli_connect.py @@ -259,7 +259,7 @@ def test_connect_auth_type_ldap(cluster: Cluster, ldap_server: LdapServer): def test_connect_auth_type_unknown(binary_path_fixt: str): cli = pexpect.spawn( command=binary_path_fixt, - args=["connect", ":0", "-u", "testuser", "-a", "deadbeef"], + args=["connect", "localhost:0", "-u", "testuser", "-a", "deadbeef"], env={"NO_COLOR": "1"}, encoding="utf-8", timeout=CLI_TIMEOUT, @@ -420,7 +420,7 @@ def test_connect_unix_ok_via_default_sock(cluster: Cluster): def test_connect_with_empty_password_path(binary_path_fixt: str): cli = pexpect.spawn( command=binary_path_fixt, - args=["connect", ":3301", "--password-file", "", "-u", "trash"], + args=["connect", "localhost:3301", "--password-file", "", "-u", "trash"], env={"NO_COLOR": "1"}, encoding="utf-8", timeout=CLI_TIMEOUT, @@ -439,7 +439,7 @@ def test_connect_with_wrong_password_path(binary_path_fixt: str): command=binary_path_fixt, args=[ "connect", - ":3301", + "localhost:3301", "--password-file", "/not/existing/path", "-u", @@ -609,7 +609,7 @@ def test_connect_timeout(cluster: Cluster): # * many others that depend on your/CI network settings and # which we don't want to list here - cli = connect_to("100") + cli = connect_to("invalid") cli.expect_exact("Connection Error. Try to reconnect") cli.expect_exact(pexpect.EOF) @@ -617,11 +617,11 @@ def test_connect_timeout(cluster: Cluster): cli.expect_exact("Connection Error. Try to reconnect") cli.expect_exact(pexpect.EOF) - cli = connect_to("1000010002") + cli = connect_to("test") cli.expect_exact("Connection Error. Try to reconnect") cli.expect_exact(pexpect.EOF) - cli = connect_to("1000010002", timeout=CLI_TIMEOUT) + cli = connect_to("test", timeout=CLI_TIMEOUT) cli.expect_exact("Connection Error. Try to reconnect") cli.expect_exact(pexpect.EOF) diff --git a/test/int/test_expelling.py b/test/int/test_expelling.py index 01435fc136..90726ab683 100644 --- a/test/int/test_expelling.py +++ b/test/int/test_expelling.py @@ -172,7 +172,7 @@ def test_expel_timeout(cluster: Cluster): "expel", "random_instance_name", f"--timeout={CLI_TIMEOUT}", - "--peer=10001", + "--peer=invalid", ], encoding="utf-8", timeout=CLI_TIMEOUT, diff --git a/test/int/test_uninitialized.py b/test/int/test_uninitialized.py index 6f3cb12011..861b2c8598 100644 --- a/test/int/test_uninitialized.py +++ b/test/int/test_uninitialized.py @@ -17,7 +17,7 @@ def uninitialized_instance(cluster: Cluster) -> Generator[Instance, None, None]: """Returns a running instance that is stuck in discovery phase.""" # Connecting TCP/0 always results in "Connection refused" - instance = cluster.add_instance(peers=[":0"], wait_online=False) + instance = cluster.add_instance(peers=["localhost:0"], wait_online=False) instance.start() def check_running(instance): -- GitLab