MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_websocket_upgrade_header

Function test_websocket_upgrade_header

tests/test_clnrest.py:494–533  ·  view source on GitHub ↗

Test that not setting an upgrade header leads to rejection

(node_factory)

Source from the content-addressed store, hash-verified

492
493
494def test_websocket_upgrade_header(node_factory):
495 """Test that not setting an upgrade header leads to rejection"""
496 # start a node with clnrest
497 l1, base_url, ca_cert = start_node_with_clnrest(node_factory)
498 http_session = http_session_with_retry()
499 http_session.verify = ca_cert.as_posix()
500
501 sio = socketio.Client(http_session=http_session)
502 notifications = []
503 connection_error_msg = None
504
505 @sio.event
506 def message(data):
507 notifications.append(data)
508
509 @sio.event
510 def connect_error(data):
511 nonlocal connection_error_msg
512 connection_error_msg = str(data)
513 try:
514 sio.connect(base_url)
515 except socketio.exceptions.ConnectionError as e:
516 error_str = connection_error_msg if connection_error_msg else str(e)
517 expect_error = "Missing rune"
518
519 if expect_error not in error_str:
520 raise ValueError(f"Expected error code `{expect_error}`, got `{error_str}` instead")
521 except Exception:
522 raise
523
524 time.sleep(2)
525 # trigger notification by calling method
526 rpc_method = 'invoice'
527 rpc_params = [100000, 'label', 'description']
528 rpc_call = getattr(l1.rpc, rpc_method)
529 rpc_call(*rpc_params)
530 time.sleep(2)
531 sio.disconnect()
532
533 assert len(notifications) == 0
534
535
536def test_accept_header_types(node_factory):

Callers

nothing calls this directly

Calls 4

start_node_with_clnrestFunction · 0.85
http_session_with_retryFunction · 0.85
connectMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected