浏览代码

helpers.is_port_open must return False on bad ip

Rodja Trappe 2 年之前
父节点
当前提交
4a4d75da73
共有 2 个文件被更改,包括 6 次插入0 次删除
  1. 2 0
      nicegui/helpers.py
  2. 4 0
      tests/test_helpers.py

+ 2 - 0
nicegui/helpers.py

@@ -46,6 +46,8 @@ def is_port_open(host: str, port: int) -> bool:
         sock.connect((host, port))
     except (ConnectionRefusedError, TimeoutError):
         return False
+    except Exception:
+        return False
     else:
         return True
     finally:

+ 4 - 0
tests/test_helpers.py

@@ -19,6 +19,10 @@ def test_is_port_open():
         assert helpers.is_port_open(host, port), 'after opening the socket, the port should be detected'
 
 
+def test_is_port_open_on_bad_ip():
+    assert not helpers.is_port_open('1.2', 0), 'should not be able to connect to a bad IP'
+
+
 def test_schedule_browser(monkeypatch):
 
     called_with_url = None