2023-02-26 02:51:59 +00:00
|
|
|
use magnetar_core::web_model::acct::Acct;
|
|
|
|
use magnetar_core::web_model::content_type::{ContentActivityStreams, ContentHtml};
|
|
|
|
use magnetar_core::web_model::rel::{RelOStatusSubscribe, RelSelf, RelWebFingerProfilePage};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2023-02-14 00:59:15 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
2023-02-18 14:28:09 +00:00
|
|
|
pub struct WebFinger {
|
|
|
|
pub subject: WebFingerSubject,
|
2023-04-21 23:39:52 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub aliases: Option<Vec<WebFingerSubject>>,
|
2023-02-18 14:28:09 +00:00
|
|
|
pub links: Vec<WebFingerRel>,
|
2023-02-14 00:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
2023-02-18 14:28:09 +00:00
|
|
|
pub enum WebFingerSubject {
|
2023-02-14 00:59:15 +00:00
|
|
|
Acct(Acct),
|
|
|
|
Url(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
#[allow(clippy::enum_variant_names)]
|
2023-02-18 14:28:09 +00:00
|
|
|
pub enum WebFingerRel {
|
2023-02-14 00:59:15 +00:00
|
|
|
RelWebFingerProfilePage {
|
|
|
|
rel: RelWebFingerProfilePage,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
content_type: ContentHtml,
|
|
|
|
href: String,
|
|
|
|
},
|
|
|
|
RelSelf {
|
|
|
|
rel: RelSelf,
|
|
|
|
#[serde(rename = "type")]
|
2023-02-17 23:31:30 +00:00
|
|
|
content_type: ContentActivityStreams,
|
2023-02-14 00:59:15 +00:00
|
|
|
href: String,
|
|
|
|
},
|
|
|
|
RelOStatusSubscribe {
|
|
|
|
rel: RelOStatusSubscribe,
|
|
|
|
template: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2023-02-26 02:51:59 +00:00
|
|
|
use crate::webfinger::WebFingerSubject::Url;
|
|
|
|
use crate::webfinger::{WebFinger, WebFingerRel, WebFingerSubject};
|
|
|
|
use magnetar_core::web_model::acct::Acct;
|
|
|
|
use magnetar_core::web_model::content_type::{ContentActivityStreams, ContentHtml};
|
|
|
|
use magnetar_core::web_model::rel::{RelOStatusSubscribe, RelSelf, RelWebFingerProfilePage};
|
2023-02-14 00:59:15 +00:00
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_webfinger() {
|
|
|
|
let json = json!({
|
|
|
|
"subject": "acct:natty@tech.lgbt",
|
|
|
|
"aliases": [
|
|
|
|
"https://tech.lgbt/@natty",
|
|
|
|
"https://tech.lgbt/users/natty"
|
|
|
|
],
|
|
|
|
"links": [
|
|
|
|
{
|
|
|
|
"rel": "http://webfinger.net/rel/profile-page",
|
|
|
|
"type": "text/html",
|
|
|
|
"href": "https://tech.lgbt/@natty"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rel": "self",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": "https://tech.lgbt/users/natty"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rel": "http://ostatus.org/schema/1.0/subscribe",
|
|
|
|
"template": "https://tech.lgbt/authorize_interaction?uri={uri}"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
let webfinger: WebFinger = serde_json::from_value(json).unwrap();
|
|
|
|
|
|
|
|
let real = WebFinger {
|
2023-02-18 14:28:09 +00:00
|
|
|
subject: WebFingerSubject::Acct(Acct::new("natty@tech.lgbt".into())),
|
2023-04-21 23:39:52 +00:00
|
|
|
aliases: Some(vec![
|
2023-02-14 00:59:15 +00:00
|
|
|
Url("https://tech.lgbt/@natty".to_owned()),
|
|
|
|
Url("https://tech.lgbt/users/natty".to_owned()),
|
2023-04-21 23:39:52 +00:00
|
|
|
]),
|
2023-02-14 00:59:15 +00:00
|
|
|
links: vec![
|
|
|
|
WebFingerRel::RelWebFingerProfilePage {
|
|
|
|
rel: RelWebFingerProfilePage,
|
|
|
|
content_type: ContentHtml,
|
|
|
|
href: "https://tech.lgbt/@natty".to_owned(),
|
|
|
|
},
|
|
|
|
WebFingerRel::RelSelf {
|
|
|
|
rel: RelSelf,
|
2023-02-17 23:31:30 +00:00
|
|
|
content_type: ContentActivityStreams,
|
2023-02-14 00:59:15 +00:00
|
|
|
href: "https://tech.lgbt/users/natty".to_owned(),
|
|
|
|
},
|
|
|
|
WebFingerRel::RelOStatusSubscribe {
|
|
|
|
rel: RelOStatusSubscribe,
|
|
|
|
template: "https://tech.lgbt/authorize_interaction?uri={uri}".to_owned(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(webfinger, real)
|
|
|
|
}
|
|
|
|
}
|