mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-16 09:24:00 +00:00
Fix unit tests
This commit is contained in:
parent
06e82fe761
commit
964d95de5c
17 changed files with 63 additions and 46 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1852,8 +1852,10 @@ dependencies = [
|
||||||
name = "lemmy_server"
|
name = "lemmy_server"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"activitystreams",
|
||||||
"actix",
|
"actix",
|
||||||
"actix-files",
|
"actix-files",
|
||||||
|
"actix-rt",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"actix-web-actors",
|
"actix-web-actors",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -1877,6 +1879,7 @@ dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rss",
|
"rss",
|
||||||
"serde 1.0.117",
|
"serde 1.0.117",
|
||||||
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"strum",
|
"strum",
|
||||||
"tokio 0.3.1",
|
"tokio 0.3.1",
|
||||||
|
|
|
@ -46,6 +46,9 @@ tokio = "0.3"
|
||||||
sha2 = "0.9"
|
sha2 = "0.9"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
reqwest = { version = "0.10", features = ["json"] }
|
reqwest = { version = "0.10", features = ["json"] }
|
||||||
|
activitystreams = "0.7.0-alpha.4"
|
||||||
|
actix-rt = { version = "1.1", default-features = false }
|
||||||
|
serde_json = { version = "1.0", features = ["preserve_order"]}
|
||||||
|
|
||||||
[dev-dependencies.cargo-husky]
|
[dev-dependencies.cargo-husky]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
|
|
@ -54,7 +54,8 @@ pub async fn get_activity(
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
if !activity.local || activity.sensitive {
|
let sensitive = activity.sensitive.unwrap_or(true);
|
||||||
|
if !activity.local || sensitive {
|
||||||
Ok(HttpResponse::NotFound().finish())
|
Ok(HttpResponse::NotFound().finish())
|
||||||
} else {
|
} else {
|
||||||
Ok(create_apub_response(&activity.data))
|
Ok(create_apub_response(&activity.data))
|
||||||
|
|
|
@ -12,22 +12,22 @@ use std::{
|
||||||
#[table_name = "activity"]
|
#[table_name = "activity"]
|
||||||
pub struct Activity {
|
pub struct Activity {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub ap_id: String,
|
|
||||||
pub data: Value,
|
pub data: Value,
|
||||||
pub local: bool,
|
pub local: bool,
|
||||||
pub sensitive: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub ap_id: Option<String>,
|
||||||
|
pub sensitive: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "activity"]
|
#[table_name = "activity"]
|
||||||
pub struct ActivityForm {
|
pub struct ActivityForm {
|
||||||
pub ap_id: String,
|
|
||||||
pub data: Value,
|
pub data: Value,
|
||||||
pub local: bool,
|
pub local: bool,
|
||||||
pub sensitive: bool,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub ap_id: String,
|
||||||
|
pub sensitive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Crud<ActivityForm> for Activity {
|
impl Crud<ActivityForm> for Activity {
|
||||||
|
@ -53,6 +53,10 @@ impl Crud<ActivityForm> for Activity {
|
||||||
.set(new_activity)
|
.set(new_activity)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
|
||||||
|
use crate::schema::activity::dsl::*;
|
||||||
|
diesel::delete(activity.find(activity_id)).execute(conn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Activity {
|
impl Activity {
|
||||||
|
@ -115,7 +119,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -162,11 +166,11 @@ mod tests {
|
||||||
let inserted_activity = Activity::create(&conn, &activity_form).unwrap();
|
let inserted_activity = Activity::create(&conn, &activity_form).unwrap();
|
||||||
|
|
||||||
let expected_activity = Activity {
|
let expected_activity = Activity {
|
||||||
ap_id: ap_id.to_string(),
|
ap_id: Some(ap_id.to_string()),
|
||||||
id: inserted_activity.id,
|
id: inserted_activity.id,
|
||||||
data: test_json,
|
data: test_json,
|
||||||
local: true,
|
local: true,
|
||||||
sensitive: false,
|
sensitive: Some(false),
|
||||||
published: inserted_activity.published,
|
published: inserted_activity.published,
|
||||||
updated: None,
|
updated: None,
|
||||||
};
|
};
|
||||||
|
@ -174,6 +178,7 @@ mod tests {
|
||||||
let read_activity = Activity::read(&conn, inserted_activity.id).unwrap();
|
let read_activity = Activity::read(&conn, inserted_activity.id).unwrap();
|
||||||
let read_activity_by_apub_id = Activity::read_from_apub_id(&conn, ap_id).unwrap();
|
let read_activity_by_apub_id = Activity::read_from_apub_id(&conn, ap_id).unwrap();
|
||||||
User_::delete(&conn, inserted_creator.id).unwrap();
|
User_::delete(&conn, inserted_creator.id).unwrap();
|
||||||
|
Activity::delete(&conn, inserted_activity.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_activity, read_activity);
|
assert_eq!(expected_activity, read_activity);
|
||||||
assert_eq!(expected_activity, read_activity_by_apub_id);
|
assert_eq!(expected_activity, read_activity_by_apub_id);
|
||||||
|
|
|
@ -280,7 +280,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -519,7 +519,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -275,8 +275,8 @@ pub struct CommunityFollower {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub user_id: i32,
|
||||||
pub pending: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub pending: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
@ -341,7 +341,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -407,6 +407,7 @@ mod tests {
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
user_id: inserted_user.id,
|
||||||
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_follower =
|
let inserted_community_follower =
|
||||||
|
@ -416,6 +417,7 @@ mod tests {
|
||||||
id: inserted_community_follower.id,
|
id: inserted_community_follower.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
user_id: inserted_user.id,
|
||||||
|
pending: Some(false),
|
||||||
published: inserted_community_follower.published,
|
published: inserted_community_follower.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -416,7 +416,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -445,7 +445,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -100,7 +100,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -349,7 +349,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -416,7 +416,7 @@ mod tests {
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
theme: "browser".into(),
|
theme: "browser".into(),
|
||||||
default_sort_type: SortType::Hot as i16,
|
default_sort_type: SortType::Hot as i16,
|
||||||
|
|
|
@ -157,7 +157,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -186,7 +186,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
table! {
|
table! {
|
||||||
activity (id) {
|
activity (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
ap_id -> Text,
|
|
||||||
data -> Jsonb,
|
data -> Jsonb,
|
||||||
local -> Bool,
|
local -> Bool,
|
||||||
sensitive -> Bool,
|
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
updated -> Nullable<Timestamp>,
|
updated -> Nullable<Timestamp>,
|
||||||
|
ap_id -> Nullable<Text>,
|
||||||
|
sensitive -> Nullable<Bool>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,8 +149,8 @@ table! {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
user_id -> Int4,
|
user_id -> Int4,
|
||||||
pending -> Bool,
|
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
|
pending -> Nullable<Bool>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -96,7 +96,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -125,7 +125,7 @@ mod tests {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
5
test.sh
5
test.sh
|
@ -2,4 +2,7 @@
|
||||||
export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
||||||
diesel migration run
|
diesel migration run
|
||||||
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
||||||
RUST_TEST_THREADS=1 cargo test --workspace --no-fail-fast
|
# Integration tests only work on stable due to a bug in config-rs
|
||||||
|
# https://github.com/mehcode/config-rs/issues/158
|
||||||
|
RUST_BACKTRACE=1 RUST_TEST_THREADS=1 \
|
||||||
|
cargo +stable test --workspace --no-fail-fast
|
||||||
|
|
|
@ -16,16 +16,8 @@ use diesel::{
|
||||||
PgConnection,
|
PgConnection,
|
||||||
};
|
};
|
||||||
use http_signature_normalization_actix::PrepareVerifyError;
|
use http_signature_normalization_actix::PrepareVerifyError;
|
||||||
use lemmy_db::{
|
use lemmy_api::match_websocket_operation;
|
||||||
community::{Community, CommunityForm},
|
use lemmy_apub::{
|
||||||
user::{User_, *},
|
|
||||||
Crud,
|
|
||||||
ListingType,
|
|
||||||
SortType,
|
|
||||||
};
|
|
||||||
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
|
|
||||||
use lemmy_server::{
|
|
||||||
apub::{
|
|
||||||
activity_queue::create_activity_queue,
|
activity_queue::create_activity_queue,
|
||||||
inbox::{
|
inbox::{
|
||||||
community_inbox,
|
community_inbox,
|
||||||
|
@ -35,11 +27,17 @@ use lemmy_server::{
|
||||||
user_inbox,
|
user_inbox,
|
||||||
user_inbox::user_inbox,
|
user_inbox::user_inbox,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
websocket::chat_server::ChatServer,
|
|
||||||
LemmyContext,
|
|
||||||
};
|
};
|
||||||
|
use lemmy_db::{
|
||||||
|
community::{Community, CommunityForm},
|
||||||
|
user::{User_, *},
|
||||||
|
Crud,
|
||||||
|
ListingType,
|
||||||
|
SortType,
|
||||||
|
};
|
||||||
|
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
|
||||||
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};
|
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};
|
||||||
|
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -61,11 +59,12 @@ fn create_context() -> LemmyContext {
|
||||||
let chat_server = ChatServer::startup(
|
let chat_server = ChatServer::startup(
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
rate_limiter.clone(),
|
rate_limiter.clone(),
|
||||||
|
|c, i, o, d| Box::pin(match_websocket_operation(c, i, o, d)),
|
||||||
Client::default(),
|
Client::default(),
|
||||||
activity_queue.clone(),
|
activity_queue.clone(),
|
||||||
)
|
)
|
||||||
.start();
|
.start();
|
||||||
LemmyContext::new(
|
LemmyContext::create(
|
||||||
pool,
|
pool,
|
||||||
chat_server,
|
chat_server,
|
||||||
Client::default(),
|
Client::default(),
|
||||||
|
@ -84,7 +83,7 @@ fn create_user(conn: &PgConnection, name: &str) -> User_ {
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: Some(false),
|
||||||
updated: None,
|
updated: None,
|
||||||
published: None,
|
published: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -177,7 +176,7 @@ async fn test_user_inbox_expired_signature() {
|
||||||
let connection = &context.pool().get().unwrap();
|
let connection = &context.pool().get().unwrap();
|
||||||
let user = create_user(connection, "user_inbox_cgsax");
|
let user = create_user(connection, "user_inbox_cgsax");
|
||||||
let activity =
|
let activity =
|
||||||
create_activity::<CreateType, ActorAndObject<user_inbox::ValidTypes>>(user.actor_id);
|
create_activity::<CreateType, ActorAndObject<user_inbox::UserValidTypes>>(user.actor_id);
|
||||||
let path = Path::<String> {
|
let path = Path::<String> {
|
||||||
0: "username".to_string(),
|
0: "username".to_string(),
|
||||||
};
|
};
|
||||||
|
@ -196,8 +195,9 @@ async fn test_community_inbox_expired_signature() {
|
||||||
let user = create_user(connection, "community_inbox_hrxa");
|
let user = create_user(connection, "community_inbox_hrxa");
|
||||||
let community = create_community(connection, user.id);
|
let community = create_community(connection, user.id);
|
||||||
let request = create_http_request();
|
let request = create_http_request();
|
||||||
let activity =
|
let activity = create_activity::<FollowType, ActorAndObject<community_inbox::CommunityValidTypes>>(
|
||||||
create_activity::<FollowType, ActorAndObject<community_inbox::ValidTypes>>(user.actor_id);
|
user.actor_id,
|
||||||
|
);
|
||||||
let path = Path::<String> { 0: community.name };
|
let path = Path::<String> { 0: community.name };
|
||||||
let response = community_inbox(request, activity, path, web::Data::new(context)).await;
|
let response = community_inbox(request, activity, path, web::Data::new(context)).await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue