Skip to content
Closed
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Ignore trailing slashes when comparing the configured URL with the auth token's embedded URL, removing a spurious conflict warning ([#3420](https://github.com/getsentry/sentry-cli/pull/3420))

## 3.8.0

### Improvements
Expand Down
32 changes: 31 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ fn merge_config_source(base: &mut Ini, overlay: &Ini) -> Option<DiscardedAuthUrl

fn warn_about_conflicting_urls(token_url: &str, manually_configured_url: Option<&str>) {
if let Some(manually_configured_url) = manually_configured_url {
if manually_configured_url != token_url {
if !urls_equivalent(token_url, manually_configured_url) {
warn!(
"Using {token_url} (embedded in token) rather than manually-configured URL \
{manually_configured_url}. To use {manually_configured_url}, please provide an \
Expand All @@ -781,6 +781,12 @@ fn warn_about_conflicting_urls(token_url: &str, manually_configured_url: Option<
}
}

/// Returns whether two URLs refer to the same Sentry instance, ignoring
/// trailing slashes (`https://sentry.io` and `https://sentry.io/` are equal).
fn urls_equivalent(a: &str, b: &str) -> bool {
a.trim_end_matches('/') == b.trim_end_matches('/')
}

fn find_global_config_file() -> Result<PathBuf> {
let home_dir_file = dirs::home_dir().map(|p| p.join(CONFIG_RC_FILE_NAME));
let config_dir_file = dirs::config_dir().map(|p| p.join(CONFIG_INI_FILE_PATH));
Expand Down Expand Up @@ -1085,4 +1091,28 @@ mod tests {
"https://us.sentry.io/api/0/organizations/test-org/chunk-upload/"
);
}

#[test]
fn urls_equivalent_ignores_trailing_slashes() {
assert!(urls_equivalent("https://sentry.io", "https://sentry.io/"));
assert!(urls_equivalent("https://sentry.io/", "https://sentry.io"));
assert!(urls_equivalent("https://sentry.io", "https://sentry.io"));
assert!(urls_equivalent(
"http://localhost:8000",
"http://localhost:8000/"
));
}

#[test]
fn urls_equivalent_detects_different_urls() {
assert!(!urls_equivalent(
"https://sentry.io",
"https://us.sentry.io"
));
assert!(!urls_equivalent(
"https://sentry.io",
"https://sentry.io.evil.com"
));
assert!(!urls_equivalent("https://sentry.io", "http://sentry.io/"));
}
}