Skip to content

Commit 0dda8f5

Browse files
author
Alex Helfet
committed
Added a few tests for relative registry index URLs, fixed a bug.
1 parent 3c5815f commit 0dda8f5

File tree

2 files changed

+125
-3
lines changed

2 files changed

+125
-3
lines changed

src/cargo/util/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ impl Config {
684684
}
685685

686686
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
687-
let base = index.definition.root(&self);
688-
let url = index.val.to_url_with_base(Some(base))?;
687+
let base = index.definition.root(&self).join("truncated-by-url-with-base");
688+
let url = index.val.to_url_with_base(Some(&*base))?;
689689
if url.password().is_some() {
690690
failure::bail!("Registry URLs may not contain passwords");
691691
}

tests/testsuite/alt_registry.rs

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,31 @@ fn publish_with_crates_io_dep() {
528528
}
529529

530530
#[test]
531-
fn passwords_in_url_forbidden() {
531+
fn passwords_in_registry_index_url_forbidden() {
532+
registry::init();
533+
534+
let config = paths::home().join(".cargo/config");
535+
536+
File::create(config)
537+
.unwrap()
538+
.write_all(
539+
br#"
540+
[registry]
541+
index = "ssh://git:secret@foobar.com"
542+
"#,
543+
)
544+
.unwrap();
545+
546+
let p = project().file("src/main.rs", "fn main() {}").build();
547+
548+
p.cargo("publish")
549+
.with_status(101)
550+
.with_stderr_contains("error: Registry URLs may not contain passwords")
551+
.run();
552+
}
553+
554+
#[test]
555+
fn passwords_in_registries_index_url_forbidden() {
532556
registry::init();
533557

534558
let config = paths::home().join(".cargo/config");
@@ -1141,3 +1165,101 @@ fn unknown_registry() {
11411165
)
11421166
.run();
11431167
}
1168+
1169+
#[test]
1170+
fn registries_index_relative_path() {
1171+
let config = paths::root().join(".cargo/config");
1172+
fs::create_dir_all(config.parent().unwrap()).unwrap();
1173+
File::create(&config).unwrap()
1174+
.write_all(br#"
1175+
[registries.relative]
1176+
index = "alternative-registry"
1177+
"#).unwrap();
1178+
1179+
registry::init();
1180+
1181+
let p = project()
1182+
.file(
1183+
"Cargo.toml",
1184+
r#"
1185+
[project]
1186+
name = "foo"
1187+
version = "0.0.1"
1188+
authors = []
1189+
1190+
[dependencies.bar]
1191+
version = "0.0.1"
1192+
registry = "relative"
1193+
"#,
1194+
)
1195+
.file("src/main.rs", "fn main() {}")
1196+
.build();
1197+
1198+
Package::new("bar", "0.0.1")
1199+
.alternative(true)
1200+
.publish();
1201+
1202+
p.cargo("build")
1203+
.with_stderr(&format!(
1204+
"\
1205+
[UPDATING] `{reg}` index
1206+
[DOWNLOADING] crates ...
1207+
[DOWNLOADED] bar v0.0.1 (registry `[ROOT][..]`)
1208+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
1209+
[COMPILING] foo v0.0.1 ([CWD])
1210+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1211+
",
1212+
reg = registry::alt_registry_path().to_str().unwrap()
1213+
))
1214+
.run();
1215+
}
1216+
1217+
#[test]
1218+
fn registry_index_relative_path() {
1219+
let config = paths::root().join(".cargo/config");
1220+
fs::create_dir_all(config.parent().unwrap()).unwrap();
1221+
File::create(&config).unwrap()
1222+
.write_all(br#"
1223+
[registry]
1224+
index = "alternative-registry"
1225+
"#).unwrap();
1226+
1227+
registry::init();
1228+
1229+
let p = project()
1230+
.file(
1231+
"Cargo.toml",
1232+
r#"
1233+
[project]
1234+
name = "foo"
1235+
version = "0.0.1"
1236+
authors = []
1237+
1238+
[dependencies.bar]
1239+
version = "0.0.1"
1240+
"#,
1241+
)
1242+
.file("src/main.rs", "fn main() {}")
1243+
.build();
1244+
1245+
Package::new("bar", "0.0.1")
1246+
.alternative(true)
1247+
.publish();
1248+
1249+
fs::remove_file(paths::home().join(".cargo/config")).unwrap();
1250+
1251+
p.cargo("build")
1252+
.with_stderr(&format!(
1253+
"\
1254+
warning: custom registry support via the `registry.index` configuration is being removed, this functionality will not work in the future
1255+
[UPDATING] `{reg}` index
1256+
[DOWNLOADING] crates ...
1257+
[DOWNLOADED] bar v0.0.1 (registry `[ROOT][..]`)
1258+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
1259+
[COMPILING] foo v0.0.1 ([CWD])
1260+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1261+
",
1262+
reg = registry::alt_registry_path().to_str().unwrap()
1263+
))
1264+
.run();
1265+
}

0 commit comments

Comments
 (0)