Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 25, 2023
1 parent 350ee40 commit fa4a9c6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/src/fetcher/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
) -> Result<Option<Account>> {
// 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));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ where
resolver: R,

// Caches
account_cache: ArcCache<str, Account>,
post_cache: ArcCache<str, Post>,
user_cache: ArcCache<str, Account>,
}

impl<R> Fetcher<R>
Expand Down
16 changes: 10 additions & 6 deletions crates/kitsune-activitypub/tests/fetcher/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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")));
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-activitypub/tests/fetcher/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/tests/fetcher/infinite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-activitypub/tests/fetcher/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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!(
Expand Down
10 changes: 6 additions & 4 deletions crates/kitsune-activitypub/tests/fetcher/webfinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-federation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ impl Fetcher for AnyFetcher {
fn prepare_activitypub() -> (ActivityPubFetcher<Webfinger>, Arc<ActivityPubDeliverer>) {
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()
Expand Down

0 comments on commit fa4a9c6

Please sign in to comment.