Skip to content

DO NOT MERGE YET encode + as %2B in S3 paths #5034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions src/tests/http-data/krate_publish_new_krate_version_with_plus
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[
{
"request": {
"uri": "http://alexcrichton-test.s3.amazonaws.com/crates/foo_plus/foo_plus-1.0.0%2Bbuild-metadata.crate",
"method": "PUT",
"headers": [
[
"host",
"alexcrichton-test.s3.amazonaws.com"
],
[
"accept-encoding",
"gzip"
],
[
"authorization",
"AWS AKIAICL5IWUZYWWKA7JA:eW1SP7V3WdqHXWZLcbN1BI2Zo0g="
],
[
"content-length",
"35"
],
[
"date",
"Fri, 15 Sep 2017 07:53:06 -0700"
],
[
"content-type",
"application/gzip"
],
[
"accept",
"*/*"
]
],
"body": "H4sIAAAAAAAA/+3AAQEAAACCIP+vbkhQwKsBLq+17wAEAAA="
},
"response": {
"status": 200,
"headers": [
[
"ETag",
"\"f9016ad360cebb4fe2e6e96e5949f022\""
],
[
"content-length",
"0"
],
[
"Server",
"AmazonS3"
],
[
"x-amz-request-id",
"11703800587FA328"
],
[
"date",
"Fri, 15 Sep 2017 14:53:07 GMT"
],
[
"x-amz-id-2",
"fIN5XfJH1PExUU+fEoYZiLAlq/GVmVohMf24Gi5CEHocX1oLc56Mhq9ILtXEsC5xgXEtboWFrEI="
]
],
"body": ""
}
},
{
"request": {
"uri": "http://alexcrichton-test.s3.amazonaws.com/fo/o_/foo_plus",
"method": "PUT",
"headers": [
[
"accept-encoding",
"gzip"
],
[
"accept",
"*/*"
],
[
"content-length",
"177"
],
[
"date",
"Fri, 15 Sep 2017 07:53:06 -0700"
],
[
"authorization",
"AWS AKIAICL5IWUZYWWKA7JA:uDc39eNdF6CcwB+q+JwKsoDLQc4="
],
[
"content-type",
"text/plain"
],
[
"host",
"alexcrichton-test.s3.amazonaws.com"
]
],
"body": "eyJuYW1lIjoiZm9vX3BsdXMiLCJ2ZXJzIjoiMS4wLjArYnVpbGQtbWV0YWRhdGEiLCJkZXBzIjpbXSwiY2tzdW0iOiJhY2I1NjA0YjEyNmFjODk0YzFlYjExYzQ1NzViZjIwNzJmZWE2MTIzMmE4ODhlNDUzNzcwYzc5ZDdlZDU2NDE5IiwiZmVhdHVyZXMiOnt9LCJ5YW5rZWQiOmZhbHNlLCJsaW5rcyI6bnVsbH0K"
},
"response": {
"status": 200,
"headers": [
[
"x-amz-request-id",
"26589A5E52F8395C"
],
[
"x-amz-id-2",
"JdIvnNTw53aqXjBIqBLNuN4kxf/w1XWX+xuIiGBDYy7yzOSDuAMtBSrTW4ZWetcCIdqCUHuQ51A="
],
[
"content-length",
"0"
],
[
"Server",
"AmazonS3"
],
[
"date",
"Fri,15 Sep 2017 14:53:07 GMT"
],
[
"ETag",
"\"f9016ad360cebb4fe2e6e96e5949f022\""
]
],
"body": ""
}
}
]
15 changes: 15 additions & 0 deletions src/tests/krate/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ fn download_nonexistent_version_of_existing_crate_404s() {
.assert_not_found();
}

#[test]
fn download_version_with_plus() {
let (app, anon, user) = TestApp::init().with_user();
let user = user.as_model();

app.db(|conn| {
CrateBuilder::new("foo_plus", user.id)
.version(VersionBuilder::new("1.0.0+hello"))
.expect_build(conn);
});

anon.get::<()>("/api/v1/crates/foo_plus/1.0.0+hello/download")
.assert_redirect_ends_with("/crates/foo_plus/foo_plus-1.0.0%2Bhello.crate");
}

#[test]
fn download_noncanonical_crate_name() {
let (app, anon, user) = TestApp::init().with_user();
Expand Down
11 changes: 11 additions & 0 deletions src/tests/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ fn new_krate_weird_version() {
assert_eq!(json.krate.max_version, "0.0.0-pre");
}

#[test]
fn new_krate_version_with_plus() {
let (_, _, _, token) = TestApp::full().with_token();

let crate_to_publish = PublishBuilder::new("foo_plus").version("1.0.0+build-metadata");
let json: GoodCrate = token.publish_crate(crate_to_publish).good();

assert_eq!(json.krate.name, "foo_plus");
assert_eq!(json.krate.max_version, "1.0.0+build-metadata");
}

#[test]
fn new_with_renamed_dependency() {
let (app, _, user, token) = TestApp::full().with_token();
Expand Down
11 changes: 8 additions & 3 deletions src/tests/util/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ impl<T> Response<T> {

#[track_caller]
pub fn assert_redirect_ends_with(&self, target: &str) -> &Self {
assert!(self
let redirect_url = self
.response
.headers()
.get(header::LOCATION)
.unwrap()
.to_str()
.unwrap()
.ends_with(target));
.unwrap();
assert!(
redirect_url.ends_with(target),
"assertion failed: `redirect_url.ends_with(target)`
redirect_url: `\"{redirect_url}\"`
target: `\"{target}\"`"
);
self
}
}
Expand Down
1 change: 1 addition & 0 deletions src/uploaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Uploader {

/// Returns the internal path of an uploaded crate's version archive.
fn crate_path(name: &str, version: &str) -> String {
let version = version.replace('+', "%2B");
format!("crates/{name}/{name}-{version}.crate")
}

Expand Down