Merge branch 'main' into db-traits-refactor

This commit is contained in:
dullbananas 2023-07-04 07:56:32 -07:00 committed by GitHub
commit d9e0269774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 53 deletions

34
Cargo.lock generated
View File

@ -31,7 +31,7 @@ dependencies = [
"enum_delegate", "enum_delegate",
"futures-core", "futures-core",
"http", "http",
"http-signature-normalization 0.7.0", "http-signature-normalization",
"http-signature-normalization-reqwest", "http-signature-normalization-reqwest",
"httpdate", "httpdate",
"itertools", "itertools",
@ -2219,15 +2219,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29"
[[package]]
name = "http-signature-normalization"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8f45adbef81d7ea3bd7e9bcc6734b7245dad05a14abdcc7ddc0988791d63515"
dependencies = [
"httpdate",
]
[[package]] [[package]]
name = "http-signature-normalization" name = "http-signature-normalization"
version = "0.7.0" version = "0.7.0"
@ -2237,26 +2228,6 @@ dependencies = [
"httpdate", "httpdate",
] ]
[[package]]
name = "http-signature-normalization-actix"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7483d0ee4d093fa4bfe5956cd405492c07808a5064a29cfe3960d474f21f39c2"
dependencies = [
"actix-http",
"actix-rt",
"actix-web",
"base64 0.13.1",
"futures-util",
"http-signature-normalization 0.6.0",
"sha2",
"thiserror",
"tokio",
"tracing",
"tracing-error",
"tracing-futures",
]
[[package]] [[package]]
name = "http-signature-normalization-reqwest" name = "http-signature-normalization-reqwest"
version = "0.8.0" version = "0.8.0"
@ -2264,7 +2235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c382c69a07b21accae86298d520579403af6479b1cd1c389e3ee11f01d48627" checksum = "3c382c69a07b21accae86298d520579403af6479b1cd1c389e3ee11f01d48627"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"http-signature-normalization 0.7.0", "http-signature-normalization",
"httpdate", "httpdate",
"reqwest", "reqwest",
"reqwest-middleware", "reqwest-middleware",
@ -2661,7 +2632,6 @@ dependencies = [
"futures", "futures",
"html2md", "html2md",
"http", "http",
"http-signature-normalization-actix",
"itertools", "itertools",
"lemmy_api_common", "lemmy_api_common",
"lemmy_db_schema", "lemmy_db_schema",

View File

@ -27,6 +27,7 @@ lto = "thin"
[features] [features]
embed-pictrs = ["pict-rs"] embed-pictrs = ["pict-rs"]
console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry", "reqwest-tracing/opentelemetry_0_16"] console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry", "reqwest-tracing/opentelemetry_0_16"]
json-log = ["tracing-subscriber/json"]
default = [] default = []
[workspace] [workspace]

View File

@ -40,7 +40,6 @@ reqwest = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
html2md = "0.2.14" html2md = "0.2.14"
serde_with = { workspace = true } serde_with = { workspace = true }
http-signature-normalization-actix = { version = "0.6.2", default-features = false, features = ["server", "sha-2"] }
enum_delegate = "0.2.0" enum_delegate = "0.2.0"
[dev-dependencies] [dev-dependencies]

View File

@ -27,9 +27,7 @@ pub async fn list_comments(
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;
let community_id = if let Some(name) = &data.community_name { let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true) Some(resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true).await?)
.await
.ok()
.map(|c| c.id) .map(|c| c.id)
} else { } else {
data.community_id data.community_id

View File

@ -29,9 +29,7 @@ pub async fn list_posts(
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let community_id = if let Some(name) = &data.community_name { let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true) Some(resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true).await?)
.await
.ok()
.map(|c| c.id) .map(|c| c.id)
} else { } else {
data.community_id data.community_id

View File

@ -41,10 +41,11 @@ pub async fn search(
let listing_type = data.listing_type; let listing_type = data.listing_type;
let search_type = data.type_.unwrap_or(SearchType::All); let search_type = data.type_.unwrap_or(SearchType::All);
let community_id = if let Some(name) = &data.community_name { let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &local_user_view, false) Some(
.await resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &local_user_view, false)
.ok() .await?,
.map(|c| c.id) )
.map(|c| c.id)
} else { } else {
data.community_id data.community_id
}; };

View File

@ -19,8 +19,6 @@ use actix_web::{
http::{header, Method}, http::{header, Method},
web, web,
}; };
use http_signature_normalization_actix::digest::middleware::VerifyDigest;
use sha2::{Digest, Sha256};
pub fn config(cfg: &mut web::ServiceConfig) { pub fn config(cfg: &mut web::ServiceConfig) {
cfg cfg
@ -57,7 +55,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(
web::scope("") web::scope("")
.wrap(VerifyDigest::new(Sha256::new()))
.guard(InboxRequestGuard) .guard(InboxRequestGuard)
.route("/c/{community_name}/inbox", web::post().to(community_inbox)) .route("/c/{community_name}/inbox", web::post().to(community_inbox))
.route("/u/{user_name}/inbox", web::post().to(person_inbox)) .route("/u/{user_name}/inbox", web::post().to(person_inbox))

View File

@ -356,10 +356,7 @@ mod tests {
diesel_option_overwrite_to_url(&Some(String::new())), diesel_option_overwrite_to_url(&Some(String::new())),
Ok(Some(None)) Ok(Some(None))
)); ));
assert!(matches!( assert!(diesel_option_overwrite_to_url(&Some("invalid_url".to_string())).is_err());
diesel_option_overwrite_to_url(&Some("invalid_url".to_string())),
Err(_)
));
let example_url = "https://example.com"; let example_url = "https://example.com";
assert!(matches!( assert!(matches!(
diesel_option_overwrite_to_url(&Some(example_url.to_string())), diesel_option_overwrite_to_url(&Some(example_url.to_string())),

View File

@ -24,6 +24,62 @@ const BIO_MAX_LENGTH: usize = 300;
const SITE_NAME_MAX_LENGTH: usize = 20; const SITE_NAME_MAX_LENGTH: usize = 20;
const SITE_NAME_MIN_LENGTH: usize = 1; const SITE_NAME_MIN_LENGTH: usize = 1;
const SITE_DESCRIPTION_MAX_LENGTH: usize = 150; const SITE_DESCRIPTION_MAX_LENGTH: usize = 150;
//Invisible unicode characters, taken from https://invisible-characters.com/
const FORBIDDEN_DISPLAY_CHARS: [char; 53] = [
'\u{0009}',
'\u{00a0}',
'\u{00ad}',
'\u{034f}',
'\u{061c}',
'\u{115f}',
'\u{1160}',
'\u{17b4}',
'\u{17b5}',
'\u{180e}',
'\u{2000}',
'\u{2001}',
'\u{2002}',
'\u{2003}',
'\u{2004}',
'\u{2005}',
'\u{2006}',
'\u{2007}',
'\u{2008}',
'\u{2009}',
'\u{200a}',
'\u{200b}',
'\u{200c}',
'\u{200d}',
'\u{200e}',
'\u{200f}',
'\u{202f}',
'\u{205f}',
'\u{2060}',
'\u{2061}',
'\u{2062}',
'\u{2063}',
'\u{2064}',
'\u{206a}',
'\u{206b}',
'\u{206c}',
'\u{206d}',
'\u{206e}',
'\u{206f}',
'\u{3000}',
'\u{2800}',
'\u{3164}',
'\u{feff}',
'\u{ffa0}',
'\u{1d159}',
'\u{1d173}',
'\u{1d174}',
'\u{1d175}',
'\u{1d176}',
'\u{1d177}',
'\u{1d178}',
'\u{1d179}',
'\u{1d17a}',
];
fn has_newline(name: &str) -> bool { fn has_newline(name: &str) -> bool {
name.contains('\n') name.contains('\n')
@ -42,8 +98,8 @@ pub fn is_valid_actor_name(name: &str, actor_name_max_length: usize) -> LemmyRes
// Can't do a regex here, reverse lookarounds not supported // Can't do a regex here, reverse lookarounds not supported
pub fn is_valid_display_name(name: &str, actor_name_max_length: usize) -> LemmyResult<()> { pub fn is_valid_display_name(name: &str, actor_name_max_length: usize) -> LemmyResult<()> {
let check = !name.starts_with('@') let check = !name.contains(FORBIDDEN_DISPLAY_CHARS)
&& !name.starts_with('\u{200b}') && !name.starts_with('@')
&& name.chars().count() >= 3 && name.chars().count() >= 3
&& name.chars().count() <= actor_name_max_length && name.chars().count() <= actor_name_max_length
&& !has_newline(name); && !has_newline(name);

View File

@ -185,7 +185,14 @@ pub fn init_logging(opentelemetry_url: &Option<Url>) -> Result<(), LemmyError> {
.trim_matches('"') .trim_matches('"')
.parse::<Targets>()?; .parse::<Targets>()?;
let format_layer = tracing_subscriber::fmt::layer().with_filter(targets.clone()); let format_layer = {
#[cfg(feature = "json-log")]
let layer = tracing_subscriber::fmt::layer().json();
#[cfg(not(feature = "json-log"))]
let layer = tracing_subscriber::fmt::layer();
layer.with_filter(targets.clone())
};
let subscriber = Registry::default() let subscriber = Registry::default()
.with(format_layer) .with(format_layer)