File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
crates/crates_io_tarball/src Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,13 @@ pub fn validate_manifest(manifest: &Manifest) -> Result<(), Error> {
7
7
// does not accept workspace manifests.
8
8
let package = package. ok_or ( Error :: Other ( "missing field `package`" . to_string ( ) ) ) ?;
9
9
10
+ // We don't want to allow [patch] sections in manifests at all.
11
+ if matches ! ( & manifest. patch, Some ( patch) if !patch. is_empty( ) ) {
12
+ return Err ( Error :: Other (
13
+ "crates cannot be published with `[patch]` tables" . to_string ( ) ,
14
+ ) ) ;
15
+ }
16
+
10
17
validate_package ( package) ?;
11
18
12
19
// These checks ensure that dependency workspace inheritance has been
Original file line number Diff line number Diff line change @@ -285,6 +285,38 @@ async fn new_krate_with_wildcard_dependency() {
285
285
assert_that ! ( app. stored_files( ) . await , empty( ) ) ;
286
286
}
287
287
288
+ #[ tokio:: test( flavor = "multi_thread" ) ]
289
+ async fn new_krate_with_patch ( ) {
290
+ let ( app, _, user, token) = TestApp :: full ( ) . with_token ( ) . await ;
291
+ let mut conn = app. db_conn ( ) . await ;
292
+
293
+ // Insert a crate directly into the database so that new_wild can depend on it
294
+ CrateBuilder :: new ( "foo_patch" , user. as_model ( ) . id )
295
+ . expect_build ( & mut conn)
296
+ . await ;
297
+
298
+ let manifest = r#"
299
+ [package]
300
+ name = "new_patch"
301
+ version = "1.0.0"
302
+ description = "foo?!"
303
+ license = "MIT"
304
+
305
+ [dependencies]
306
+ foo_patch = "1.0.0"
307
+
308
+ [patch.crates-io]
309
+ foo_patch = { git = "https://github.com/foo/patch.git" }
310
+ "# ;
311
+
312
+ let crate_to_publish = PublishBuilder :: new ( "new_patch" , "1.0.0" ) . custom_manifest ( manifest) ;
313
+
314
+ let response = token. publish_crate ( crate_to_publish) . await ;
315
+ assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
316
+ assert_snapshot ! ( response. text( ) , @r###"{"errors":[{"detail":"failed to parse `Cargo.toml` manifest file\n\ncrates cannot be published with `[patch]` tables"}]}"### ) ;
317
+ assert_that ! ( app. stored_files( ) . await , empty( ) ) ;
318
+ }
319
+
288
320
#[ tokio:: test( flavor = "multi_thread" ) ]
289
321
async fn new_krate_dependency_missing ( ) {
290
322
let ( app, _, _, token) = TestApp :: full ( ) . with_token ( ) . await ;
You can’t perform that action at this time.
0 commit comments