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

Function test_websocket_upgrade_header

tests/test_clnrest.py:496–535  ·  view source on GitHub ↗

Test that not setting an upgrade header leads to rejection

(node_factory)

Source from the content-addressed store, hash-verified

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