Skip to content

Commit

Permalink
feat!: [#1006] remove config deafults for secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Aug 12, 2024
1 parent eaa86a7 commit f5e38bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 13 additions & 8 deletions packages/configuration/src/v2_0_0/tracker_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ impl HttpApi {
}

fn default_access_tokens() -> AccessTokens {
[(String::from("admin"), String::from("MyAccessToken"))]
.iter()
.cloned()
.collect()
[].iter().cloned().collect()
}

pub fn override_admin_token(&mut self, api_admin_token: &str) {
self.access_tokens.insert("admin".to_string(), api_admin_token.to_string());
pub fn add_token(&mut self, key: &str, token: &str) {
self.access_tokens.insert(key.to_string(), token.to_string());
}

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

#[test]
fn http_api_configuration_should_check_if_it_contains_a_token() {
fn default_http_api_configuration_should_not_contains_any_token() {
let configuration = HttpApi::default();

assert_eq!(configuration.access_tokens.values().len(), 0);
}

#[test]
fn http_api_configuration_should_allow_adding_tokens() {
let mut configuration = HttpApi::default();

configuration.add_token("admin", "MyAccessToken");

assert!(configuration.access_tokens.values().any(|t| t == "MyAccessToken"));
assert!(!configuration.access_tokens.values().any(|t| t == "NonExistingToken"));
}
}
6 changes: 4 additions & 2 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ pub fn ephemeral() -> Configuration {

// Ephemeral socket address for API
let api_port = 0u16;
config.http_api = Some(HttpApi {
let mut http_api = HttpApi {
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port),
..Default::default()
});
};
http_api.add_token("admin", "MyAccessToken");
config.http_api = Some(http_api);

// Ephemeral socket address for Health Check API
let health_check_api_port = 0u16;
Expand Down

0 comments on commit f5e38bb

Please sign in to comment.