File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -67,10 +67,11 @@ fn test_valid_org_auth_token_missing_url() {
67
67
68
68
// User auth token tests ----------------------------------------------------
69
69
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) ;
74
75
75
76
testing_logger:: setup ( ) ;
76
77
let token = AuthToken :: from ( good_token. clone ( ) ) ;
@@ -138,6 +139,11 @@ fn test_valid_user_auth_token() {
138
139
#[ case:: invalid_hex( "c66aee1348a6g7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c30" ) ]
139
140
#[ case:: sixty_three_characters( "c66aee1348a6e7a0993145d71cf8fa529ed09ee13dd5177b5f692e9f6ca38c3" ) ]
140
141
#[ 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" ) ]
141
147
fn test_unknown_auth_token ( #[ case] token_str : & ' static str ) {
142
148
testing_logger:: setup ( ) ;
143
149
let token = AuthToken :: from ( token_str. to_owned ( ) ) ;
Original file line number Diff line number Diff line change 1
1
use super :: { AuthTokenParseError , Result } ;
2
2
3
3
const USER_TOKEN_BYTES : usize = 32 ;
4
+ const USER_TOKEN_PREFIX : & str = "sntryu_" ;
4
5
5
6
/// Represents a valid User Auth Token.
6
7
#[ derive( Debug , Clone ) ]
@@ -9,7 +10,11 @@ pub struct UserAuthToken(String);
9
10
impl UserAuthToken {
10
11
/// Constructs a new UserAuthToken from a string. Returns an error if the string is not a valid user auth token.
11
12
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 ( ) ) ;
13
18
14
19
if bytes. is_ok ( ) && bytes. unwrap ( ) . len ( ) == USER_TOKEN_BYTES {
15
20
Ok ( UserAuthToken ( auth_string) )
You can’t perform that action at this time.
0 commit comments