Allow to expose a subset of unsafe RPCs (#5233)

* sc-cli: Use type-safe constructors for RPC/Prometheus interfaces

* service: Simplify rpc handler creation

Could probably be further simplifies once [this][commit] lands.

[commit]: https://github.com/paritytech/jsonrpc/commit/20485387ed06a48f1a70bf4d609a7cde6cf0accf

* service: Streamline some HTTP & WS server start logic

* client: Introduce a simple RPC policy mechanism

* rpc/system: Check unsafe RPCs

* rpc/offchain: Check unsafe RPCs

* rpc/author: Check unsafe RPCs
This commit is contained in:
Igor Matuszewski
2020-04-20 11:03:58 +02:00
committed by GitHub
parent d05dc090a8
commit 4b1f7d187f
20 changed files with 281 additions and 95 deletions
+26 -14
View File
@@ -109,13 +109,17 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
future::ready(())
}))
});
System::new(SystemInfo {
impl_name: "testclient".into(),
impl_version: "0.2.0".into(),
chain_name: "testchain".into(),
properties: Default::default(),
chain_type: Default::default(),
}, tx)
System::new(
SystemInfo {
impl_name: "testclient".into(),
impl_version: "0.2.0".into(),
chain_name: "testchain".into(),
properties: Default::default(),
chain_type: Default::default(),
},
tx,
sc_rpc_api::DenyUnsafe::No
)
}
fn wait_receiver<T>(rx: Receiver<T>) -> T {
@@ -238,14 +242,19 @@ fn system_local_listen_addresses_works() {
#[test]
fn system_peers() {
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
let peer_id = PeerId::random();
let req = api(Status {
peer_id: peer_id.clone(),
peers: 1,
is_syncing: false,
is_dev: true,
}).system_peers();
let res = runtime.block_on(req).unwrap();
assert_eq!(
wait_receiver(api(Status {
peer_id: peer_id.clone(),
peers: 1,
is_syncing: false,
is_dev: true,
}).system_peers()),
res,
vec![PeerInfo {
peer_id: peer_id.to_base58(),
roles: "FULL".into(),
@@ -258,7 +267,10 @@ fn system_peers() {
#[test]
fn system_network_state() {
let res = wait_receiver(api(None).system_network_state());
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
let req = api(None).system_network_state();
let res = runtime.block_on(req).unwrap();
assert_eq!(
serde_json::from_value::<sc_network::network_state::NetworkState>(res).unwrap(),
sc_network::network_state::NetworkState {