Check appservice registrations for unique as_token. (#72)

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-06-20 15:27:57 +00:00
parent a84e559640
commit ac26193ffe

View File

@@ -1,7 +1,11 @@
mod namespace_regex;
mod registration_info;
use std::{collections::BTreeMap, iter::IntoIterator, sync::Arc};
use std::{
collections::{BTreeMap, HashSet},
iter::IntoIterator,
sync::Arc,
};
use async_trait::async_trait;
use futures::{Future, FutureExt, Stream, StreamExt, TryStreamExt};
@@ -47,6 +51,7 @@ impl crate::Service for Service {
async fn worker(self: Arc<Self>) -> Result {
self.init_registrations().await?;
self.check_registrations().await?;
Ok(())
}
@@ -88,6 +93,25 @@ impl Service {
.await
}
#[tracing::instrument(name = "check", skip(self))]
async fn check_registrations(&self) -> Result {
let regs = self.registration_info.read().await;
let num_as_tokens = regs
.values()
.map(|info| &info.registration.as_token)
.collect::<HashSet<_>>()
.len();
if num_as_tokens < regs.len() {
return Err!(
"Conflicting Appservice registrations: each must have a unique as_token."
);
}
Ok(())
}
/// Registers an appservice and returns the ID to the caller
pub async fn register_appservice(
&self,