Skip to content

Commit f6bbcf5

Browse files
committed
Merge #1007: Remove default configuration values for secrets
6a707b9 fix: linter errors (Jose Celano) f5e38bb feat!: [#1006] remove config deafults for secrets (Jose Celano) Pull request description: Remove default configuration values for secrets. To avoid running the tracker unintentionally with known values. ACKs for top commit: josecelano: ACK 6a707b9 Tree-SHA512: 4360ad36f97afcc21307d2f945ca73dc40ef08a96406c40ac4b9e856756e1b3ca0464b99e34b6843013bfb393d46ede618d49c000fdb386829a450b61d6e44f0
2 parents eaa86a7 + 6a707b9 commit f6bbcf5

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

packages/configuration/src/v2_0_0/tracker_api.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ impl HttpApi {
5252
}
5353

5454
fn default_access_tokens() -> AccessTokens {
55-
[(String::from("admin"), String::from("MyAccessToken"))]
56-
.iter()
57-
.cloned()
58-
.collect()
55+
[].iter().cloned().collect()
5956
}
6057

61-
pub fn override_admin_token(&mut self, api_admin_token: &str) {
62-
self.access_tokens.insert("admin".to_string(), api_admin_token.to_string());
58+
pub fn add_token(&mut self, key: &str, token: &str) {
59+
self.access_tokens.insert(key.to_string(), token.to_string());
6360
}
6461

6562
pub fn mask_secrets(&mut self) {
@@ -74,10 +71,18 @@ mod tests {
7471
use crate::v2_0_0::tracker_api::HttpApi;
7572

7673
#[test]
77-
fn http_api_configuration_should_check_if_it_contains_a_token() {
74+
fn default_http_api_configuration_should_not_contains_any_token() {
7875
let configuration = HttpApi::default();
7976

77+
assert_eq!(configuration.access_tokens.values().len(), 0);
78+
}
79+
80+
#[test]
81+
fn http_api_configuration_should_allow_adding_tokens() {
82+
let mut configuration = HttpApi::default();
83+
84+
configuration.add_token("admin", "MyAccessToken");
85+
8086
assert!(configuration.access_tokens.values().any(|t| t == "MyAccessToken"));
81-
assert!(!configuration.access_tokens.values().any(|t| t == "NonExistingToken"));
8287
}
8388
}

packages/test-helpers/src/configuration.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ pub fn ephemeral() -> Configuration {
3232

3333
// Ephemeral socket address for API
3434
let api_port = 0u16;
35-
config.http_api = Some(HttpApi {
35+
let mut http_api = HttpApi {
3636
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port),
3737
..Default::default()
38-
});
38+
};
39+
http_api.add_token("admin", "MyAccessToken");
40+
config.http_api = Some(http_api);
3941

4042
// Ephemeral socket address for Health Check API
4143
let health_check_api_port = 0u16;

src/app.rs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,53 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
6666
}
6767

6868
// Start the UDP blocks
69-
match &config.udp_trackers {
70-
Some(udp_trackers) => {
71-
for udp_tracker_config in udp_trackers {
72-
if tracker.is_private() {
73-
warn!(
74-
"Could not start UDP tracker on: {} while in private mode. UDP is not safe for private trackers!",
75-
udp_tracker_config.bind_address
76-
);
77-
} else {
78-
jobs.push(udp_tracker::start_job(udp_tracker_config, tracker.clone(), registar.give_form()).await);
79-
}
69+
if let Some(udp_trackers) = &config.udp_trackers {
70+
for udp_tracker_config in udp_trackers {
71+
if tracker.is_private() {
72+
warn!(
73+
"Could not start UDP tracker on: {} while in private mode. UDP is not safe for private trackers!",
74+
udp_tracker_config.bind_address
75+
);
76+
} else {
77+
jobs.push(udp_tracker::start_job(udp_tracker_config, tracker.clone(), registar.give_form()).await);
8078
}
8179
}
82-
None => info!("No UDP blocks in configuration"),
80+
} else {
81+
info!("No UDP blocks in configuration");
8382
}
8483

8584
// Start the HTTP blocks
86-
match &config.http_trackers {
87-
Some(http_trackers) => {
88-
for http_tracker_config in http_trackers {
89-
if let Some(job) = http_tracker::start_job(
90-
http_tracker_config,
91-
tracker.clone(),
92-
registar.give_form(),
93-
servers::http::Version::V1,
94-
)
95-
.await
96-
{
97-
jobs.push(job);
98-
};
99-
}
100-
}
101-
None => info!("No HTTP blocks in configuration"),
102-
}
103-
104-
// Start HTTP API
105-
match &config.http_api {
106-
Some(http_api_config) => {
107-
if let Some(job) = tracker_apis::start_job(
108-
http_api_config,
85+
if let Some(http_trackers) = &config.http_trackers {
86+
for http_tracker_config in http_trackers {
87+
if let Some(job) = http_tracker::start_job(
88+
http_tracker_config,
10989
tracker.clone(),
11090
registar.give_form(),
111-
servers::apis::Version::V1,
91+
servers::http::Version::V1,
11292
)
11393
.await
11494
{
11595
jobs.push(job);
11696
};
11797
}
118-
None => info!("No API block in configuration"),
98+
} else {
99+
info!("No HTTP blocks in configuration");
100+
}
101+
102+
// Start HTTP API
103+
if let Some(http_api_config) = &config.http_api {
104+
if let Some(job) = tracker_apis::start_job(
105+
http_api_config,
106+
tracker.clone(),
107+
registar.give_form(),
108+
servers::apis::Version::V1,
109+
)
110+
.await
111+
{
112+
jobs.push(job);
113+
};
114+
} else {
115+
info!("No API block in configuration");
119116
}
120117

121118
// Start runners to remove torrents without peers, every interval

src/console/ci/e2e/tracker_container.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,11 @@ impl TrackerContainer {
105105
///
106106
/// Will panic if it can't remove the container.
107107
pub fn remove(&self) {
108-
match &self.running {
109-
Some(_running_container) => {
110-
error!("Can't remove running container: {} ...", self.name);
111-
}
112-
None => {
113-
info!("Removing docker tracker container: {} ...", self.name);
114-
Docker::remove(&self.name).expect("Container should be removed");
115-
}
108+
if let Some(_running_container) = &self.running {
109+
error!("Can't remove running container: {} ...", self.name);
110+
} else {
111+
info!("Removing docker tracker container: {} ...", self.name);
112+
Docker::remove(&self.name).expect("Container should be removed");
116113
}
117114
}
118115

0 commit comments

Comments
 (0)