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

Function test_dynamic_path_rune

tests/test_clnrest.py:805–886  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

803
804
805def test_dynamic_path_rune(node_factory):
806 l1, base_url, ca_cert = start_node_with_clnrest(
807 node_factory, os.path.join(os.getcwd(), "tests/plugins/dynamic_clnrest_path.py")
808 )
809
810 with pytest.raises(RpcError, match="rune_required must be true for anything but GET requests"):
811 l1.rpc.call(
812 "clnrest-register-path",
813 {
814 "path": r"v1/keys/{keyset_id}",
815 "rpc_method": "normal-route",
816 "http_method": "PATCH",
817 "rune_required": False,
818 },
819 )
820
821 http_session = http_session_with_retry()
822
823 dynamic_res = http_session.post(base_url + "/test/no/rune_restrictions", verify=ca_cert)
824 assert dynamic_res.status_code == 403
825 assert dynamic_res.json()["code"] == 1501
826 assert dynamic_res.json()["message"] == "Not authorized: Missing rune"
827
828 rune = l1.rpc.createrune()["rune"]
829 dynamic_res = http_session.post(
830 base_url + "/test/no/rune_restrictions", headers={"Rune": rune}, verify=ca_cert
831 )
832 dynamic_res.raise_for_status()
833 dynamic_json = dynamic_res.json()
834 assert dynamic_json["test-dynamic-clnrest"] == "success"
835
836 dynamic_res = http_session.get(base_url + "/test/no/rune_required", verify=ca_cert)
837 dynamic_res.raise_for_status()
838 dynamic_json = dynamic_res.json()
839 assert dynamic_json["test-dynamic-clnrest"] == "success"
840
841 rune = l1.rpc.createrune(
842 restrictions=[
843 ["id=0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518"]
844 ]
845 )["rune"]
846
847 dynamic_res = http_session.post(
848 base_url + "/invalid/nodeid", headers={"Rune": rune}, verify=ca_cert
849 )
850 assert dynamic_res.status_code == 401
851 assert dynamic_res.json()["code"] == 1502
852 assert (
853 dynamic_res.json()["message"]
854 == "Not permitted: id is not equal to 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518"
855 )
856
857 rune = l1.rpc.createrune(
858 restrictions=[
859 ["id=035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d"]
860 ]
861 )["rune"]
862

Callers

nothing calls this directly

Calls 6

start_node_with_clnrestFunction · 0.85
http_session_with_retryFunction · 0.85
joinMethod · 0.80
jsonMethod · 0.80
callMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected