Skip to content

Commit e94e9cd

Browse files
committed
test: authorization test for guest users
1 parent 26451f9 commit e94e9cd

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
11
//! API contract for `proxy` context.
22
3-
// todo
3+
mod authorization {
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_return_an_ok_response_when_a_guest_user_tries_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, 200);
40+
}
41+
}

0 commit comments

Comments
 (0)