Skip to content

Commit

Permalink
fix: Strip /api/0 prefix from endpoint URLs (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored Sep 22, 2023
1 parent 7d2652b commit 3ef1c6b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ impl Config {
/// Returns the API URL for a path
pub fn get_api_endpoint(&self, path: &str) -> Result<String> {
let base = self.get_base_url()?;
Ok(format!("{}/api/0/{}", base, path.trim_start_matches('/')))
let path = path.trim_start_matches('/');
let path = path.trim_start_matches("api/0/");
Ok(format!("{}/api/0/{}", base, path))
}

/// Returns the log level.
Expand Down Expand Up @@ -749,6 +751,8 @@ fn get_default_vcs_remote(ini: &Ini) -> String {

#[cfg(test)]
mod tests {
use log::LevelFilter;

use super::*;

#[test]
Expand All @@ -763,4 +767,33 @@ mod tests {
}
);
}

#[test]
fn test_get_api_endpoint() {
let config = Config {
filename: PathBuf::from("/path/to/config"),
process_bound: false,
ini: Default::default(),
cached_auth: None,
cached_base_url: "https://sentry.io/".to_string(),
cached_headers: None,
cached_log_level: LevelFilter::Off,
cached_vcs_remote: String::new(),
cached_token_data: None,
};

assert_eq!(
config
.get_api_endpoint("/organizations/test-org/chunk-upload/")
.unwrap(),
"https://sentry.io/api/0/organizations/test-org/chunk-upload/"
);

assert_eq!(
config
.get_api_endpoint("/api/0/organizations/test-org/chunk-upload/")
.unwrap(),
"https://sentry.io/api/0/organizations/test-org/chunk-upload/"
);
}
}

0 comments on commit 3ef1c6b

Please sign in to comment.