Use "aliases" property in Move() activity handler

This commit is contained in:
silverpill 2023-03-21 23:24:11 +00:00
parent eb1f815548
commit 4f9a99e6f2
2 changed files with 11 additions and 8 deletions

View file

@ -10,7 +10,6 @@ use crate::activitypub::{
},
fetcher::helpers::get_or_import_profile_by_actor_id,
identifiers::{parse_local_actor_id, profile_actor_id},
receiver::parse_array,
vocabulary::PERSON,
};
use crate::database::{DatabaseClient, DatabaseError};
@ -80,13 +79,8 @@ pub async fn handle_move(
.into_iter()
.map(|profile| profile_actor_id(&instance.url(), &profile))
.collect::<Vec<_>>();
// Read aliases from alsoKnownAs property
// TODO: use new_profile.aliases.into_actor_ids()
if let Some(ref value) = new_actor.also_known_as {
let also_known_as = parse_array(value)
.map_err(|_| ValidationError("invalid alias list"))?;
aliases.extend(also_known_as);
};
// Add aliases reported by server (actor's alsoKnownAs property)
aliases.extend(new_profile.aliases.into_actor_ids());
if !aliases.contains(&old_actor_id) {
return Err(ValidationError("target ID is not an alias").into());
};

View file

@ -547,4 +547,13 @@ mod tests {
let serialized = serde_json::to_string(&payment_option).unwrap();
assert_eq!(serialized, r#"{"payment_type":2,"chain_id":"eip155:1"}"#);
}
#[test]
fn test_alias() {
let actor_id = "https://example.com/users/alice";
let aliases = Aliases::new(vec![actor_id.to_string()]);
let actor_ids = aliases.into_actor_ids();
assert_eq!(actor_ids.len(), 1);
assert_eq!(actor_ids[0], actor_id);
}
}