From 384ad456ae5b65919bb004c1622ec7d0fb8c3903 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 21 Mar 2022 10:44:46 -0700 Subject: [PATCH 1/3] add wifi min length check --- meshtastic/__main__.py | 4 ++++ meshtastic/tests/test_main.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index a4d704d..2b27df3 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -119,6 +119,10 @@ def setPref(attributes, name, valStr): val = meshtastic.util.fromStr(valStr) logging.debug(f'valStr:{valStr} val:{val}') + if snake_name == 'wifi_password' and len(valStr) < 8: + print(f"Warning: wifi_password must be 8 or more characters.") + return + enumType = field.enum_type # pylint: disable=C0123 if enumType and type(val) == str: diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 58d1721..8298f5e 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -902,6 +902,27 @@ def test_main_set_valid_wifi_passwd(capsys): mo.assert_called() +@pytest.mark.unit +@pytest.mark.usefixtures("reset_globals") +def test_main_set_invalid_wifi_passwd(capsys): + """Test --set with an invalid value (password must be 8 or more characters)""" + sys.argv = ['', '--set', 'wifi_password', '1234567'] + Globals.getInstance().set_args(sys.argv) + + mocked_node = MagicMock(autospec=Node) + + iface = MagicMock(autospec=SerialInterface) + iface.getNode.return_value = mocked_node + + with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo: + main() + out, err = capsys.readouterr() + assert re.search(r'Connected to radio', out, re.MULTILINE) + assert not re.search(r'Set wifi_password to 1234567', out, re.MULTILINE) + assert re.search(r'Warning: wifi_password must be 8 or more characters.', out, re.MULTILINE) + assert err == '' + mo.assert_called() + @pytest.mark.unit @pytest.mark.usefixtures("reset_globals") def test_main_set_valid_camel_case(capsys): From 5761c89818392d5a705a2f7e920c59d972b5ff00 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 21 Mar 2022 17:49:55 +0000 Subject: [PATCH 2/3] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c8468ab..bd6a9fc 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md", "r") as fh: # This call to setup() does all the work setup( name="meshtastic", - version="1.2.92", + version="1.2.93", description="Python API & client shell for talking to Meshtastic devices", long_description=long_description, long_description_content_type="text/markdown", From 5ac9867a91b2efda0a6e62e6d43eb7c1a597d642 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 27 Apr 2022 18:37:44 +0000 Subject: [PATCH 3/3] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bd6a9fc..03e59a4 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md", "r") as fh: # This call to setup() does all the work setup( name="meshtastic", - version="1.2.93", + version="1.2.94", description="Python API & client shell for talking to Meshtastic devices", long_description=long_description, long_description_content_type="text/markdown",