@@ -3192,3 +3192,85 @@ required by package `foo v0.0.1 ([ROOT]/foo)`
31923192 ]
31933193 ) ;
31943194}
3195+
3196+ #[ cargo_test]
3197+ fn default_auth_error ( ) {
3198+ // Check for the error message for an authentication error when default is set.
3199+ let crates_io = RegistryBuilder :: new ( ) . http_api ( ) . build ( ) ;
3200+ let _alternative = RegistryBuilder :: new ( ) . http_api ( ) . alternative ( ) . build ( ) ;
3201+
3202+ paths:: home ( ) . join ( ".cargo/credentials.toml" ) . rm_rf ( ) ;
3203+
3204+ let p = project ( )
3205+ . file (
3206+ "Cargo.toml" ,
3207+ r#"
3208+ [package]
3209+ name = "foo"
3210+ version = "0.1.0"
3211+ license = "MIT"
3212+ description = "foo"
3213+ "# ,
3214+ )
3215+ . file ( "src/lib.rs" , "" )
3216+ . build ( ) ;
3217+
3218+ // Test output before setting the default.
3219+ p. cargo ( "publish --no-verify" )
3220+ . replace_crates_io ( crates_io. index_url ( ) )
3221+ . with_stderr (
3222+ "\
3223+ [UPDATING] crates.io index
3224+ error: no token found, please run `cargo login`
3225+ or use environment variable CARGO_REGISTRY_TOKEN
3226+ " ,
3227+ )
3228+ . with_status ( 101 )
3229+ . run ( ) ;
3230+
3231+ p. cargo ( "publish --no-verify --registry alternative" )
3232+ . replace_crates_io ( crates_io. index_url ( ) )
3233+ . with_stderr (
3234+ "\
3235+ [UPDATING] `alternative` index
3236+ error: no token found for `alternative`, please run `cargo login --registry alternative`
3237+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
3238+ " ,
3239+ )
3240+ . with_status ( 101 )
3241+ . run ( ) ;
3242+
3243+ // Test the output with the default.
3244+ cargo_util:: paths:: append (
3245+ & cargo_home ( ) . join ( "config" ) ,
3246+ br#"
3247+ [registry]
3248+ default = "alternative"
3249+ "# ,
3250+ )
3251+ . unwrap ( ) ;
3252+
3253+ p. cargo ( "publish --no-verify" )
3254+ . replace_crates_io ( crates_io. index_url ( ) )
3255+ . with_stderr (
3256+ "\
3257+ [UPDATING] `alternative` index
3258+ error: no token found for `alternative`, please run `cargo login --registry alternative`
3259+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
3260+ " ,
3261+ )
3262+ . with_status ( 101 )
3263+ . run ( ) ;
3264+
3265+ p. cargo ( "publish --no-verify --registry crates-io" )
3266+ . replace_crates_io ( crates_io. index_url ( ) )
3267+ . with_stderr (
3268+ "\
3269+ [UPDATING] crates.io index
3270+ error: no token found, please run `cargo login --registry crates-io`
3271+ or use environment variable CARGO_REGISTRY_TOKEN
3272+ " ,
3273+ )
3274+ . with_status ( 101 )
3275+ . run ( ) ;
3276+ }
0 commit comments