Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 441fd35

Browse files
committedJan 31, 2025·
Check token validity when loading registry config
1 parent ca6274c commit 441fd35

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

‎src/cargo/util/auth/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cargo_credential::{
99
Action, CacheControl, Credential, CredentialResponse, LoginOptions, Operation, RegistryInfo,
1010
Secret,
1111
};
12+
use crates_io::check_token;
1213

1314
use core::fmt;
1415
use serde::Deserialize;
@@ -236,6 +237,17 @@ pub fn registry_credential_config_raw(
236237
return Ok(cfg.clone());
237238
}
238239
let cfg = registry_credential_config_raw_uncached(gctx, sid)?;
240+
if let Some(RegistryConfig {
241+
token: Some(token), ..
242+
}) = &cfg
243+
{
244+
check_token(&token.val.as_deref().expose()).with_context(|| {
245+
format!(
246+
"Token for {sid} is invalid (defined in {})",
247+
token.definition
248+
)
249+
})?;
250+
}
239251
cache.insert(*sid, cfg.clone());
240252
return Ok(cfg);
241253
}

‎tests/testsuite/publish.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3609,10 +3609,7 @@ fn invalid_token() {
36093609
.env("CARGO_REGISTRY_TOKEN", "\x16")
36103610
.with_stderr_data(str![[r#"
36113611
[UPDATING] crates.io index
3612-
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
3613-
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3614-
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
3615-
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
3612+
[ERROR] Token for registry `crates-io` is invalid (defined in environment variable `CARGO_REGISTRY_TOKEN`)
36163613
36173614
Caused by:
36183615
token contains invalid characters.

0 commit comments

Comments
 (0)
Please sign in to comment.