Skip to content

Commit e44a6f2

Browse files
committed
tests/krate: Add test for broken dependency version_req
1 parent e57531f commit e44a6f2

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[
2+
{
3+
"request": {
4+
"uri": "http://alexcrichton-test.s3.amazonaws.com/crates/new_dep/new_dep-1.0.0.crate",
5+
"method": "PUT",
6+
"headers": [
7+
[
8+
"host",
9+
"alexcrichton-test.s3.amazonaws.com"
10+
],
11+
[
12+
"authorization",
13+
"AWS AKIAICL5IWUZYWWKA7JA:lH91IZJxBDr21vB3eSZXwXTQelk="
14+
],
15+
[
16+
"date",
17+
"Fri, 15 Sep 2017 07:53:06 -0700"
18+
],
19+
[
20+
"content-type",
21+
"application/x-tar"
22+
],
23+
[
24+
"accept-encoding",
25+
"gzip"
26+
],
27+
[
28+
"content-length",
29+
"35"
30+
],
31+
[
32+
"accept",
33+
"*/*"
34+
]
35+
],
36+
"body": "H4sIAAAAAAAA/+3AAQEAAACCIP+vbkhQwKsBLq+17wAEAAA="
37+
},
38+
"response": {
39+
"status": 200,
40+
"headers": [
41+
[
42+
"Server",
43+
"AmazonS3"
44+
],
45+
[
46+
"content-length",
47+
"0"
48+
],
49+
[
50+
"x-amz-request-id",
51+
"8190F375F5651D47"
52+
],
53+
[
54+
"x-amz-id-2",
55+
"PQEXq2S9IgVfG/u0l2cjHuWU8EDPlRSwxqai2oNPCz8TyX/CEwn2ydL+A1qnNK3Ng+FpC9ukVl8="
56+
],
57+
[
58+
"date",
59+
"Fri, 15 Sep 2017 14:53:07 GMT"
60+
],
61+
[
62+
"ETag",
63+
"\"f9016ad360cebb4fe2e6e96e5949f022\""
64+
]
65+
],
66+
"body": ""
67+
}
68+
}
69+
]

src/tests/krate/publish.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,40 @@ fn new_krate_with_dependency() {
203203
assert_eq!(dependencies[0].req, "^1.0.0");
204204
}
205205

206+
#[test]
207+
fn new_krate_with_broken_dependency_requirement() {
208+
let (app, _, user, token) = TestApp::full().with_token();
209+
210+
app.db(|conn| {
211+
// Insert a crate directly into the database so that new_dep can depend on it
212+
// The name choice of `foo-dep` is important! It has the property of
213+
// name != canon_crate_name(name) and is a regression test for
214+
// https://github.com/rust-lang/crates.io/issues/651
215+
CrateBuilder::new("foo-dep", user.as_model().id).expect_build(conn);
216+
});
217+
218+
let dependency = DependencyBuilder::new("foo-dep").version_req("1.2.3");
219+
220+
let crate_to_publish = PublishBuilder::new("new_dep")
221+
.version("1.0.0")
222+
.dependency(dependency);
223+
224+
// create a request body with `version_req: "broken"`
225+
let (json, tarball) = crate_to_publish.build();
226+
let new_json = json.replace("\"version_req\":\"^1.2.3\"", "\"version_req\":\"broken\"");
227+
assert_ne!(json, new_json);
228+
let body = PublishBuilder::create_publish_body(&new_json, &tarball);
229+
230+
let response = token
231+
.put::<serde_json::Value>("/api/v1/crates/new", &body)
232+
.good();
233+
234+
assert_eq!(
235+
response,
236+
json!({"errors": [{"detail": "invalid upload request: invalid value: string \"broken\", expected a valid version req at line 1 column 136"}]})
237+
);
238+
}
239+
206240
#[test]
207241
fn reject_new_krate_with_non_exact_dependency() {
208242
let (app, _, user, token) = TestApp::init().with_token();

0 commit comments

Comments
 (0)