Skip to content
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
3 changes: 3 additions & 0 deletions node_cli/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
19 changes: 19 additions & 0 deletions tests/utils/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

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
Loading