@@ -1337,12 +1337,150 @@ mod for_authenticated_users {
1337
1337
}
1338
1338
1339
1339
#[ tokio:: test]
1340
- async fn it_should_allow_admin_users_to_get_torrent_details_searching_by_info_hash ( ) {
1340
+ async fn it_should_allow_admin_users_to_get_torrent_details_searching_by_info_hash_using_a_public_tracker ( ) {
1341
1341
let mut env = TestEnv :: new ( ) ;
1342
1342
env. start ( api:: Version :: V1 ) . await ;
1343
1343
1344
- if !env. provides_a_tracker ( ) {
1345
- println ! ( "test skipped. It requires a tracker to be running." ) ;
1344
+ if !env. provides_a_public_tracker ( ) {
1345
+ println ! ( "test skipped. It requires a public tracker to be running." ) ;
1346
+ return ;
1347
+ }
1348
+
1349
+ let uploader = new_logged_in_user ( & env) . await ;
1350
+ let ( test_torrent, uploaded_torrent) = upload_random_torrent_to_index ( & uploader, & env) . await ;
1351
+
1352
+ let logged_in_admin = new_logged_in_admin ( & env) . await ;
1353
+
1354
+ let client = Client :: authenticated ( & env. server_socket_addr ( ) . unwrap ( ) , & logged_in_admin. token ) ;
1355
+
1356
+ let response = client. get_torrent ( & test_torrent. file_info_hash ( ) ) . await ;
1357
+
1358
+ let torrent_details_response: TorrentDetailsResponse = serde_json:: from_str ( & response. body ) . unwrap ( ) ;
1359
+
1360
+ let tracker_url = env. server_settings ( ) . unwrap ( ) . tracker . url . to_string ( ) ;
1361
+ let encoded_tracker_url = urlencoding:: encode ( & tracker_url) ;
1362
+
1363
+ let expected_torrent = TorrentDetails {
1364
+ torrent_id : uploaded_torrent. torrent_id ,
1365
+ uploader : uploader. username ,
1366
+ info_hash : test_torrent. file_info . info_hash . to_lowercase ( ) ,
1367
+ title : test_torrent. index_info . title . clone ( ) ,
1368
+ description : test_torrent. index_info . description ,
1369
+ category : Category {
1370
+ id : software_predefined_category_id ( ) ,
1371
+ name : test_torrent. index_info . category ,
1372
+ num_torrents : 19 , // Ignored in assertion
1373
+ } ,
1374
+ upload_date : "2023-04-27 07:56:08" . to_string ( ) , // Ignored in assertion
1375
+ file_size : test_torrent. file_info . content_size ,
1376
+ seeders : 0 ,
1377
+ leechers : 0 ,
1378
+ files : vec ! [ File {
1379
+ path: vec![ test_torrent. file_info. files[ 0 ] . clone( ) ] ,
1380
+ // Using one file torrent for testing: content_size = first file size
1381
+ length: test_torrent. file_info. content_size,
1382
+ md5sum: None , // DevSkim: ignore DS126858
1383
+ } ] ,
1384
+ trackers : vec ! [ tracker_url. clone( ) . to_string( ) ] ,
1385
+ magnet_link : format ! (
1386
+ // cspell:disable-next-line
1387
+ "magnet:?xt=urn:btih:{}&dn={}&tr={}" ,
1388
+ test_torrent. file_info. info_hash. to_lowercase( ) ,
1389
+ urlencoding:: encode( & test_torrent. index_info. title) ,
1390
+ encoded_tracker_url
1391
+ ) ,
1392
+ tags : vec ! [ ] ,
1393
+ name : test_torrent. index_info . name . clone ( ) ,
1394
+ comment : test_torrent. file_info . comment . clone ( ) ,
1395
+ creation_date : test_torrent. file_info . creation_date ,
1396
+ created_by : test_torrent. file_info . created_by . clone ( ) ,
1397
+ encoding : test_torrent. file_info . encoding . clone ( ) ,
1398
+ canonical_info_hash_group : vec ! [ test_torrent. file_info. info_hash. to_lowercase( ) ] ,
1399
+ } ;
1400
+
1401
+ assert_expected_torrent_details ( & torrent_details_response. data , & expected_torrent) ;
1402
+ assert ! ( response. is_json_and_ok( ) ) ;
1403
+ }
1404
+
1405
+ /* #[tokio::test]
1406
+ async fn it_should_allow_admin_users_to_get_torrent_details_searching_by_info_hash_using_a_private_tracker() {
1407
+ let mut env = TestEnv::new();
1408
+ env.start(api::Version::V1).await;
1409
+
1410
+ if !env.provides_a_private_tracker() {
1411
+ println!("test skipped. It requires a private tracker to be running.");
1412
+ return;
1413
+ }
1414
+
1415
+ let uploader = new_logged_in_user(&env).await;
1416
+ let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;
1417
+
1418
+ let logged_in_admin = new_logged_in_admin(&env).await;
1419
+
1420
+ let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token);
1421
+
1422
+ let response = client.get_torrent(&test_torrent.file_info_hash()).await;
1423
+
1424
+ let torrent_details_response: TorrentDetailsResponse = serde_json::from_str(&response.body).unwrap();
1425
+
1426
+ let tracker_url = env.server_settings().unwrap().tracker.url.to_string();
1427
+ let encoded_tracker_url = urlencoding::encode(&tracker_url);
1428
+
1429
+ let expected_torrent_info = client.get_torrent(&test_torrent.file_info.info_hash.to_lowercase()).await;
1430
+
1431
+ //expected_torrent_info.body.
1432
+
1433
+ let parsed_response = serde_json::from_str(&expected_torrent_info.body);
1434
+
1435
+ let expected_torrent = TorrentDetails {
1436
+ torrent_id: uploaded_torrent.torrent_id,
1437
+ uploader: uploader.username,
1438
+ info_hash: test_torrent.file_info.info_hash.to_lowercase(),
1439
+ title: test_torrent.index_info.title.clone(),
1440
+ description: test_torrent.index_info.description,
1441
+ category: Category {
1442
+ id: software_predefined_category_id(),
1443
+ name: test_torrent.index_info.category,
1444
+ num_torrents: 19, // Ignored in assertion
1445
+ },
1446
+ upload_date: "2023-04-27 07:56:08".to_string(), // Ignored in assertion
1447
+ file_size: test_torrent.file_info.content_size,
1448
+ seeders: 0,
1449
+ leechers: 0,
1450
+ files: vec![File {
1451
+ path: vec![test_torrent.file_info.files[0].clone()],
1452
+ // Using one file torrent for testing: content_size = first file size
1453
+ length: test_torrent.file_info.content_size,
1454
+ md5sum: None, // DevSkim: ignore DS126858
1455
+ }],
1456
+ trackers: vec![tracker_url.clone().to_string()],
1457
+ magnet_link: format!(
1458
+ // cspell:disable-next-line
1459
+ "magnet:?xt=urn:btih:{}&dn={}&tr={}",
1460
+ test_torrent.file_info.info_hash.to_lowercase(),
1461
+ urlencoding::encode(&test_torrent.index_info.title),
1462
+ encoded_tracker_url
1463
+ ),
1464
+ tags: vec![],
1465
+ name: test_torrent.index_info.name.clone(),
1466
+ comment: test_torrent.file_info.comment.clone(),
1467
+ creation_date: test_torrent.file_info.creation_date,
1468
+ created_by: test_torrent.file_info.created_by.clone(),
1469
+ encoding: test_torrent.file_info.encoding.clone(),
1470
+ canonical_info_hash_group: vec![test_torrent.file_info.info_hash.to_lowercase()],
1471
+ };
1472
+
1473
+ assert_expected_torrent_details(&torrent_details_response.data, &expected_torrent);
1474
+ assert!(response.is_json_and_ok());
1475
+ } */
1476
+
1477
+ #[ tokio:: test]
1478
+ async fn it_should_allow_admin_users_to_get_torrent_details_searching_by_info_hash_using_a_private_tracker ( ) {
1479
+ let mut env = TestEnv :: new ( ) ;
1480
+ env. start ( api:: Version :: V1 ) . await ;
1481
+
1482
+ if !env. provides_a_private_tracker ( ) {
1483
+ println ! ( "test skipped. It requires a private tracker to be running." ) ;
1346
1484
return ;
1347
1485
}
1348
1486
@@ -1583,7 +1721,7 @@ mod for_authenticated_users {
1583
1721
env. start ( api:: Version :: V1 ) . await ;
1584
1722
1585
1723
if !env. provides_a_private_tracker ( ) {
1586
- println ! ( "test skipped. It requires a public tracker to be running." ) ;
1724
+ println ! ( "test skipped. It requires a private tracker to be running." ) ;
1587
1725
return ;
1588
1726
}
1589
1727
0 commit comments