mirror of https://github.com/scrapy/scrapy.git
Validate reversed telnet console port ranges (#7593)
This commit is contained in:
parent
2d0a898e2d
commit
ba28630c98
|
|
@ -33,6 +33,8 @@ def listen_tcp(portrange: list[int], host: str, factory: ServerFactory) -> Port:
|
|||
|
||||
if len(portrange) > 2:
|
||||
raise ValueError(f"invalid portrange: {portrange}")
|
||||
if len(portrange) == 2 and portrange[0] > portrange[1]:
|
||||
raise ValueError(f"invalid portrange: {portrange}")
|
||||
if not portrange:
|
||||
return reactor.listenTCP(0, factory, interface=host) # type: ignore[no-any-return]
|
||||
if len(portrange) == 1:
|
||||
|
|
|
|||
|
|
@ -53,3 +53,9 @@ class TestTelnetExtension:
|
|||
d = portal.login(creds, None, ITelnetProtocol)
|
||||
yield d
|
||||
console.stop_listening()
|
||||
|
||||
def test_invalid_reversed_portrange(self):
|
||||
settings = {"TELNETCONSOLE_PORT": [2, 1]}
|
||||
console = TelnetConsole(get_crawler(settings_dict=settings))
|
||||
with pytest.raises(ValueError, match=r"invalid portrange: \[2, 1\]"):
|
||||
console.start_listening()
|
||||
|
|
|
|||
Loading…
Reference in New Issue