Skip to content

Commit 83ccc7e

Browse files
feat(auth): Recognize new format user tokens
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 cdf3ebb commit 83ccc7e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
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)]
78
pub struct UserAuthToken(String);
89

910
impl UserAuthToken {
11+
/// Returns the secret portion of the auth token. This is the token without the sntryu_ prefix, if present.
12+
fn secret_portion(auth_str: &str) -> &str {
13+
if auth_str.starts_with(USER_TOKEN_PREFIX) {
14+
&auth_str[USER_TOKEN_PREFIX.len()..]
15+
} else {
16+
auth_str
17+
}
18+
}
19+
1020
/// Constructs a new UserAuthToken from a string. Returns an error if the string is not a valid user auth token.
1121
fn construct_from_string(auth_string: String) -> Result<Self> {
12-
let bytes = data_encoding::HEXLOWER_PERMISSIVE.decode(auth_string.as_bytes());
22+
let bytes = data_encoding::HEXLOWER_PERMISSIVE
23+
.decode(Self::secret_portion(&auth_string).as_bytes());
1324

1425
if bytes.is_ok() && bytes.unwrap().len() == USER_TOKEN_BYTES {
1526
Ok(UserAuthToken(auth_string))

0 commit comments

Comments
 (0)