@@ -23,8 +23,7 @@ mod for_guests {
23
23
use crate :: common:: client:: Client ;
24
24
use crate :: common:: contexts:: category:: fixtures:: software_predefined_category_id;
25
25
use crate :: common:: contexts:: torrent:: asserts:: assert_expected_torrent_details;
26
- use crate :: common:: contexts:: torrent:: fixtures:: { random_torrent, TestTorrent } ;
27
- use crate :: common:: contexts:: torrent:: forms:: UploadTorrentMultipartForm ;
26
+ use crate :: common:: contexts:: torrent:: fixtures:: TestTorrent ;
28
27
use crate :: common:: contexts:: torrent:: requests:: InfoHash ;
29
28
use crate :: common:: contexts:: torrent:: responses:: {
30
29
Category , File , TorrentDetails , TorrentDetailsResponse , TorrentListResponse ,
@@ -34,29 +33,6 @@ mod for_guests {
34
33
use crate :: e2e:: web:: api:: v1:: contexts:: torrent:: steps:: { upload_random_torrent_to_index, upload_test_torrent} ;
35
34
use crate :: e2e:: web:: api:: v1:: contexts:: user:: steps:: new_logged_in_user;
36
35
37
- #[ tokio:: test]
38
- async fn it_should_allow_guests_to_get_torrents ( ) {
39
- let mut env = TestEnv :: new ( ) ;
40
- env. start ( api:: Version :: V1 ) . await ;
41
-
42
- if !env. provides_a_tracker ( ) {
43
- println ! ( "test skipped. It requires a tracker to be running." ) ;
44
- return ;
45
- }
46
-
47
- let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
48
-
49
- let uploader = new_logged_in_user ( & env) . await ;
50
- let ( _test_torrent, _indexed_torrent) = upload_random_torrent_to_index ( & uploader, & env) . await ;
51
-
52
- let response = client. get_torrents ( Query :: empty ( ) ) . await ;
53
-
54
- let torrent_list_response: TorrentListResponse = serde_json:: from_str ( & response. body ) . unwrap ( ) ;
55
-
56
- assert ! ( torrent_list_response. data. total > 0 ) ;
57
- assert ! ( response. is_json_and_ok( ) ) ;
58
- }
59
-
60
36
#[ tokio:: test]
61
37
async fn it_should_allow_to_get_torrents_with_pagination ( ) {
62
38
let mut env = TestEnv :: new ( ) ;
@@ -429,40 +405,98 @@ mod for_guests {
429
405
assert_eq ! ( response. status, 404 ) ;
430
406
}
431
407
432
- #[ tokio:: test]
433
- async fn it_should_not_allow_guests_to_upload_torrents ( ) {
434
- let mut env = TestEnv :: new ( ) ;
435
- env. start ( api:: Version :: V1 ) . await ;
408
+ mod authorization {
409
+ use torrust_index:: web:: api;
436
410
437
- let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
411
+ use crate :: common:: client:: Client ;
412
+ use crate :: common:: contexts:: torrent:: fixtures:: random_torrent;
413
+ use crate :: common:: contexts:: torrent:: forms:: UploadTorrentMultipartForm ;
414
+ use crate :: common:: contexts:: torrent:: responses:: TorrentListResponse ;
415
+ use crate :: common:: http:: Query ;
416
+ use crate :: e2e:: environment:: TestEnv ;
417
+ use crate :: e2e:: web:: api:: v1:: contexts:: torrent:: steps:: upload_random_torrent_to_index;
418
+ use crate :: e2e:: web:: api:: v1:: contexts:: user:: steps:: new_logged_in_user;
438
419
439
- let test_torrent = random_torrent ( ) ;
420
+ #[ tokio:: test]
421
+ async fn it_should_not_allow_guests_to_upload_torrents ( ) {
422
+ let mut env = TestEnv :: new ( ) ;
423
+ env. start ( api:: Version :: V1 ) . await ;
440
424
441
- let form : UploadTorrentMultipartForm = test_torrent . index_info . into ( ) ;
425
+ let client = Client :: unauthenticated ( & env . server_socket_addr ( ) . unwrap ( ) ) ;
442
426
443
- let response = client . upload_torrent ( form . into ( ) ) . await ;
427
+ let test_torrent = random_torrent ( ) ;
444
428
445
- assert_eq ! ( response. status, 401 ) ;
446
- }
429
+ let form: UploadTorrentMultipartForm = test_torrent. index_info . into ( ) ;
447
430
448
- #[ tokio:: test]
449
- async fn it_should_not_allow_guests_to_delete_torrents ( ) {
450
- let mut env = TestEnv :: new ( ) ;
451
- env. start ( api:: Version :: V1 ) . await ;
431
+ let response = client. upload_torrent ( form. into ( ) ) . await ;
452
432
453
- if !env. provides_a_tracker ( ) {
454
- println ! ( "test skipped. It requires a tracker to be running." ) ;
455
- return ;
433
+ assert_eq ! ( response. status, 401 ) ;
456
434
}
457
435
458
- let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
436
+ #[ tokio:: test]
437
+ async fn it_should_not_allow_guests_to_delete_torrents ( ) {
438
+ let mut env = TestEnv :: new ( ) ;
439
+ env. start ( api:: Version :: V1 ) . await ;
459
440
460
- let uploader = new_logged_in_user ( & env) . await ;
461
- let ( test_torrent, _uploaded_torrent) = upload_random_torrent_to_index ( & uploader, & env) . await ;
441
+ if !env. provides_a_tracker ( ) {
442
+ println ! ( "test skipped. It requires a tracker to be running." ) ;
443
+ return ;
444
+ }
445
+
446
+ let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
447
+
448
+ let uploader = new_logged_in_user ( & env) . await ;
449
+ let ( test_torrent, _uploaded_torrent) = upload_random_torrent_to_index ( & uploader, & env) . await ;
450
+
451
+ let response = client. delete_torrent ( & test_torrent. file_info_hash ( ) ) . await ;
452
+
453
+ assert_eq ! ( response. status, 401 ) ;
454
+ }
455
+
456
+ #[ tokio:: test]
457
+ async fn it_should_allow_guests_to_download_a_torrent_file_searching_by_info_hash ( ) {
458
+ let mut env = TestEnv :: new ( ) ;
459
+ env. start ( api:: Version :: V1 ) . await ;
460
+
461
+ if !env. provides_a_tracker ( ) {
462
+ println ! ( "test skipped. It requires a tracker to be running." ) ;
463
+ return ;
464
+ }
465
+
466
+ let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
467
+ let uploader = new_logged_in_user ( & env) . await ;
462
468
463
- let response = client. delete_torrent ( & test_torrent. file_info_hash ( ) ) . await ;
469
+ // Upload
470
+ let ( test_torrent, _torrent_listed_in_index) = upload_random_torrent_to_index ( & uploader, & env) . await ;
471
+
472
+ // Download
473
+ let response = client. download_torrent ( & test_torrent. file_info_hash ( ) ) . await ;
474
+
475
+ assert_eq ! ( response. status, 200 ) ;
476
+ }
464
477
465
- assert_eq ! ( response. status, 401 ) ;
478
+ #[ tokio:: test]
479
+ async fn it_should_allow_guests_to_get_torrents ( ) {
480
+ let mut env = TestEnv :: new ( ) ;
481
+ env. start ( api:: Version :: V1 ) . await ;
482
+
483
+ if !env. provides_a_tracker ( ) {
484
+ println ! ( "test skipped. It requires a tracker to be running." ) ;
485
+ return ;
486
+ }
487
+
488
+ let client = Client :: unauthenticated ( & env. server_socket_addr ( ) . unwrap ( ) ) ;
489
+
490
+ let uploader = new_logged_in_user ( & env) . await ;
491
+ let ( _test_torrent, _indexed_torrent) = upload_random_torrent_to_index ( & uploader, & env) . await ;
492
+
493
+ let response = client. get_torrents ( Query :: empty ( ) ) . await ;
494
+
495
+ let torrent_list_response: TorrentListResponse = serde_json:: from_str ( & response. body ) . unwrap ( ) ;
496
+
497
+ assert ! ( torrent_list_response. data. total > 0 ) ;
498
+ assert ! ( response. is_json_and_ok( ) ) ;
499
+ }
466
500
}
467
501
}
468
502
0 commit comments