Skip to content

Commit 5974123

Browse files
committed
test: v3 lockfile format doesn't respect url encode
These tests verify the existing buggy behavior.
1 parent 424362a commit 5974123

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

tests/testsuite/lockfile_compat.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,110 @@ version = "0.0.1"
951951
let lock = p.read_lockfile();
952952
assert_match_exact(lockfile, &lock);
953953
}
954+
955+
fn create_branch(repo: &git2::Repository, branch: &str, head_id: git2::Oid) {
956+
repo.branch(branch, &repo.find_commit(head_id).unwrap(), true)
957+
.unwrap();
958+
}
959+
960+
fn create_tag(repo: &git2::Repository, tag: &str, head_id: git2::Oid) {
961+
repo.tag(
962+
tag,
963+
&repo.find_object(head_id, None).unwrap(),
964+
&repo.signature().unwrap(),
965+
"make a new tag",
966+
false,
967+
)
968+
.unwrap();
969+
}
970+
971+
fn v3_and_git_url_encoded(ref_kind: &str, f: impl FnOnce(&git2::Repository, &str, git2::Oid)) {
972+
let (git_project, repo) = git::new_repo("dep1", |project| {
973+
project
974+
.file("Cargo.toml", &basic_lib_manifest("dep1"))
975+
.file("src/lib.rs", "")
976+
});
977+
let url = git_project.url();
978+
let head_id = repo.head().unwrap().target().unwrap();
979+
// Ref name with special characters
980+
let git_ref = "a-_+#$)";
981+
f(&repo, git_ref, head_id);
982+
983+
let lockfile = format!(
984+
r#"# This file is automatically @generated by Cargo.
985+
# It is not intended for manual editing.
986+
version = 3
987+
988+
[[package]]
989+
name = "dep1"
990+
version = "0.5.0"
991+
source = "git+{url}?{ref_kind}={git_ref}#{head_id}"
992+
993+
[[package]]
994+
name = "foo"
995+
version = "0.0.1"
996+
dependencies = [
997+
"dep1",
998+
]
999+
"#,
1000+
);
1001+
1002+
let p = project()
1003+
.file(
1004+
"Cargo.toml",
1005+
&format!(
1006+
r#"
1007+
[package]
1008+
name = "foo"
1009+
version = "0.0.1"
1010+
1011+
[dependencies]
1012+
dep1 = {{ git = '{url}', {ref_kind} = '{git_ref}' }}
1013+
"#,
1014+
),
1015+
)
1016+
.file("src/lib.rs", "")
1017+
.file("Cargo.lock", "version = 3")
1018+
.build();
1019+
1020+
p.cargo("check")
1021+
.with_stderr(format!(
1022+
"\
1023+
[UPDATING] git repository `{url}`
1024+
[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..])
1025+
[CHECKING] foo v0.0.1 ([CWD])
1026+
[FINISHED] dev [..]
1027+
"
1028+
))
1029+
.run();
1030+
1031+
let lock = p.read_lockfile();
1032+
assert_match_exact(&lockfile, &lock);
1033+
1034+
// v3 doesn't URL-encode URL parameters, but `url` crate does decode as it
1035+
// was URL-encoded. Therefore Cargo thinks they are from different source
1036+
// and clones the repository again.
1037+
p.cargo("check")
1038+
.with_stderr(format!(
1039+
"\
1040+
[UPDATING] git repository `{url}`
1041+
[FINISHED] dev [..]
1042+
"
1043+
))
1044+
.run();
1045+
}
1046+
1047+
#[cargo_test]
1048+
fn v3_and_git_url_encoded_branch() {
1049+
v3_and_git_url_encoded("branch", create_branch);
1050+
}
1051+
1052+
#[cargo_test]
1053+
fn v3_and_git_url_encoded_tag() {
1054+
v3_and_git_url_encoded("tag", create_tag);
1055+
}
1056+
1057+
#[cargo_test]
1058+
fn v3_and_git_url_encoded_rev() {
1059+
v3_and_git_url_encoded("rev", create_tag);
1060+
}

0 commit comments

Comments
 (0)