[Updt] Mtp 0.3.0
This commit is contained in:
parent
e1dd86ec02
commit
ad8555bc6e
45 changed files with 2019 additions and 1441 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use async_trait::async_trait;
|
||||
use iota_daemon_lib::log_buffer::LogBuffer;
|
||||
use iota_daemon_lib::{CommandRouter, DaemonRuntime, DaemonServices};
|
||||
use iota_ipc::{LocalRequest, ResponseResult};
|
||||
use iota_daemon_lib::{CommandRouter, DaemonRuntime, DaemonServices, IpcRole, PeerContext};
|
||||
use iota_ipc::{IpcErrorCode, LocalRequest, ResponseResult};
|
||||
use mtp::codec::CommunicationValue;
|
||||
use omikron_connector::{OmikronClient, OmikronError};
|
||||
use std::sync::{
|
||||
|
|
@ -13,6 +13,22 @@ use std::time::Duration;
|
|||
struct FakeOmikron {
|
||||
reconnects: AtomicUsize,
|
||||
}
|
||||
|
||||
fn admin_peer() -> PeerContext {
|
||||
PeerContext {
|
||||
pid: 1,
|
||||
uid: 0,
|
||||
role: IpcRole::Admin,
|
||||
}
|
||||
}
|
||||
|
||||
fn read_peer() -> PeerContext {
|
||||
PeerContext {
|
||||
pid: 2,
|
||||
uid: 1000,
|
||||
role: IpcRole::Read,
|
||||
}
|
||||
}
|
||||
#[async_trait]
|
||||
impl OmikronClient for FakeOmikron {
|
||||
async fn send_message(&self, _: &CommunicationValue) -> Result<(), OmikronError> {
|
||||
|
|
@ -55,7 +71,10 @@ async fn reconnect_uses_the_injected_client() {
|
|||
Arc::new(Mutex::new(LogBuffer::new(100))),
|
||||
);
|
||||
assert!(matches!(
|
||||
router.route(1, LocalRequest::ReconnectOmikron).await.result,
|
||||
router
|
||||
.route(&admin_peer(), 1, LocalRequest::ReconnectOmikron)
|
||||
.await
|
||||
.result,
|
||||
ResponseResult::Ok(_)
|
||||
));
|
||||
assert_eq!(fake.reconnects.load(Ordering::SeqCst), 1);
|
||||
|
|
@ -79,10 +98,44 @@ async fn identity_rotation_is_available_while_omikron_is_offline() {
|
|||
);
|
||||
assert!(matches!(
|
||||
router
|
||||
.route(1, LocalRequest::RotateIotaIdentity)
|
||||
.route(&admin_peer(), 1, LocalRequest::RotateIotaIdentity)
|
||||
.await
|
||||
.result,
|
||||
ResponseResult::Ok(_)
|
||||
));
|
||||
assert_eq!(fake.reconnects.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_role_cannot_execute_an_administrative_request() {
|
||||
let fake = Arc::new(FakeOmikron {
|
||||
reconnects: AtomicUsize::new(0),
|
||||
});
|
||||
let services = Arc::new(DaemonServices {
|
||||
omikron: fake.clone(),
|
||||
users: Default::default(),
|
||||
config: Default::default(),
|
||||
active: true,
|
||||
});
|
||||
let router = CommandRouter::new(
|
||||
Arc::new(DaemonRuntime::new()),
|
||||
services,
|
||||
Arc::new(Mutex::new(LogBuffer::new(100))),
|
||||
);
|
||||
|
||||
assert!(matches!(
|
||||
router
|
||||
.route(
|
||||
&read_peer(),
|
||||
9,
|
||||
LocalRequest::SetConfig {
|
||||
key: "port".into(),
|
||||
value: "1984".into(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.result,
|
||||
ResponseResult::Error(IpcErrorCode::Unauthorized)
|
||||
));
|
||||
assert_eq!(fake.reconnects.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue