File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
crates/crates_io_smoke_test/src Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11use crate :: exit_status_ext:: ExitStatusExt ;
22use secrecy:: { ExposeSecret , SecretString } ;
33use std:: path:: Path ;
4+ use std:: process:: Output ;
45use tokio:: process:: Command ;
56
67#[ allow( unstable_name_collisions) ]
@@ -43,3 +44,21 @@ pub async fn publish(project_path: &Path, token: &SecretString) -> anyhow::Resul
4344 . exit_ok ( )
4445 . map_err ( Into :: into)
4546}
47+
48+ pub async fn publish_with_output (
49+ project_path : & Path ,
50+ token : & SecretString ,
51+ ) -> anyhow:: Result < Output > {
52+ Command :: new ( "cargo" )
53+ . args ( [ "publish" , "--registry" , "staging" ] )
54+ . current_dir ( project_path)
55+ . env ( "CARGO_TERM_COLOR" , "always" )
56+ . env (
57+ "CARGO_REGISTRIES_STAGING_INDEX" ,
58+ "https://github.com/rust-lang/staging.crates.io-index" ,
59+ )
60+ . env ( "CARGO_REGISTRIES_STAGING_TOKEN" , token. expose_secret ( ) )
61+ . output ( )
62+ . await
63+ . map_err ( Into :: into)
64+ }
Original file line number Diff line number Diff line change 77extern crate tracing;
88
99use crate :: api:: ApiClient ;
10- use anyhow:: { anyhow, Context } ;
10+ use anyhow:: { anyhow, bail , Context } ;
1111use clap:: Parser ;
1212use secrecy:: SecretString ;
1313use std:: path:: { Path , PathBuf } ;
@@ -65,6 +65,20 @@ async fn main() -> anyhow::Result<()> {
6565 . await
6666 . context ( "Failed to create project" ) ?;
6767
68+ info ! ( "Checking publish with invalid authentication…" ) ;
69+ let invalid_token = "invalid-token" . into ( ) ;
70+ let output = cargo:: publish_with_output ( & project_path, & invalid_token) . await ?;
71+ if output. status . success ( ) {
72+ bail ! ( "Expected `cargo publish` to fail with invalid token" ) ;
73+ } else {
74+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
75+ if !stderr. contains ( "401 Unauthorized" )
76+ || !stderr. contains ( "The given API token does not match the format used by crates.io" )
77+ {
78+ bail ! ( "Expected `cargo publish` to fail with an `401 Unauthorized` error, but got: {stderr}" ) ;
79+ }
80+ }
81+
6882 if options. skip_publish {
6983 info ! ( "Packaging crate file…" ) ;
7084 cargo:: package ( & project_path)
You can’t perform that action at this time.
0 commit comments