Skip to content

Commit 008fc0a

Browse files
authored
controllers/krate/publish: Respond with "429 Too Many Requests" when daily version limit is reached (#7883)
1 parent 91b5fe7 commit 008fc0a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/controllers/krate/publish.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
303303
if let Some(daily_version_limit) = app.config.new_version_rate_limit {
304304
let published_today = count_versions_published_today(krate.id, conn)?;
305305
if published_today >= daily_version_limit as i64 {
306-
return Err(cargo_err(
306+
return Err(custom(
307+
StatusCode::TOO_MANY_REQUESTS,
307308
"You have published too many versions of this crate in the last 24 hours",
308309
));
309310
}

src/tests/routes/crates/new.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::builders::PublishBuilder;
22
use crate::util::{RequestHelper, TestApp};
3+
use http::StatusCode;
34

45
#[test]
56
fn daily_limit() {
@@ -13,7 +14,7 @@ fn daily_limit() {
1314

1415
let crate_to_publish = PublishBuilder::new("foo_daily_limit", "1.0.0");
1516
let response = user.publish_crate(crate_to_publish);
16-
assert!(response.status().is_success());
17+
assert_eq!(response.status(), StatusCode::TOO_MANY_REQUESTS);
1718
let json = response.json();
1819
assert_eq!(
1920
json["errors"][0]["detail"],

0 commit comments

Comments
 (0)