Test POST requests on `/v1/ ` end points with default values for options.
(node_factory)
| 183 | |
| 184 | |
| 185 | def test_rpc_method(node_factory): |
| 186 | """Test POST requests on `/v1/<rpc_method>` end points with default values for options.""" |
| 187 | # start a node with clnrest |
| 188 | l1, base_url, ca_cert = start_node_with_clnrest(node_factory) |
| 189 | http_session = http_session_with_retry() |
| 190 | |
| 191 | # /v1/getinfo no rune provided in header of the request |
| 192 | response = http_session.post(base_url + '/v1/getinfo', verify=ca_cert) |
| 193 | assert response.status_code == 403 |
| 194 | assert response.json()['code'] == 1501 |
| 195 | assert response.json()['message'] == 'Not authorized: Missing rune' |
| 196 | |
| 197 | # /v1/getinfo with a rune which doesn't authorized getinfo method |
| 198 | rune_no_getinfo = l1.rpc.createrune(restrictions=[["method/getinfo"]])['rune'] |
| 199 | response = http_session.post(base_url + '/v1/getinfo', headers={'Rune': rune_no_getinfo}, |
| 200 | verify=ca_cert) |
| 201 | assert response.status_code == 401 |
| 202 | assert response.json()['code'] == 1502 |
| 203 | assert response.json()['message'] == 'Not permitted: method is equal to getinfo' |
| 204 | |
| 205 | # /v1/getinfo with a correct rune |
| 206 | rune_getinfo = l1.rpc.createrune(restrictions=[["method=getinfo"]])['rune'] |
| 207 | response = http_session.post(base_url + '/v1/getinfo', headers={'Rune': rune_getinfo}, |
| 208 | verify=ca_cert) |
| 209 | assert response.status_code == 201 |
| 210 | assert response.json()['id'] == l1.info['id'] |
| 211 | |
| 212 | # /v1/invoice with a correct rune but missing parameters |
| 213 | rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune'] |
| 214 | response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice}, |
| 215 | verify=ca_cert) |
| 216 | assert response.status_code == 500 |
| 217 | assert response.json()['code'] == -32602 |
| 218 | |
| 219 | # /v1/invoice with a correct rune but wrong parameters |
| 220 | rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune'] |
| 221 | response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice}, |
| 222 | data={'amount_msat': '<WRONG>', |
| 223 | 'label': 'label', |
| 224 | 'description': 'description'}, |
| 225 | verify=ca_cert) |
| 226 | assert response.status_code == 500 |
| 227 | assert response.json()['code'] == -32602 |
| 228 | |
| 229 | # l2 pays l1's invoice where the invoice is created with /v1/invoice |
| 230 | rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune'] |
| 231 | response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice}, |
| 232 | data={'amount_msat': '50000000', |
| 233 | 'label': 'label', |
| 234 | 'description': 'description'}, |
| 235 | verify=ca_cert) |
| 236 | assert response.status_code == 201 |
| 237 | assert 'bolt11' in response.json() |
| 238 | |
| 239 | |
| 240 | def test_large_response(node_factory): |
nothing calls this directly
no test coverage detected