From 6dfd30a8ab6ca25233f0fe34d129eb54ec27becd Mon Sep 17 00:00:00 2001 From: MrKaplan <169855803+MrKaplan-lw@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:02:04 +0200 Subject: [PATCH] Add test case for http fetch limit fixed in #97 (#128) --- src/fetch/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/fetch/mod.rs b/src/fetch/mod.rs index e36e8b2..b8e9c84 100644 --- a/src/fetch/mod.rs +++ b/src/fetch/mod.rs @@ -154,3 +154,34 @@ async fn fetch_object_http_with_accept( )), } } + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + use crate::{ + config::FederationConfig, + traits::tests::{DbConnection, Person}, + }; + + #[tokio::test] + async fn test_request_limit() -> Result<(), Error> { + let config = FederationConfig::builder() + .domain("example.com") + .app_data(DbConnection) + .http_fetch_limit(0) + .build() + .await + .unwrap(); + let data = config.to_request_data(); + + let fetch_url = "https://example.net/".to_string(); + + let res: Result, Error> = + fetch_object_http(&Url::parse(&fetch_url).map_err(Error::UrlParse)?, &data).await; + + assert_eq!(res.err(), Some(Error::RequestLimit)); + + Ok(()) + } +}