File tree Expand file tree Collapse file tree 2 files changed +32
-15
lines changed Expand file tree Collapse file tree 2 files changed +32
-15
lines changed Original file line number Diff line number Diff line change @@ -518,16 +518,20 @@ pub fn is_url_crates_io(url: &str) -> bool {
518
518
/// It would be easier to check just for alphanumeric tokens, but we can't be sure that all
519
519
/// registries only create tokens in that format so that is as less restricted as possible.
520
520
pub fn check_token ( token : & str ) -> Result < ( ) > {
521
- let is_valid = token. bytes ( ) . all ( |b| {
521
+ if token. is_empty ( ) {
522
+ bail ! ( "please provide a non-empty token" ) ;
523
+ }
524
+ if token. bytes ( ) . all ( |b| {
522
525
b >= 32 // undefined in ISO-8859-1, in ASCII/ UTF-8 not-printable character
523
526
&& b < 128 // utf-8: the first bit signals a multi-byte character
524
527
&& b != 127 // 127 is a control character in ascii and not in ISO 8859-1
525
528
|| b == b't' // tab is also allowed (even when < 32)
526
- } ) ;
527
-
528
- if is_valid {
529
+ } ) {
529
530
Ok ( ( ) )
530
531
} else {
531
- Err ( anyhow:: anyhow!( "invalid token." ) )
532
+ Err ( anyhow:: anyhow!(
533
+ "token contains invalid characters.\n Only printable ISO-8859-1 characters \
534
+ are allowed as it is sent in a HTTPS header."
535
+ ) )
532
536
}
533
537
}
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ fn invalid_login_token() {
134
134
. build ( ) ;
135
135
setup_new_credentials ( ) ;
136
136
137
- let check_ = |stdin : & str , stderr : & str | {
137
+ let check = |stdin : & str , stderr : & str | {
138
138
cargo_process ( "login" )
139
139
. replace_crates_io ( registry. index_url ( ) )
140
140
. with_stdout ( "please paste the token found on [..]/me below" )
@@ -143,19 +143,32 @@ fn invalid_login_token() {
143
143
. with_status ( 101 )
144
144
. run ( ) ;
145
145
} ;
146
- let check = |stdin : & str | {
147
- check_ ( stdin, "[ERROR] invalid token." ) ;
148
- } ;
149
- // first check updates index so it must be handled differently
150
- check_ (
146
+
147
+ check (
151
148
"😄" ,
152
149
"\
153
150
[UPDATING] crates.io index
154
- [ERROR] invalid token." ,
151
+ [ERROR] token contains invalid characters.
152
+ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header." ,
153
+ ) ;
154
+ check (
155
+ "\u{0016} " ,
156
+ "\
157
+ [ERROR] token contains invalid characters.
158
+ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header." ,
159
+ ) ;
160
+ check (
161
+ "\u{0000} " ,
162
+ "\
163
+ [ERROR] token contains invalid characters.
164
+ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header." ,
165
+ ) ;
166
+ check (
167
+ "你好" ,
168
+ "\
169
+ [ERROR] token contains invalid characters.
170
+ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header." ,
155
171
) ;
156
- check ( "\u{0016} " ) ;
157
- check ( "\u{0000} " ) ;
158
- check ( "你好" ) ;
159
172
}
160
173
161
174
#[ cargo_test]
You can’t perform that action at this time.
0 commit comments