qa: Verify HTTP listen port exclusivity

This commit is contained in:
Hodlinator
2026-09-04 21:52:48 +02:00
parent af65069fd1
commit bcb09b3f4a

View File

@@ -134,6 +134,7 @@ class HTTPBasicsTest (BitcoinTestFramework):
self.node.reuse_http_connections = False
self.check_default_connection()
self.check_socket_exclusivity()
self.check_keepalive_connection()
self.check_close_connection()
self.check_excessive_request_size()
@@ -173,6 +174,18 @@ class HTTPBasicsTest (BitcoinTestFramework):
assert conn.sock_closed()
def check_socket_exclusivity(self):
self.log.info("Checking that another process cannot bind the HTTP listen port")
url = urllib.parse.urlparse(self.node.url)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as competing_listener:
competing_listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# Ill-configured sockets permit port reuse unless the original
# listener requested exclusive address use.
assert_raises(
OSError,
lambda: competing_listener.bind((url.hostname, url.port)))
def check_keepalive_connection(self):
self.log.info("Checking keep-alive connection persistence")
conn = BitcoinHTTPConnection(self.node)