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

Function test_grpc_request_validation

tests/test_cln_rs.py:181–342  ·  view source on GitHub ↗

Malformed gRPC request values must be rejected, not panic the server.

(node_factory)

Source from the content-addressed store, hash-verified

179
180
181def test_grpc_request_validation(node_factory):
182 """Malformed gRPC request values must be rejected, not panic the server."""
183 l1 = node_factory.get_node()
184 wait_for_grpc_start(l1)
185 stub = l1.grpc
186
187 valid_pubkey = bytes.fromhex(l1.info["id"])
188 valid_hash = b"\x00" * 32
189
190 cases = [
191 (
192 "pubkey",
193 lambda: stub.ListPeers(clnpb.ListpeersRequest(id=b"\x00" * 33)),
194 "id",
195 ),
196 (
197 "u16_overflow",
198 lambda: stub.ConnectPeer(clnpb.ConnectRequest(id="x", port=65536)),
199 "port",
200 ),
201 ("enum", lambda: stub.ListPeers(clnpb.ListpeersRequest(level=9999)), "level"),
202 (
203 "hash",
204 lambda: stub.ListPays(clnpb.ListpaysRequest(payment_hash=b"\x00" * 31)),
205 "payment_hash",
206 ),
207 (
208 "secret",
209 lambda: stub.SendPay(
210 clnpb.SendpayRequest(
211 payment_hash=valid_hash, payment_secret=b"\x00" * 31
212 )
213 ),
214 "payment_secret",
215 ),
216 (
217 "short_channel_id",
218 lambda: stub.ListChannels(
219 clnpb.ListchannelsRequest(short_channel_id="not-a-scid")
220 ),
221 "short_channel_id",
222 ),
223 (
224 "short_channel_id_dir",
225 lambda: stub.AskReneBiasChannel(
226 clnpb.AskrenebiaschannelRequest(
227 layer="x", bias=1, short_channel_id_dir="not-a-scid"
228 )
229 ),
230 "short_channel_id_dir",
231 ),
232 (
233 "missing_required",
234 lambda: stub.Withdraw(clnpb.WithdrawRequest(destination="bcrt1qtest")),
235 "satoshi",
236 ),
237 (
238 "array_pubkey",

Callers

nothing calls this directly

Calls 15

wait_for_grpc_startFunction · 0.85
is_in_logMethod · 0.80
get_nodeMethod · 0.45
ListPeersMethod · 0.45
ConnectPeerMethod · 0.45
ListPaysMethod · 0.45
SendPayMethod · 0.45
ListChannelsMethod · 0.45
AskReneBiasChannelMethod · 0.45
WithdrawMethod · 0.45
SendOnionMethod · 0.45
TxPrepareMethod · 0.45

Tested by

no test coverage detected