Skip to content

Commit ab080e3

Browse files
Merge #1449
1449: Add a test that hard links are rejected r=carols10cents Follow-up with a test for #1448
2 parents 30eecf1 + 8499123 commit ab080e3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/tests/all.rs

+7
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,13 @@ fn new_crate_to_body_with_io(
715715
}
716716
t!(ar.finish());
717717
}
718+
new_crate_to_body_with_tarball(new_crate, &tarball)
719+
}
720+
721+
fn new_crate_to_body_with_tarball(
722+
new_crate: &u::NewCrate,
723+
tarball: &[u8],
724+
) -> Vec<u8> {
718725
let json = serde_json::to_string(&new_crate).unwrap();
719726
let mut body = Vec::new();
720727
body.extend(

src/tests/krate.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ use std::io;
66
use std::io::prelude::*;
77
use std::sync::Arc;
88

9-
use self::diesel::prelude::*;
109
use chrono::Utc;
1110
use conduit::{Handler, Method};
1211
use diesel::update;
12+
use flate2::Compression;
13+
use flate2::write::GzEncoder;
1314
use git2;
15+
use self::diesel::prelude::*;
1416
use semver;
1517
use serde_json;
18+
use tar;
1619

1720
use cargo_registry::git;
1821
use cargo_registry::models::krate::MAX_NAME_LENGTH;
@@ -2235,3 +2238,25 @@ fn test_cargo_invite_owners() {
22352238
// assert_eq!(json.krate.name, "foo_new");
22362239
// assert_eq!(json.krate.max_version, "1.0.0");
22372240
// }
2241+
2242+
#[test]
2243+
fn new_krate_hard_links() {
2244+
let (_b, app, middle) = ::app();
2245+
let mut req = ::new_req(Arc::clone(&app), "foo", "1.1.0");
2246+
::sign_in(&mut req, &app);
2247+
2248+
let mut tarball = Vec::new();
2249+
{
2250+
let mut ar = tar::Builder::new(GzEncoder::new(&mut tarball, Compression::default()));
2251+
let mut header = tar::Header::new_gnu();
2252+
t!(header.set_path("foo-1.1.0/bar"));
2253+
header.set_size(0);
2254+
header.set_cksum();
2255+
header.set_entry_type(tar::EntryType::hard_link());
2256+
t!(header.set_link_name("foo-1.1.0/another"));
2257+
t!(ar.append(&header, &[][..]));
2258+
t!(ar.finish());
2259+
}
2260+
let body = ::new_crate_to_body_with_tarball(&new_crate("foo"), &tarball);
2261+
bad_resp!(middle.call(req.with_body(&body)));
2262+
}

0 commit comments

Comments
 (0)