Skip to content

Commit

Permalink
fix broken tests - token_caching token_not_logged
Browse files Browse the repository at this point in the history
  • Loading branch information
stupendoussuperpowers committed Aug 7, 2024
1 parent d24d542 commit b5be434
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {

if !duplicate_query.is_empty() {
bail!(
"crate {} already has version {}. Aborting publish.",
"crate {}@{} already exists on {}",
pkg.name(),
pkg.version()
pkg.version(),
source.describe()
);
}

Expand Down
27 changes: 26 additions & 1 deletion tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,31 @@ You may press ctrl-c [..]
.with_stderr_data(output)
.run();

let output_non_independent = r#"[UPDATING] `alternative` index
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read"}
[PACKAGING] foo v0.1.1 ([ROOT]/foo)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.1","cksum":"[..]"}
[UPLOADING] foo v0.1.1 ([ROOT]/foo)
[UPLOADED] foo v0.1.1 to registry `alternative`
[NOTE] waiting [..]
You may press ctrl-c [..]
[PUBLISHED] foo v0.1.1 at registry `alternative`
"#;

p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.1"
edition = "2015"
description = "foo"
license = "MIT"
homepage = "https://example.com/"
"#,
);

p.change_file(
".cargo/config.toml",
&format!(
Expand All @@ -557,7 +582,7 @@ You may press ctrl-c [..]
);

p.cargo("publish --registry alternative --no-verify")
.with_stderr_data(output)
.with_stderr_data(output_non_independent)
.run();
}

Expand Down
17 changes: 2 additions & 15 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.

#[cargo_test]
fn duplicate_version() {
let arc: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
let registry_dupl = RegistryBuilder::new()
.http_api()
.http_index()
.add_responder("/index/3/f/foo", move |req, server| {
let mut lock = arc.lock().unwrap();
*lock += 1;
if *lock <= 1 {
server.not_found(req)
} else {
server.index(req)
}
})
.build();
let registry_dupl = RegistryBuilder::new().http_api().http_index().build();

let p = project()
.file(
Expand All @@ -171,7 +158,7 @@ fn duplicate_version() {
.replace_crates_io(registry_dupl.index_url())
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] crate foo already has version 0.0.1. Aborting publish.
[ERROR] crate foo@0.0.1 already exists on [..]
"#]])
.with_status(101)
Expand Down
9 changes: 5 additions & 4 deletions tests/testsuite/registry_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,10 @@ fn token_not_logged() {
// 2. config.json again for verification
// 3. /index/3/b/bar
// 4. /dl/bar/1.0.0/download
// 5. /api/v1/crates/new
// 6. config.json for the "wait for publish"
// 7. /index/3/f/foo for the "wait for publish"
assert_eq!(authorizations.len(), 7);
// 5. /index/3/f/foo for checking duplicate version
// 6. /api/v1/crates/new
// 7. config.json for the "wait for publish"
// 8. /index/3/f/foo for the "wait for publish"
assert_eq!(authorizations.len(), 8);
assert!(!log.contains("a-unique_token"));
}

0 comments on commit b5be434

Please sign in to comment.