#[cfg(feature = "mock-network")]
mod mock_routing {
use crate::auth_flush_app_revocation_queue;
use crate::tests::utils::create_containers_req;
use ffi_utils::test_utils::call_0;
use safe_authenticator::{
app_auth::{app_state, AppState},
config,
test_utils::{create_authenticator, rand_app, register_app, simulate_revocation_failure},
AuthError, Authenticator,
};
use safe_core::ipc::AuthReq;
use unwrap::unwrap;
#[tokio::test]
async fn flushing_app_revocation_queue() -> Result<(), AuthError> {
let (auth, locator, password) = create_authenticator().await;
let auth_req = AuthReq {
app: rand_app(),
app_container: false,
app_permissions: Default::default(),
containers: create_containers_req(),
};
let _ = register_app(&auth, &auth_req).await?;
let app_id_0 = auth_req.app.id;
let auth_req = AuthReq {
app: rand_app(),
app_container: false,
app_permissions: Default::default(),
containers: create_containers_req(),
};
let _ = register_app(&auth, &auth_req).await?;
let app_id_1 = auth_req.app.id;
simulate_revocation_failure(&locator, &password, &[&app_id_0, &app_id_1]).await;
let client = &auth.client;
{
let app_id_0 = app_id_0.clone();
let app_id_1 = app_id_1.clone();
let (_, apps) = config::list_apps(&client).await?;
let state_0 = app_state(&client, &apps, &app_id_0).await?;
let state_1 = app_state(&client, &apps, &app_id_1).await?;
assert_eq!(state_0, AppState::Authenticated);
assert_eq!(state_1, AppState::Authenticated);
}
let auth = Authenticator::login(locator, password, || ()).await?;
unsafe {
unwrap!(call_0(|ud, cb| auth_flush_app_revocation_queue(
&auth, ud, cb
),))
}
let c2 = client.clone();
let (_, apps) = config::list_apps(&c2).await?;
let state_0 = app_state(&c2, &apps, &app_id_0).await?;
let state_1 = app_state(&c2, &apps, &app_id_1).await?;
assert_eq!(state_0, AppState::Revoked);
assert_eq!(state_1, AppState::Revoked);
Ok(())
}
}