Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/http/axum_implementation/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::tracker::error::Error;
pub mod announce;
pub mod auth;
pub mod scrape;
pub mod status;

impl From<Error> for responses::error::Error {
fn from(err: Error) -> Self {
Expand Down
12 changes: 0 additions & 12 deletions src/http/axum_implementation/handlers/status.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/http/axum_implementation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod extractors;
pub mod handlers;
pub mod query;
pub mod requests;
pub mod resources;
pub mod responses;
pub mod routes;
pub mod server;
Expand Down
1 change: 0 additions & 1 deletion src/http/axum_implementation/resources/mod.rs

This file was deleted.

8 changes: 0 additions & 8 deletions src/http/axum_implementation/resources/ok.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/http/axum_implementation/responses/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod announce;
pub mod error;
pub mod ok;
pub mod scrape;
11 changes: 0 additions & 11 deletions src/http/axum_implementation/responses/ok.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/http/axum_implementation/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ use axum::routing::get;
use axum::Router;
use axum_client_ip::SecureClientIpSource;

use super::handlers::{announce, scrape, status};
use super::handlers::{announce, scrape};
use crate::tracker::Tracker;

pub fn router(tracker: &Arc<Tracker>) -> Router {
Router::new()
// Status
.route("/status", get(status::handle))
// Announce request
.route("/announce", get(announce::handle_without_key).with_state(tracker.clone()))
.route("/announce/:key", get(announce::handle_with_key).with_state(tracker.clone()))
Expand Down
139 changes: 1 addition & 138 deletions tests/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// cargo test `warp_http_tracker_server` -- --nocapture
/// ```
///
/// Axum version ()WIP):
/// Axum version (WIP):
/// ```text
/// cargo test `warp_http_tracker_server` -- --nocapture
/// ```
Expand Down Expand Up @@ -1271,143 +1271,6 @@ mod axum_http_tracker_server {

// WIP: migration HTTP from Warp to Axum

use local_ip_address::local_ip;
use torrust_tracker::http::axum_implementation::extractors::remote_client_ip::RemoteClientIp;
use torrust_tracker::http::axum_implementation::resources::ok::Ok;
use torrust_tracker::http::Version;

use crate::http::client::Client;
use crate::http::server::start_default_http_tracker;

#[tokio::test]
async fn should_return_the_status() {
// This is a temporary test to test the new Axum HTTP tracker server scaffolding

let http_tracker_server = start_default_http_tracker(Version::Axum).await;

let client_ip = local_ip().unwrap();

let response = Client::bind(http_tracker_server.get_connection_info(), client_ip)
.get("status")
.await;

let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();

assert_eq!(
ok,
Ok {
remote_client_ip: RemoteClientIp {
right_most_x_forwarded_for: None,
connection_info_ip: Some(client_ip)
}
}
);
}

mod should_get_the_remote_client_ip_from_the_http_request {

// Temporary tests to test that the new Axum HTTP tracker gets the right remote client IP.
// Once the implementation is finished, test for announce request will cover these cases.

use std::net::IpAddr;
use std::str::FromStr;

use local_ip_address::local_ip;
use torrust_tracker::http::axum_implementation::extractors::remote_client_ip::RemoteClientIp;
use torrust_tracker::http::axum_implementation::resources::ok::Ok;
use torrust_tracker::http::Version;

use crate::http::client::Client;
use crate::http::server::{start_http_tracker_on_reverse_proxy, start_public_http_tracker};

#[tokio::test]
async fn when_the_client_ip_is_a_local_ip_it_should_assign_that_ip() {
let http_tracker_server = start_public_http_tracker(Version::Axum).await;

let client_ip = local_ip().unwrap();

let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);

let response = client.get("status").await;

let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();

assert_eq!(
ok,
Ok {
remote_client_ip: RemoteClientIp {
right_most_x_forwarded_for: None,
connection_info_ip: Some(client_ip)
}
}
);
}

#[tokio::test]
async fn when_the_client_ip_is_a_loopback_ipv4_it_should_assign_that_ip() {
let http_tracker_server = start_public_http_tracker(Version::Axum).await;

let loopback_ip = IpAddr::from_str("127.0.0.1").unwrap();
let client_ip = loopback_ip;

let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);

let response = client.get("status").await;

let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();

assert_eq!(
ok,
Ok {
remote_client_ip: RemoteClientIp {
right_most_x_forwarded_for: None,
connection_info_ip: Some(client_ip)
}
}
);
}

#[tokio::test]
async fn when_the_tracker_is_behind_a_reverse_proxy_it_should_assign_as_secure_ip_the_right_most_ip_in_the_x_forwarded_for_http_header(
) {
/*
client <-> http proxy <-> tracker <-> Internet
ip: header: config: remote client ip:
145.254.214.256 X-Forwarded-For = 145.254.214.256 on_reverse_proxy = true 145.254.214.256
*/

let http_tracker_server = start_http_tracker_on_reverse_proxy(Version::Axum).await;

let loopback_ip = IpAddr::from_str("127.0.0.1").unwrap();
let client_ip = loopback_ip;

let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);

let left_most_ip = IpAddr::from_str("203.0.113.195").unwrap();
let right_most_ip = IpAddr::from_str("150.172.238.178").unwrap();

let response = client
.get_with_header(
"status",
"X-Forwarded-For",
&format!("{left_most_ip},2001:db8:85a3:8d3:1319:8a2e:370:7348,{right_most_ip}"),
)
.await;

let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();

assert_eq!(
ok,
Ok {
remote_client_ip: RemoteClientIp {
right_most_x_forwarded_for: Some(right_most_ip),
connection_info_ip: Some(client_ip)
}
}
);
}
}

mod for_all_config_modes {

mod and_running_on_reverse_proxy {
Expand Down