Skip to content

Commit 215f1c9

Browse files
feat(auth): Recognize new format user tokens (#2100)
getsentry/sentry#68148 changed user auth tokens, so that they now start with a sntryu_ prefix. While the CLI correctly handles these new tokens, the CLI issued a warning when using these new format tokens. This PR updates the CLI's auth token parsing logic to recognize the new user auth token format (in addition to the old format), so that the warning is no longer issued.
1 parent 98ba434 commit 215f1c9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/utils/auth_token/test.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ fn test_valid_org_auth_token_missing_url() {
6767

6868
// User auth token tests ----------------------------------------------------
6969

70-
#[test]
71-
fn test_valid_user_auth_token() {
72-
let good_token =
73-
String::from("c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c30");
70+
#[rstest]
71+
#[case::no_prefix("c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c30")]
72+
#[case::with_prefix("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")]
73+
fn test_valid_user_auth_token(#[case] token_str: &'static str) {
74+
let good_token = String::from(token_str);
7475

7576
testing_logger::setup();
7677
let token = AuthToken::from(good_token.clone());
@@ -138,6 +139,11 @@ fn test_valid_user_auth_token() {
138139
#[case::invalid_hex("c66aee1348a6g7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c30")]
139140
#[case::sixty_three_characters("c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c3")]
140141
#[case::sixty_five_characters("c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c300")]
142+
#[case::prefix_only("sntryu_")]
143+
#[case::prefix_sixty_three_characters(
144+
"sntryu_c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c3"
145+
)]
146+
#[case::wrong_prefix("sntryt_c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c30")]
141147
fn test_unknown_auth_token(#[case] token_str: &'static str) {
142148
testing_logger::setup();
143149
let token = AuthToken::from(token_str.to_owned());

src/utils/auth_token/user_auth_token.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{AuthTokenParseError, Result};
22

33
const USER_TOKEN_BYTES: usize = 32;
4+
const USER_TOKEN_PREFIX: &str = "sntryu_";
45

56
/// Represents a valid User Auth Token.
67
#[derive(Debug, Clone)]
@@ -9,7 +10,11 @@ pub struct UserAuthToken(String);
910
impl UserAuthToken {
1011
/// Constructs a new UserAuthToken from a string. Returns an error if the string is not a valid user auth token.
1112
fn construct_from_string(auth_string: String) -> Result<Self> {
12-
let bytes = data_encoding::HEXLOWER_PERMISSIVE.decode(auth_string.as_bytes());
13+
let secret_portion = auth_string
14+
.strip_prefix(USER_TOKEN_PREFIX)
15+
.unwrap_or(&auth_string);
16+
17+
let bytes = data_encoding::HEXLOWER_PERMISSIVE.decode(secret_portion.as_bytes());
1318

1419
if bytes.is_ok() && bytes.unwrap().len() == USER_TOKEN_BYTES {
1520
Ok(UserAuthToken(auth_string))

0 commit comments

Comments
 (0)