Revision ba5b8be64d2c68cddeeab923dcdf88c71959107b authored by Mehdi Bouaziz on 31 October 2022, 18:10:35 UTC, committed by Mehdi Bouaziz on 07 November 2022, 15:44:37 UTC
1 parent 3eccab6
test_cors.py
import pytest
from daemons.node import Node
from launchers.sandbox import Sandbox
from tools import utils
@pytest.fixture(scope="class")
def node(sandbox: Sandbox):
"""Launches one node in sandbox mode (genesis)"""
sandbox.add_node(0, params=['--cors-origin', '*'])
yield sandbox.node(0)
class TestCors:
def test_preflight(self, node: Node):
origin = 'localhost'
port = node.rpc_port
headers = {
'Origin': origin,
'Access-Control-Request-Method': 'GET',
'Access-Control-Request-Headers': 'Content-Type',
}
res = utils.rpc(
origin,
port,
'options',
'/chains/main/blocks/head/header/shell',
headers=headers,
)
print(res.headers)
assert res.headers["access-control-allow-origin"] == '*'
assert res.headers["access-control-allow-methods"] == 'GET'
assert res.headers["access-control-allow-headers"] == 'Content-Type'
def test_request(self, node: Node):
origin = 'localhost'
port = node.rpc_port
headers = {'Origin': origin, 'Content-Type': 'application/json'}
res = utils.rpc(
origin,
port,
'get',
'/chains/main/blocks/head/header/shell',
headers=headers,
)
print(res.headers)
assert res.headers["access-control-allow-origin"] == '*'
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...