Skip to content

Commit 627559b

Browse files
feat(api): Validate Auth Tokens client-side (#1885)
Perform client-side validation of all Auth Tokens input to the Sentry CLI. To ensure future-compatibility, we only provide soft validation, meaning that we only print a warning message if we detect that the Auth Token is invalid – the CLI will still proceed with normal execution if the Auth Token is invalid. Fixes GH-1859
1 parent e49cd05 commit 627559b

21 files changed

+623
-81
lines changed

Cargo.lock

Lines changed: 162 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ prettytable-rs = "0.10.0"
5454
proguard = { version = "5.0.0", features = ["uuid"] }
5555
r2d2 = "0.8.10"
5656
rayon = "1.6.1"
57-
regex = "1.7.1"
57+
regex = "1.7.3"
5858
runas = "1.0.0"
5959
rust-ini = "0.18.0"
6060
semver = "1.0.16"
@@ -83,7 +83,9 @@ chrono-tz = "0.8.4"
8383
insta = { version = "1.26.0", features = ["redactions", "yaml"] }
8484
mockito = "0.31.1"
8585
predicates = "2.1.5"
86+
rstest = "0.18.2"
8687
tempfile = "3.8.1"
88+
testing_logger = "0.1.1"
8789
trycmd = "0.14.11"
8890

8991
[features]

src/commands/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn make_command(command: Command) -> Command {
2020

2121
fn update_config(config: &Config, token: &str) -> Result<()> {
2222
let mut new_cfg = config.clone();
23-
new_cfg.set_auth(Auth::Token(token.to_string()))?;
23+
new_cfg.set_auth(Auth::Token(token.into()))?;
2424
new_cfg.save()?;
2525
Ok(())
2626
}
@@ -68,7 +68,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
6868
};
6969

7070
let test_cfg = config.make_copy(|cfg| {
71-
cfg.set_auth(Auth::Token(token.to_string()))?;
71+
cfg.set_auth(Auth::Token(token.clone().into()))?;
7272
Ok(())
7373
})?;
7474

src/commands/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use log::{debug, info, set_logger, set_max_level, LevelFilter};
1212
use crate::api::Api;
1313
use crate::config::{Auth, Config};
1414
use crate::constants::{ARCH, PLATFORM, VERSION};
15+
use crate::utils::auth_token::AuthToken;
1516
use crate::utils::logging::set_quiet_mode;
1617
use crate::utils::logging::Logger;
1718
use crate::utils::system::{init_backtrace, load_dotenv, print_error, QuietExit};
@@ -107,7 +108,7 @@ fn configure_args(config: &mut Config, matches: &ArgMatches) -> Result<()> {
107108
config.set_auth(Auth::Key(api_key.to_owned()))?;
108109
}
109110

110-
if let Some(auth_token) = matches.get_one::<String>("auth_token") {
111+
if let Some(auth_token) = matches.get_one::<AuthToken>("auth_token") {
111112
config.set_auth(Auth::Token(auth_token.to_owned()))?;
112113
}
113114

@@ -161,6 +162,7 @@ fn app() -> Command {
161162
.value_name("AUTH_TOKEN")
162163
.long("auth-token")
163164
.global(true)
165+
.value_parser(value_parser!(AuthToken))
164166
.help("Use the given Sentry auth token."),
165167
)
166168
.arg(

0 commit comments

Comments
 (0)