diff --git a/src/controllers/krate/publish.rs b/src/controllers/krate/publish.rs index 004ea2df45a..41e79d6b851 100644 --- a/src/controllers/krate/publish.rs +++ b/src/controllers/krate/publish.rs @@ -157,6 +157,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult 5 { + return Err(cargo_err("expected at most 5 categories per crate")); + } + // Create a transaction on the database, if there are no errors, // commit the transactions to record a new or updated crate. conn.transaction(|conn| { @@ -172,11 +181,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult>(); - let categories = metadata - .categories - .iter() - .map(|s| s.as_str()) - .collect::>(); + let categories = categories.iter().map(|s| s.as_str()).collect::>(); // Persist the new crate, if it doesn't already exist let persist = NewCrate { diff --git a/src/tests/builders/publish.rs b/src/tests/builders/publish.rs index a51ba34f71b..2e1dd6408f2 100644 --- a/src/tests/builders/publish.rs +++ b/src/tests/builders/publish.rs @@ -151,7 +151,6 @@ impl PublishBuilder { .map(u::EncodableKeyword) .collect(), ), - categories: u::EncodableCategoryList(self.categories.clone()), }; let mut tarball_builder = TarballBuilder::new(); diff --git a/src/tests/krate/publish/snapshots/all__krate__publish__categories__too_many_categories.snap b/src/tests/krate/publish/snapshots/all__krate__publish__categories__too_many_categories.snap index a7b65bb264c..5970faae56c 100644 --- a/src/tests/krate/publish/snapshots/all__krate__publish__categories__too_many_categories.snap +++ b/src/tests/krate/publish/snapshots/all__krate__publish__categories__too_many_categories.snap @@ -5,7 +5,7 @@ expression: response.into_json() { "errors": [ { - "detail": "invalid upload request: invalid length 6, expected at most 5 categories per crate at line 1 column 155" + "detail": "expected at most 5 categories per crate" } ] } diff --git a/src/tests/krate/publish/snapshots/all__krate__publish__keywords__too_many_keywords.snap b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__too_many_keywords.snap index cb921102eeb..5e183db775b 100644 --- a/src/tests/krate/publish/snapshots/all__krate__publish__keywords__too_many_keywords.snap +++ b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__too_many_keywords.snap @@ -5,7 +5,7 @@ expression: response.into_json() { "errors": [ { - "detail": "invalid upload request: invalid length 6, expected at most 5 keywords per crate at line 1 column 138" + "detail": "invalid upload request: invalid length 6, expected at most 5 keywords per crate at line 1 column 139" } ] } diff --git a/src/views/krate_publish.rs b/src/views/krate_publish.rs index 301c15ab89f..eb0cf0031eb 100644 --- a/src/views/krate_publish.rs +++ b/src/views/krate_publish.rs @@ -25,8 +25,6 @@ pub struct PublishMetadata { pub readme_file: Option, #[serde(default)] pub keywords: EncodableKeywordList, - #[serde(default)] - pub categories: EncodableCategoryList, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -195,21 +193,6 @@ impl<'de> Deserialize<'de> for EncodableKeywordList { } } -#[derive(Serialize, Debug, Deref, Default)] -pub struct EncodableCategoryList(pub Vec); - -impl<'de> Deserialize<'de> for EncodableCategoryList { - fn deserialize>(d: D) -> Result { - let inner = as Deserialize<'de>>::deserialize(d)?; - if inner.len() > 5 { - let expected = "at most 5 categories per crate"; - Err(de::Error::invalid_length(inner.len(), &expected)) - } else { - Ok(EncodableCategoryList(inner)) - } - } -} - #[test] fn feature_deserializes_for_valid_features() { use serde_json as json;