From 8f1d1c8524e69276b57d50f894d1c15d19655530 Mon Sep 17 00:00:00 2001 From: Dmytro Tkachuk Date: Tue, 10 Nov 2026 13:21:53 +0000 Subject: [PATCH] Reject endpoints that are not http or https --- node_cli/utils/settings.py | 3 +++ tests/utils/settings_test.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/node_cli/utils/settings.py b/node_cli/utils/settings.py index 77a39427..f9f704bf 100644 --- a/node_cli/utils/settings.py +++ b/node_cli/utils/settings.py @@ -35,6 +35,7 @@ ) from node_cli.configs import INTERNAL_SETTINGS_PATH, NODE_SETTINGS_PATH, SKALE_DIR +from node_cli.utils.helper import error_exit from node_cli.utils.node_type import NodeMode, NodeType InternalSettings.model_config['toml_file'] = INTERNAL_SETTINGS_PATH @@ -58,6 +59,8 @@ def validate_and_save_node_settings( ) -> BaseNodeSettings: data = load_config_file(config_filepath) settings_type = SETTINGS_MAP[(node_type.value, node_mode.value)] + if settings_type.model_validate(data).endpoint.scheme not in ('http', 'https'): + error_exit('Endpoint must be an http or https URL') write_node_settings_file(path=NODE_SETTINGS_PATH, settings_type=settings_type, data=data) return settings_type() diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index e7b3f4be..f50752e0 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -17,3 +17,22 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import pytest + +from node_cli.configs import NODE_SETTINGS_PATH +from node_cli.utils.node_type import NodeMode, NodeType +from node_cli.utils.settings import validate_and_save_node_settings + + +@pytest.mark.parametrize('endpoint', ['ws://localhost:8545', 'wss://localhost:8545']) +def test_validate_and_save_node_settings_non_http_endpoint(regular_user_conf, endpoint, capsys): + regular_user_conf.write_text( + regular_user_conf.read_text().replace('http://localhost:8545', endpoint) + ) + node_settings = NODE_SETTINGS_PATH.read_bytes() + with pytest.raises(SystemExit): + validate_and_save_node_settings( + regular_user_conf.as_posix(), NodeType.SKALE, NodeMode.ACTIVE + ) + assert 'Endpoint must be an http or https URL' in capsys.readouterr().out + assert NODE_SETTINGS_PATH.read_bytes() == node_settings