Reject mismatched channel properties during snapshot export

This commit is contained in:
omar committed 2026-11-27 12:46:27 +03:00
1 parent 4fee4c0ce6
commit 89cf17066f
4 files changed
+35 -4

No files matched your search

+2
View File
@@ -2,6 +2,8 @@
## Unreleased ## Unreleased
- Snapshot export no longer attaches an unrelated channel's properties to a saved channel. Missing or ambiguous properties are reported as a partial export.
- Channel Info ignores superseded successes and errors after navigation or reconnect. It rejects an empty, ambiguous or mismatched reply instead of showing the wrong channel. - Channel Info ignores superseded successes and errors after navigation or reconnect. It rejects an empty, ambiguous or mismatched reply instead of showing the wrong channel.
- Contacts offers Ignore or Unignore according to the selected UID's current state. A queued action from a deleted contact can no longer change the ignore list. - Contacts offers Ignore or Unignore according to the selected UID's current state. A queued action from a deleted contact can no longer change the ignore list.
+2
View File
@@ -4,6 +4,8 @@
## Возврат к разработке на ПК, 2026-11-26 ## Возврат к разработке на ПК, 2026-11-26
Windows, база `4fee4c0`: экспорт снимка сверяет ID единственной строки свойств с ID экспортируемого канала. При неверном ответе отчёт частичный; соседний канал сохранён со своим описанием. Прошли 10 тестов сервиса снимков. Системный диалог экспорта не проверялся.
Windows, база `061bb2d`: закрыт `command:channel_info`. На beta14 из меню временного канала Slint прочитаны имя, тема и многострочное описание; при выборе лобби прежние свойства не остались. Шесть нативных тестов и одна отдельная проверка stdio прошли. Стенд остановлен. Windows, база `061bb2d`: закрыт `command:channel_info`. На beta14 из меню временного канала Slint прочитаны имя, тема и многострочное описание; при выборе лобби прежние свойства не остались. Шесть нативных тестов и одна отдельная проверка stdio прошли. Стенд остановлен.
Windows, база `96d9c45`: проверен `preference:highlightContacts` в Slint после двух перезапусков. Подсветка строки следует за UID, а не номером клиента. Прошли две проверки контактов на изолированном профиле и синтетическом списке участников. Windows, база `96d9c45`: проверен `preference:highlightContacts` в Slint после двух перезапусков. Подсветка строки следует за UID, а не номером клиента. Прошли две проверки контактов на изолированном профиле и синтетическом списке участников.
+8 -3
View File
@@ -350,9 +350,15 @@ impl<'a, A: SessionAccess + Send> SnapshotOperation<'a, A> {
if !seen.insert(channel_id) { return Err(codec::invalid("Cyclic server channel tree")); } if !seen.insert(channel_id) { return Err(codec::invalid("Cyclic server channel tree")); }
if wire_u64(&row["channel_flag_permanent"]) != Some(1) { continue; } if wire_u64(&row["channel_flag_permanent"]) != Some(1) { continue; }
let result = async { let result = async {
let info = rows_from(self.call(extra(Extra::ChannelInfo { channel_id })).await?)?.into_iter().next().unwrap_or_else(|| json!({})); let info = self.call(extra(Extra::ChannelInfo { channel_id })).await?;
let Some([details]) = info["rows"].as_array().map(Vec::as_slice) else {
return Err(ServiceError::new("bad_response", "Expected one properties row for the channel being exported"));
};
if id(details,"cid")? != channel_id {
return Err(ServiceError::new("target_changed", "Channel properties belong to another channel"));
}
let mut merged = row.as_object().cloned().ok_or_else(|| codec::invalid("Invalid channel row"))?; let mut merged = row.as_object().cloned().ok_or_else(|| codec::invalid("Invalid channel row"))?;
if let Some(info) = info.as_object() { merged.extend(info.clone()); } merged.extend(details.as_object().expect("validated channel ID").clone());
let mut item = codec::from_wire(&Value::Object(merged), CHANNEL_FIELDS, "channel_", vars)?; let mut item = codec::from_wire(&Value::Object(merged), CHANNEL_FIELDS, "channel_", vars)?;
let permissions = self.permissions(Admin::ChannelPermList { channel_id }).await; let permissions = self.permissions(Admin::ChannelPermList { channel_id }).await;
item["permissions"] = Value::Array(self.record("channelPermission", channel_id, permissions)?.unwrap_or_default()); item["permissions"] = Value::Array(self.record("channelPermission", channel_id, permissions)?.unwrap_or_default());
@@ -542,7 +548,6 @@ impl<'a, A: SessionAccess + Send> SnapshotOperation<'a, A> {
}) })
} }
} }
fn rows_from(value: Value) -> Result<Vec<Value>> { rows(value) }
fn remap_icon(value: i64, map: &HashMap<u32,u32>) -> Result<u32> { fn remap_icon(value: i64, map: &HashMap<u32,u32>) -> Result<u32> {
let id = value as u32; let id = value as u32;
if id <= 1000 { return Ok(id); } if id <= 1000 { return Ok(id); }
+23 -1
View File
@@ -51,7 +51,7 @@ async fn export_preserves_permanent_hierarchy_predecessor_order_all_categories_a
{"cid":"10","cpid":"0","channel_order":"0","channel_flag_permanent":"1","channel_name":"Example Lobby"}, {"cid":"10","cpid":"0","channel_order":"0","channel_flag_permanent":"1","channel_name":"Example Lobby"},
{"cid":"11","cpid":"10","channel_order":"0","channel_flag_permanent":"1","channel_name":"Child"}, {"cid":"11","cpid":"10","channel_order":"0","channel_flag_permanent":"1","channel_name":"Child"},
{"cid":"13","cpid":"0","channel_order":"12","channel_flag_permanent":"0","channel_name":"Temporary"}]), {"cid":"13","cpid":"0","channel_order":"12","channel_flag_permanent":"0","channel_name":"Temporary"}]),
Command::Admin(Admin::Extra(Extra::ChannelInfo { channel_id })) => json!([{"channel_description":if *channel_id == 10 {"Example description"} else {""}}]), Command::Admin(Admin::Extra(Extra::ChannelInfo { channel_id })) => json!([{"cid":channel_id.to_string(),"channel_description":if *channel_id == 10 {"Example description"} else {""}}]),
Command::Admin(Admin::ChannelPermList { .. }) => json!([{"permid":"1","permvalue":"-1"}]), Command::Admin(Admin::ChannelPermList { .. }) => json!([{"permid":"1","permvalue":"-1"}]),
Command::Admin(Admin::Extra(Extra::ServerGroupList {})) => json!([{"sgid":"5","type":"1","sortid":"0","name":"Example Admin"},{"sgid":"1","type":"0","name":"Template"}]), Command::Admin(Admin::Extra(Extra::ServerGroupList {})) => json!([{"sgid":"5","type":"1","sortid":"0","name":"Example Admin"},{"sgid":"1","type":"0","name":"Template"}]),
Command::Admin(Admin::ServerGroupPermList { .. }) => json!([{"permid":"1","permvalue":"100","permskip":"1","permnegated":"1"}]), Command::Admin(Admin::ServerGroupPermList { .. }) => json!([{"permid":"1","permvalue":"100","permskip":"1","permnegated":"1"}]),
@@ -132,6 +132,28 @@ async fn cancelled_acknowledged_parent_is_retained_without_creating_child() {
assert!(report.cancelled); assert_eq!(report.created.channels,vec![8]); assert!(report.cancelled); assert_eq!(report.created.channels,vec![8]);
assert_eq!(access.calls.lock().unwrap().iter().filter(|c| c.name()=="channel_create").count(),1); assert_eq!(access.calls.lock().unwrap().iter().filter(|c| c.name()=="channel_create").count(),1);
} }
#[tokio::test]
async fn export_reports_bad_channel_details_without_contaminating_siblings() {
for broken in [json!([]), json!([{"cid":"1"},{"cid":"2"}]), json!([{"cid":"2","channel_name":"Wrong"}])] {
let (_,icons,_) = fixture(move |_,_,cmd| match cmd {
Command::Admin(Admin::ServerInfo) => Ok(json!({"rows":[{}]})),
Command::Admin(Admin::Extra(Extra::ChannelList{})) => Ok(json!({"rows":[
{"cid":"1","cpid":"0","channel_order":"0","channel_name":"First","channel_flag_permanent":"1"},
{"cid":"2","cpid":"0","channel_order":"1","channel_name":"Second","channel_flag_permanent":"1"}]})),
Command::Admin(Admin::Extra(Extra::ChannelInfo{channel_id:1})) => Ok(json!({"rows":broken})),
Command::Admin(Admin::Extra(Extra::ChannelInfo{channel_id:2})) => Ok(json!({"rows":[{"cid":"2","channel_description":"Second only"}]})),
Command::Admin(Admin::ChannelPermList{channel_id:2}) => Ok(json!({"rows":[]})),
_ => panic!("unexpected {}",cmd.name()),
});
let key=key();let cancel=OperationCancellation::default();let mut op=SnapshotOperation::new(&icons,&key,context(),&cancel,&progress);
let document=op.create(&ExportOptions{include_channels:true,..Default::default()}).await.unwrap();
let channels=document.catalog()[0]["channels"].as_array().unwrap();
assert_eq!(channels.len(),1);assert_eq!(channels[0]["name"],"Second");assert_eq!(channels[0]["description"],"Second only");
let report=op.finish("export",Ok(()));assert!(report.partial&&!report.success);
assert_eq!(report.errors.len(),1);assert_eq!(report.errors[0].identifier,"First");
}
}
#[tokio::test] #[tokio::test]
async fn every_conflict_mode_preserves_channel_parent_ownership() { async fn every_conflict_mode_preserves_channel_parent_ownership() {
for mode in [ConflictMode::Skip,ConflictMode::RenameNew,ConflictMode::RenameExisting] { for mode in [ConflictMode::Skip,ConflictMode::RenameNew,ConflictMode::RenameExisting] {