-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appservice virt member test #747
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,12 @@ use matrix_sdk::{ | |
}; | ||
use matrix_sdk_appservice::*; | ||
use matrix_sdk_test::{appservice::TransactionBuilder, async_test, EventsJson}; | ||
use ruma::{api::MatrixVersion, room_id}; | ||
use ruma::{ | ||
api::{appservice::event::push_events, MatrixVersion}, | ||
events::AnyRoomEvent, | ||
room_id, | ||
serde::Raw, | ||
}; | ||
use serde_json::json; | ||
use warp::{Filter, Reply}; | ||
|
||
|
@@ -299,6 +304,105 @@ async fn test_appservice_on_sub_path() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
#[async_test] | ||
async fn test_receive_transaction() -> Result<()> { | ||
tracing_subscriber::fmt().try_init().ok(); | ||
let json = vec![ | ||
Raw::new(&json!({ | ||
"content": { | ||
"avatar_url": null, | ||
"displayname": "Appservice", | ||
"membership": "join" | ||
}, | ||
"event_id": "$151800140479rdvjg:localhost", | ||
"membership": "join", | ||
"origin_server_ts": 151800140, | ||
"sender": "@_appservice:localhost", | ||
"state_key": "@_appservice:localhost", | ||
"type": "m.room.member", | ||
"room_id": "!coolplace:localhost", | ||
"unsigned": { | ||
"age": 2970366 | ||
} | ||
}))? | ||
.cast::<AnyRoomEvent>(), | ||
Raw::new(&json!({ | ||
"content": { | ||
"avatar_url": null, | ||
"displayname": "Appservice", | ||
"membership": "join" | ||
}, | ||
"event_id": "$151800140491rfbja:localhost", | ||
"membership": "join", | ||
"origin_server_ts": 151800140, | ||
"sender": "@_appservice:localhost", | ||
"state_key": "@_appservice:localhost", | ||
"type": "m.room.member", | ||
"room_id": "!boringplace:localhost", | ||
"unsigned": { | ||
"age": 2970366 | ||
} | ||
}))? | ||
.cast::<AnyRoomEvent>(), | ||
Raw::new(&json!({ | ||
"content": { | ||
"avatar_url": null, | ||
"displayname": "Alice", | ||
"membership": "join" | ||
}, | ||
"event_id": "$151800140517rfvjc:localhost", | ||
"membership": "join", | ||
"origin_server_ts": 151800140, | ||
"sender": "@_appservice_alice:localhost", | ||
"state_key": "@_appservice_alice:localhost", | ||
"type": "m.room.member", | ||
"room_id": "!coolplace:localhost", | ||
"unsigned": { | ||
"age": 2970366 | ||
} | ||
}))? | ||
.cast::<AnyRoomEvent>(), | ||
Raw::new(&json!({ | ||
"content": { | ||
"avatar_url": null, | ||
"displayname": "Bob", | ||
"membership": "invite" | ||
}, | ||
"event_id": "$151800140594rfvjc:localhost", | ||
"membership": "invite", | ||
"origin_server_ts": 151800174, | ||
"sender": "@_appservice_bob:localhost", | ||
"state_key": "@_appservice_bob:localhost", | ||
"type": "m.room.member", | ||
"room_id": "!boringplace:localhost", | ||
"unsigned": { | ||
"age": 2970366 | ||
} | ||
}))? | ||
.cast::<AnyRoomEvent>(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure where to put the test json, as the needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases I prefer to put the JSON close to the test, even at the cost of some duplication. Otherwise it makes it harder to keep in mind which JSON we're using and what assumptions it carries with it. |
||
]; | ||
let appservice = appservice(None).await?; | ||
|
||
let alice = appservice.virtual_user_client("_appservice_alice").await?; | ||
let bob = appservice.virtual_user_client("_appservice_bob").await?; | ||
appservice | ||
.receive_transaction(push_events::v1::IncomingRequest::new("dontcare".into(), json)) | ||
.await?; | ||
let coolplace = room_id!("!coolplace:localhost"); | ||
let boringplace = room_id!("!boringplace:localhost"); | ||
assert!( | ||
alice.get_joined_room(coolplace).is_some(), | ||
"Alice's membership in coolplace should be join" | ||
); | ||
assert!( | ||
bob.get_invited_room(boringplace).is_some(), | ||
"Bob's membership in boringplace should be invite" | ||
); | ||
assert!(alice.get_room(boringplace).is_none(), "Alice should not know about boringplace"); | ||
assert!(bob.get_room(coolplace).is_none(), "Bob should not know about coolplace"); | ||
Ok(()) | ||
} | ||
|
||
mod registration { | ||
use super::*; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed like a safe assumption that if the appservice receives events for a given room, the main client is already a member of it and we just missed it or haven't processed the relevant membership event yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, seems like a save assumption. A proper fix would be to force a full state sync if we see events for a room the first time, but that's out of scope for this PR.