Skip to content

Commit 3ba38d9

Browse files
committed
wip
1 parent abc3839 commit 3ba38d9

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

tests/common/client.rs

+6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ impl Client {
177177
pub async fn ban_user(&self, username: Username) -> TextResponse {
178178
self.http_client.delete(&format!("/user/ban/{}", &username.value)).await
179179
}
180+
181+
// Context: proxy
182+
183+
pub async fn get_image_by_url(&self, url: &str) -> TextResponse {
184+
self.http_client.get(&format!("/proxy/image/{}", url), Query::empty()).await
185+
}
180186
}
181187

182188
/// Generic HTTP Client
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
11
//! API contract for `proxy` context.
22
3-
// todo
3+
mod for_guest_users {
4+
use torrust_index::web::api;
5+
6+
use crate::common::client::Client;
7+
use crate::common::contexts::torrent::fixtures::random_torrent;
8+
use crate::e2e::environment::TestEnv;
9+
use crate::e2e::web::api::v1::contexts::torrent::steps::upload_torrent;
10+
use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user;
11+
12+
#[tokio::test]
13+
async fn it_should_not_allow_guest_user_to_get_a_proxied_image_by_url() {
14+
let mut env = TestEnv::new();
15+
16+
env.start(api::Version::V1).await;
17+
18+
/* if !env.provides_a_tracker() {
19+
println!("test skipped. It requires a tracker to be running.");
20+
return;
21+
} */
22+
23+
let mut test_torrent = random_torrent();
24+
25+
test_torrent.index_info.description = String::from(
26+
"![image info](https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Zaadpluizen_van_een_Clematis_texensis_%27Princess_Diana%27._18-07-2023_%28actm.%29_02.jpg/1024px-Zaadpluizen_van_een_Clematis_texensis_%27Princess_Diana%27._18-07-2023_%28actm.%29_02.jpg)",
27+
);
28+
29+
let torrent_uploader = new_logged_in_user(&env).await;
30+
31+
upload_torrent(&torrent_uploader, &test_torrent.index_info, &env).await;
32+
33+
let client = Client::unauthenticated(&env.server_socket_addr().unwrap());
34+
35+
let url = "https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F7%2F71%2FZaadpluizen_van_een_Clematis_texensis_%2527Princess_Diana%2527._18-07-2023_%2528actm.%2529_02.jpg%2F1024px-Zaadpluizen_van_een_Clematis_texensis_%2527Princess_Diana%2527._18-07-2023_%2528actm.%2529_02.jpg";
36+
37+
let response = client.get_image_by_url(url).await;
38+
39+
assert_eq!(response.status, 401);
40+
}
41+
}

0 commit comments

Comments
 (0)