From fa4a9c65db3a0e7fb2ace98281c38127c73a08b5 Mon Sep 17 00:00:00 2001 From: aumetra Date: Sat, 25 Nov 2023 16:32:33 +0100 Subject: [PATCH] fix tests --- crates/kitsune-activitypub/src/fetcher/actor.rs | 2 +- crates/kitsune-activitypub/src/fetcher/mod.rs | 2 +- .../kitsune-activitypub/tests/fetcher/basic.rs | 16 ++++++++++------ .../kitsune-activitypub/tests/fetcher/filter.rs | 6 +++--- .../tests/fetcher/infinite.rs | 2 +- .../kitsune-activitypub/tests/fetcher/origin.rs | 6 +++--- .../tests/fetcher/webfinger.rs | 10 ++++++---- crates/kitsune-federation/src/lib.rs | 2 +- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/crates/kitsune-activitypub/src/fetcher/actor.rs b/crates/kitsune-activitypub/src/fetcher/actor.rs index 14b108f20..798c7ab00 100644 --- a/crates/kitsune-activitypub/src/fetcher/actor.rs +++ b/crates/kitsune-activitypub/src/fetcher/actor.rs @@ -35,7 +35,7 @@ where ) -> Result> { // Obviously we can't hit the cache nor the database if we wanna refetch the actor if !opts.refetch { - if let Some(user) = self.user_cache.get(opts.url).await? { + if let Some(user) = self.account_cache.get(opts.url).await? { return Ok(Some(user)); } diff --git a/crates/kitsune-activitypub/src/fetcher/mod.rs b/crates/kitsune-activitypub/src/fetcher/mod.rs index 082b485df..f193177d9 100644 --- a/crates/kitsune-activitypub/src/fetcher/mod.rs +++ b/crates/kitsune-activitypub/src/fetcher/mod.rs @@ -50,8 +50,8 @@ where resolver: R, // Caches + account_cache: ArcCache, post_cache: ArcCache, - user_cache: ArcCache, } impl Fetcher diff --git a/crates/kitsune-activitypub/tests/fetcher/basic.rs b/crates/kitsune-activitypub/tests/fetcher/basic.rs index dc4fc8a27..a90c819b5 100644 --- a/crates/kitsune-activitypub/tests/fetcher/basic.rs +++ b/crates/kitsune-activitypub/tests/fetcher/basic.rs @@ -37,14 +37,15 @@ async fn fetch_actor() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); let user = fetcher .fetch_account("https://corteximplant.com/users/0x0".into()) .await - .expect("Fetch actor"); + .expect("Fetch actor") + .unwrap(); assert_eq!(user.username, "0x0"); assert_eq!(user.domain, "corteximplant.com"); @@ -75,14 +76,15 @@ async fn fetch_emoji() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); let emoji = fetcher .fetch_emoji("https://corteximplant.com/emojis/7952") .await - .expect("Fetch emoji"); + .expect("Fetch emoji") + .unwrap(); assert_eq!(emoji.shortcode, "Blobhaj"); assert_eq!(emoji.domain, Some(String::from("corteximplant.com"))); @@ -126,14 +128,16 @@ async fn fetch_note() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); let note = fetcher .fetch_post("https://corteximplant.com/@0x0/109501674056556919") .await - .expect("Fetch note"); + .expect("Fetch note") + .unwrap(); + assert_eq!( note.url, "https://corteximplant.com/users/0x0/statuses/109501674056556919" diff --git a/crates/kitsune-activitypub/tests/fetcher/filter.rs b/crates/kitsune-activitypub/tests/fetcher/filter.rs index 68f6a8c4f..8e55af900 100644 --- a/crates/kitsune-activitypub/tests/fetcher/filter.rs +++ b/crates/kitsune-activitypub/tests/fetcher/filter.rs @@ -26,8 +26,8 @@ async fn federation_allow() { .unwrap(), ) .search_backend(NoopSearchService) - .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())); + .account_cache(Arc::new(NoopCache.into())) + .post_cache(Arc::new(NoopCache.into())); let client = service_fn( #[allow(unreachable_code)] // https://github.com/rust-lang/rust/issues/67227 @@ -94,8 +94,8 @@ async fn federation_deny() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); assert!(matches!( diff --git a/crates/kitsune-activitypub/tests/fetcher/infinite.rs b/crates/kitsune-activitypub/tests/fetcher/infinite.rs index 6151d4c82..5f65e5ac8 100644 --- a/crates/kitsune-activitypub/tests/fetcher/infinite.rs +++ b/crates/kitsune-activitypub/tests/fetcher/infinite.rs @@ -105,8 +105,8 @@ async fn fetch_infinitely_long_reply_chain() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); assert!(fetcher diff --git a/crates/kitsune-activitypub/tests/fetcher/origin.rs b/crates/kitsune-activitypub/tests/fetcher/origin.rs index 9d9e7b52d..85e2d8582 100644 --- a/crates/kitsune-activitypub/tests/fetcher/origin.rs +++ b/crates/kitsune-activitypub/tests/fetcher/origin.rs @@ -27,8 +27,8 @@ async fn check_ap_id_authority() { .unwrap(), ) .search_backend(NoopSearchService) - .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())); + .account_cache(Arc::new(NoopCache.into())) + .post_cache(Arc::new(NoopCache.into())); let client = service_fn(|req: Request<_>| { assert_ne!(req.uri().host(), Some("corteximplant.com")); @@ -94,8 +94,8 @@ async fn check_ap_content_type() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); assert!(matches!( diff --git a/crates/kitsune-activitypub/tests/fetcher/webfinger.rs b/crates/kitsune-activitypub/tests/fetcher/webfinger.rs index 9302bb2a0..42ca9a555 100644 --- a/crates/kitsune-activitypub/tests/fetcher/webfinger.rs +++ b/crates/kitsune-activitypub/tests/fetcher/webfinger.rs @@ -57,14 +57,15 @@ async fn fetch_actor_with_custom_acct() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); let user = fetcher .fetch_account("https://corteximplant.com/users/0x0".into()) .await - .expect("Fetch actor"); + .expect("Fetch actor") + .unwrap(); assert_eq!(user.username, "0x0"); assert_eq!(user.domain, "joinkitsune.org"); @@ -134,14 +135,15 @@ async fn ignore_fake_webfinger_acct() { ) .search_backend(NoopSearchService) .resolver(Webfinger::with_client(client, Arc::new(NoopCache.into()))) + .account_cache(Arc::new(NoopCache.into())) .post_cache(Arc::new(NoopCache.into())) - .user_cache(Arc::new(NoopCache.into())) .build(); let user = fetcher .fetch_account("https://corteximplant.com/users/0x0".into()) .await - .expect("Fetch actor"); + .expect("Fetch actor") + .unwrap(); assert_eq!(user.username, "0x0"); assert_eq!(user.domain, "corteximplant.com"); diff --git a/crates/kitsune-federation/src/lib.rs b/crates/kitsune-federation/src/lib.rs index 060cacf85..228bca7ac 100644 --- a/crates/kitsune-federation/src/lib.rs +++ b/crates/kitsune-federation/src/lib.rs @@ -65,13 +65,13 @@ impl Fetcher for AnyFetcher { fn prepare_activitypub() -> (ActivityPubFetcher, Arc) { let webfinger = Webfinger::new(); let fetcher = ActivityPubFetcher::builder() + .account_cache() .db_pool() .embed_client() .federation_filter() .post_cache() .resolver(webfinger) .search_backend() - .user_cache() .build(); let core_deliverer = kitsune_activitypub::CoreDeliverer::builder()