Fix all failing tests because of state_key unwraps
This commit is contained in:
parent
625c37cb77
commit
a0177669e6
@ -28,7 +28,6 @@ features = ["client-api", "federation-api", "appservice-api", "unstable-pre-spec
|
||||
|
||||
[features]
|
||||
default = ["unstable-pre-spec"]
|
||||
gen-eventid = []
|
||||
unstable-pre-spec = ["ruma/unstable-pre-spec"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -561,21 +561,6 @@ pub mod event {
|
||||
event_id: EventId,
|
||||
}
|
||||
|
||||
/// This feature is turned on in conduit but off when the tests run because
|
||||
/// we rely on the EventId to check the state-res.
|
||||
#[cfg(feature = "gen-eventid")]
|
||||
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
|
||||
use std::convert::TryFrom;
|
||||
EventId::try_from(format!(
|
||||
"${}",
|
||||
reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6)
|
||||
.map_err(de::Error::custom)?,
|
||||
))
|
||||
.map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
/// Only turned on for testing where we need to keep the ID.
|
||||
#[cfg(not(feature = "gen-eventid"))]
|
||||
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
|
||||
use std::convert::TryFrom;
|
||||
Ok(match from_raw_json_value::<EventIdHelper, E>(&json) {
|
||||
|
@ -1 +1 @@
|
||||
merge_imports = true
|
||||
imports_granularity="Crate"
|
17
src/lib.rs
17
src/lib.rs
@ -48,7 +48,9 @@ impl StateResolution {
|
||||
current_state: &StateMap<EventId>,
|
||||
event_map: &EventMap<Arc<E>>,
|
||||
) -> Result<bool> {
|
||||
let state_key = incoming_event.state_key().ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?;
|
||||
let state_key = incoming_event
|
||||
.state_key()
|
||||
.ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?;
|
||||
|
||||
log::info!("Applying a single event, state resolution starting");
|
||||
let ev = incoming_event;
|
||||
@ -60,9 +62,12 @@ impl StateResolution {
|
||||
};
|
||||
|
||||
let mut auth_events = StateMap::new();
|
||||
for key in
|
||||
event_auth::auth_types_for_event(&ev.kind(), &ev.sender(), Some(state_key), ev.content())
|
||||
{
|
||||
for key in event_auth::auth_types_for_event(
|
||||
&ev.kind(),
|
||||
&ev.sender(),
|
||||
Some(state_key),
|
||||
ev.content(),
|
||||
) {
|
||||
if let Some(ev_id) = current_state.get(&key) {
|
||||
if let Ok(event) = StateResolution::get_or_load_event(room_id, ev_id, event_map) {
|
||||
// TODO synapse checks `rejected_reason` is None here
|
||||
@ -500,7 +505,9 @@ impl StateResolution {
|
||||
|
||||
for (idx, event_id) in events_to_check.iter().enumerate() {
|
||||
let event = StateResolution::get_or_load_event(room_id, event_id, event_map)?;
|
||||
let state_key = event.state_key().ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?;
|
||||
let state_key = event
|
||||
.state_key()
|
||||
.ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?;
|
||||
|
||||
let mut auth_events = BTreeMap::new();
|
||||
for aid in &event.auth_events() {
|
||||
|
@ -222,7 +222,14 @@ pub fn do_check(
|
||||
.get(&event_id("$END:foo"))
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(k, v)| expected_state.contains_key(k) || start_state.get(k) != Some(*v))
|
||||
.filter(|(k, v)| {
|
||||
expected_state.contains_key(k)
|
||||
|| start_state.get(k) != Some(*v)
|
||||
// Filter out the dummy messages events.
|
||||
// These act as points in time where there should be a known state to
|
||||
// test against.
|
||||
&& k != &&(EventType::RoomMessage, "dummy".to_string())
|
||||
})
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect::<StateMap<EventId>>();
|
||||
|
||||
@ -482,7 +489,7 @@ pub fn INITIAL_EVENTS() -> BTreeMap<EventId, Arc<StateEvent>> {
|
||||
"START",
|
||||
charlie(),
|
||||
EventType::RoomMessage,
|
||||
None,
|
||||
Some("dummy"),
|
||||
json!({}),
|
||||
&[],
|
||||
&[],
|
||||
@ -491,7 +498,7 @@ pub fn INITIAL_EVENTS() -> BTreeMap<EventId, Arc<StateEvent>> {
|
||||
"END",
|
||||
charlie(),
|
||||
EventType::RoomMessage,
|
||||
None,
|
||||
Some("dummy"),
|
||||
json!({}),
|
||||
&[],
|
||||
&[],
|
||||
@ -585,21 +592,6 @@ pub mod event {
|
||||
event_id: EventId,
|
||||
}
|
||||
|
||||
/// This feature is turned on in conduit but off when the tests run because
|
||||
/// we rely on the EventId to check the state-res.
|
||||
#[cfg(feature = "gen-eventid")]
|
||||
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
|
||||
use std::convert::TryFrom;
|
||||
EventId::try_from(format!(
|
||||
"${}",
|
||||
reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6)
|
||||
.map_err(de::Error::custom)?,
|
||||
))
|
||||
.map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
/// Only turned on for testing where we need to keep the ID.
|
||||
#[cfg(not(feature = "gen-eventid"))]
|
||||
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
|
||||
use std::convert::TryFrom;
|
||||
Ok(match from_raw_json_value::<EventIdHelper, E>(&json) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user