Browse Source

helpers.is_port_open must return False on bad ip

Rodja Trappe 2 năm trước cách đây
mục cha
commit
4a4d75da73
2 tập tin đã thay đổi với 6 bổ sung0 xóa
  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