|
1 | 1 | //! Tests for registry authentication.
|
2 | 2 |
|
3 |
| -use cargo_test_support::registry::{Package, RegistryBuilder}; |
| 3 | +use cargo_test_support::compare::match_contains; |
| 4 | +use cargo_test_support::registry::{Package, RegistryBuilder, Token}; |
4 | 5 | use cargo_test_support::{project, Execs, Project};
|
5 | 6 |
|
6 | 7 | fn cargo(p: &Project, s: &str) -> Execs {
|
@@ -517,3 +518,73 @@ Caused by:
|
517 | 518 | )
|
518 | 519 | .run();
|
519 | 520 | }
|
| 521 | + |
| 522 | +#[cargo_test] |
| 523 | +fn token_not_logged() { |
| 524 | + // Checks that the token isn't displayed in debug output (for both HTTP |
| 525 | + // index and registry API). Note that this doesn't fully verify the |
| 526 | + // correct behavior since we don't have an HTTP2 server, and curl behaves |
| 527 | + // significantly differently when using HTTP2. |
| 528 | + let crates_io = RegistryBuilder::new() |
| 529 | + .http_api() |
| 530 | + .http_index() |
| 531 | + .auth_required() |
| 532 | + .token(Token::Plaintext("a-unique_token".to_string())) |
| 533 | + .build(); |
| 534 | + Package::new("bar", "1.0.0").publish(); |
| 535 | + let p = project() |
| 536 | + .file( |
| 537 | + "Cargo.toml", |
| 538 | + r#" |
| 539 | + [package] |
| 540 | + name = "foo" |
| 541 | + version = "0.1.0" |
| 542 | +
|
| 543 | + [dependencies] |
| 544 | + bar = "1.0" |
| 545 | + "#, |
| 546 | + ) |
| 547 | + .file("src/lib.rs", "") |
| 548 | + .build(); |
| 549 | + let output = cargo(&p, "publish") |
| 550 | + .replace_crates_io(crates_io.index_url()) |
| 551 | + .env("CARGO_HTTP_DEBUG", "true") |
| 552 | + .env("CARGO_LOG", "trace") |
| 553 | + .exec_with_output() |
| 554 | + .unwrap(); |
| 555 | + let log = String::from_utf8(output.stderr).unwrap(); |
| 556 | + let lines = "\ |
| 557 | +[UPDATING] crates.io index |
| 558 | +[PACKAGING] foo v0.1.0 [..] |
| 559 | +[VERIFYING] foo v0.1.0 [..] |
| 560 | +[DOWNLOADING] crates ... |
| 561 | +[DOWNLOADED] bar v1.0.0 |
| 562 | +[COMPILING] bar v1.0.0 |
| 563 | +[COMPILING] foo v0.1.0 [..] |
| 564 | +[FINISHED] [..] |
| 565 | +[PACKAGED] 3 files[..] |
| 566 | +[UPLOADING] foo v0.1.0[..] |
| 567 | +[UPLOADED] foo v0.1.0 to registry `crates-io` |
| 568 | +note: Waiting [..] |
| 569 | +"; |
| 570 | + for line in lines.lines() { |
| 571 | + match_contains(line, &log, None).unwrap(); |
| 572 | + } |
| 573 | + let authorizations: Vec<_> = log |
| 574 | + .lines() |
| 575 | + .filter(|line| { |
| 576 | + line.contains("http-debug:") && line.to_lowercase().contains("authorization") |
| 577 | + }) |
| 578 | + .collect(); |
| 579 | + assert!(authorizations.iter().all(|line| line.contains("REDACTED"))); |
| 580 | + // Total authorizations: |
| 581 | + // 1. Initial config.json |
| 582 | + // 2. config.json again for verification |
| 583 | + // 3. /index/3/b/bar |
| 584 | + // 4. /dl/bar/1.0.0/download |
| 585 | + // 5. /api/v1/crates/new |
| 586 | + // 6. config.json for the "wait for publish" |
| 587 | + // 7. /index/3/f/foo for the "wait for publish" |
| 588 | + assert_eq!(authorizations.len(), 7); |
| 589 | + assert!(!log.contains("a-unique_token")); |
| 590 | +} |
0 commit comments