parent
f8b02d1a11
commit
b5bd6dfee9
@ -0,0 +1,5 @@
|
||||
|
||||
[profile.default]
|
||||
retries = 2
|
||||
# kill the slow tests if they still aren't up after 180s
|
||||
slow-timeout = { period = "60s", terminate-after = 3 }
|
@ -0,0 +1,68 @@
|
||||
use std::{collections::HashMap, option_env};
|
||||
|
||||
use anyhow::Result;
|
||||
use assign::assign;
|
||||
use matrix_sdk::{
|
||||
ruma::api::client::{account::register::v3::Request as RegistrationRequest, uiaa},
|
||||
store::make_store_config,
|
||||
Client,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
static USERS: Lazy<Mutex<HashMap<String, (Client, TempDir)>>> = Lazy::new(Mutex::default);
|
||||
|
||||
#[ctor::ctor]
|
||||
fn init_logging() {
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with(tracing_subscriber::fmt::layer().with_test_writer())
|
||||
.init();
|
||||
}
|
||||
|
||||
/// read the test configuration from the environment
|
||||
pub fn test_server_conf() -> (String, String) {
|
||||
(
|
||||
option_env!("HOMESERVER_URL").unwrap_or("http://localhost:8228").to_owned(),
|
||||
option_env!("HOMESERVER_DOMAIN").unwrap_or("matrix-sdk.rs").to_owned(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn get_client_for_user(username: String) -> Result<Client> {
|
||||
let mut users = USERS.lock().await;
|
||||
if let Some((client, _)) = users.get(&username) {
|
||||
return Ok(client.clone());
|
||||
}
|
||||
|
||||
let (homeserver_url, _domain_name) = test_server_conf();
|
||||
|
||||
let tmp_dir = tempdir()?;
|
||||
|
||||
let client = Client::builder()
|
||||
.user_agent("matrix-sdk-integation-tests")
|
||||
.store_config(make_store_config(tmp_dir.path(), None)?)
|
||||
.homeserver_url(homeserver_url)
|
||||
.build()
|
||||
.await?;
|
||||
// safe to assume we have not registered this user yet, but ignore if we did
|
||||
|
||||
if let Err(resp) = client.register(RegistrationRequest::new()).await {
|
||||
// FIXME: do actually check the registration types...
|
||||
if let Some(_response) = resp.uiaa_response() {
|
||||
let request = assign!(RegistrationRequest::new(), {
|
||||
username: Some(username.as_ref()),
|
||||
password: Some(username.as_ref()),
|
||||
|
||||
auth: Some(uiaa::AuthData::Dummy(uiaa::Dummy::new())),
|
||||
});
|
||||
// we don't care if this failed, then we just try to login anyways
|
||||
let _ = client.register(request).await;
|
||||
}
|
||||
}
|
||||
client.login_username(&username, &username).send().await?;
|
||||
users.insert(username, (client.clone(), tmp_dir)); // keeping temp dir around so it doesn't get destroyed yet
|
||||
|
||||
Ok(client)
|
||||
}
|
@ -1,2 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod helpers;
|
||||
|
@ -1,70 +1,2 @@
|
||||
use std::{collections::HashMap, option_env};
|
||||
|
||||
use anyhow::Result;
|
||||
use assign::assign;
|
||||
use matrix_sdk::{
|
||||
ruma::api::client::{account::register::v3::Request as RegistrationRequest, uiaa},
|
||||
store::make_store_config,
|
||||
Client,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
static USERS: Lazy<Mutex<HashMap<String, (Client, TempDir)>>> = Lazy::new(Mutex::default);
|
||||
|
||||
#[ctor::ctor]
|
||||
fn init_logging() {
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with(tracing_subscriber::fmt::layer().with_test_writer())
|
||||
.init();
|
||||
}
|
||||
|
||||
/// read the test configuration from the environment
|
||||
pub fn test_server_conf() -> (String, String) {
|
||||
(
|
||||
option_env!("HOMESERVER_URL").unwrap_or("http://localhost:8228").to_owned(),
|
||||
option_env!("HOMESERVER_DOMAIN").unwrap_or("matrix-sdk.rs").to_owned(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn get_client_for_user(username: String) -> Result<Client> {
|
||||
let mut users = USERS.lock().await;
|
||||
if let Some((client, _)) = users.get(&username) {
|
||||
return Ok(client.clone());
|
||||
}
|
||||
|
||||
let (homeserver_url, _domain_name) = test_server_conf();
|
||||
|
||||
let tmp_dir = tempdir()?;
|
||||
|
||||
let client = Client::builder()
|
||||
.user_agent("matrix-sdk-integation-tests")
|
||||
.store_config(make_store_config(tmp_dir.path(), None)?)
|
||||
.homeserver_url(homeserver_url)
|
||||
.build()
|
||||
.await?;
|
||||
// safe to assume we have not registered this user yet, but ignore if we did
|
||||
|
||||
if let Err(resp) = client.register(RegistrationRequest::new()).await {
|
||||
// FIXME: do actually check the registration types...
|
||||
if let Some(_response) = resp.uiaa_response() {
|
||||
let request = assign!(RegistrationRequest::new(), {
|
||||
username: Some(username.as_ref()),
|
||||
password: Some(username.as_ref()),
|
||||
|
||||
auth: Some(uiaa::AuthData::Dummy(uiaa::Dummy::new())),
|
||||
});
|
||||
// we don't care if this failed, then we just try to login anyways
|
||||
let _ = client.register(request).await;
|
||||
}
|
||||
}
|
||||
client.login_username(&username, &username).send().await?;
|
||||
users.insert(username, (client.clone(), tmp_dir)); // keeping temp dir around so it doesn't get destroyed yet
|
||||
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
mod invitations;
|
||||
mod redaction;
|
||||
|
@ -0,0 +1,157 @@
|
||||
use anyhow::Result;
|
||||
use assign::assign;
|
||||
use matrix_sdk::{
|
||||
config::SyncSettings,
|
||||
ruma::{
|
||||
api::client::room::create_room::v3::Request as CreateRoomRequest,
|
||||
events::{
|
||||
room::name::{RoomNameEventContent, SyncRoomNameEvent},
|
||||
StateEventType,
|
||||
},
|
||||
},
|
||||
Client,
|
||||
};
|
||||
|
||||
use crate::helpers::get_client_for_user;
|
||||
|
||||
async fn sync_once(client: &Client) -> Result<()> {
|
||||
let settings = match client.sync_token().await {
|
||||
Some(token) => SyncSettings::default().token(token),
|
||||
None => SyncSettings::default(),
|
||||
};
|
||||
client.sync_once(settings).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn test_redacting_name() -> Result<()> {
|
||||
let tamatoa = get_client_for_user("tamatoa".to_owned()).await?;
|
||||
// create a room
|
||||
let request = assign!(CreateRoomRequest::new(), {
|
||||
is_direct: true,
|
||||
});
|
||||
|
||||
let room_id = tamatoa.create_room(request).await?.room_id;
|
||||
for _ in 0..=10 {
|
||||
sync_once(&tamatoa).await?;
|
||||
if tamatoa.get_joined_room(&room_id).is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let room = tamatoa.get_joined_room(&room_id).unwrap();
|
||||
// let's send a specific state event
|
||||
|
||||
let content = RoomNameEventContent::new(Some("Inappropriate text".to_owned()));
|
||||
|
||||
room.send_state_event(content).await?;
|
||||
// sync up.
|
||||
for _ in 0..=10 {
|
||||
// we call sync up to ten times to give the server time to flush other
|
||||
// messages over and send us the new state event
|
||||
sync_once(&tamatoa).await?;
|
||||
|
||||
if room.name().is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(room.name(), Some("Inappropriate text".to_owned()));
|
||||
// check state event.
|
||||
|
||||
let raw_event =
|
||||
room.get_state_event(StateEventType::RoomName, "").await?.expect("Room Name not found");
|
||||
let room_name_event: SyncRoomNameEvent = raw_event.deserialize_as()?;
|
||||
assert!(
|
||||
room_name_event.as_original().expect("event exists").content.name.is_some(),
|
||||
"Event not found"
|
||||
);
|
||||
|
||||
room.redact(room_name_event.event_id(), None, None).await?;
|
||||
// sync up.
|
||||
for _ in 0..=10 {
|
||||
// we call sync up to ten times to give the server time to flush other
|
||||
// messages over and send us the new state ev
|
||||
sync_once(&tamatoa).await?;
|
||||
|
||||
if room.name().is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let raw_event =
|
||||
room.get_state_event(StateEventType::RoomName, "").await?.expect("Room Name not found");
|
||||
let room_name_event: SyncRoomNameEvent = raw_event.deserialize_as()?;
|
||||
// Name content has been redacted
|
||||
assert!(
|
||||
room_name_event.as_original().expect("event exists").content.name.is_none(),
|
||||
"Event hasn't been redacted"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn test_redacting_name_static() -> Result<()> {
|
||||
let tamatoa = get_client_for_user("tamatoa".to_owned()).await?;
|
||||
// create a room
|
||||
let request = assign!(CreateRoomRequest::new(), {
|
||||
is_direct: true,
|
||||
});
|
||||
|
||||
let room_id = tamatoa.create_room(request).await?.room_id;
|
||||
for _ in 0..=10 {
|
||||
sync_once(&tamatoa).await?;
|
||||
if tamatoa.get_joined_room(&room_id).is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let room = tamatoa.get_joined_room(&room_id).unwrap();
|
||||
|
||||
// let's send a specific state event
|
||||
let content = RoomNameEventContent::new(Some("Inappropriate text".to_owned()));
|
||||
|
||||
room.send_state_event(content).await?;
|
||||
// sync up.
|
||||
for _ in 0..=10 {
|
||||
// we call sync up to ten times to give the server time to flush other
|
||||
// messages over and send us the new state event
|
||||
sync_once(&tamatoa).await?;
|
||||
|
||||
if room.name().is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check state event.
|
||||
|
||||
let room_name_event: SyncRoomNameEvent =
|
||||
room.get_state_event_static().await?.expect("Room Name not found").deserialize()?;
|
||||
assert!(
|
||||
room_name_event.as_original().expect("event exists").content.name.is_some(),
|
||||
"Event not found"
|
||||
);
|
||||
|
||||
room.redact(room_name_event.event_id(), None, None).await?;
|
||||
// we sync up.
|
||||
for _ in 0..=10 {
|
||||
// we call sync up to ten times to give the server time to flush other
|
||||
// messages over and send us the new state ev
|
||||
sync_once(&tamatoa).await?;
|
||||
|
||||
if room.name().is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let room_name_event: SyncRoomNameEvent =
|
||||
room.get_state_event_static().await?.expect("Room Name not found").deserialize()?;
|
||||
// Name content has been redacted
|
||||
assert!(
|
||||
room_name_event.as_original().expect("event exists").content.name.is_none(),
|
||||
"Event hasn't been redacted"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue