Skip to content

controllers/krate/publish: Respond with "429 Too Many Requests" when daily version limit is reached #7883

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

Merged
merged 1 commit into from
Jan 5, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
if let Some(daily_version_limit) = app.config.new_version_rate_limit {
let published_today = count_versions_published_today(krate.id, conn)?;
if published_today >= daily_version_limit as i64 {
return Err(cargo_err(
return Err(custom(
StatusCode::TOO_MANY_REQUESTS,
"You have published too many versions of this crate in the last 24 hours",
));
}
Expand Down
3 changes: 2 additions & 1 deletion src/tests/routes/crates/new.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::builders::PublishBuilder;
use crate::util::{RequestHelper, TestApp};
use http::StatusCode;

#[test]
fn daily_limit() {
Expand All @@ -13,7 +14,7 @@ fn daily_limit() {

let crate_to_publish = PublishBuilder::new("foo_daily_limit", "1.0.0");
let response = user.publish_crate(crate_to_publish);
assert!(response.status().is_success());
assert_eq!(response.status(), StatusCode::TOO_MANY_REQUESTS);
let json = response.json();
assert_eq!(
json["errors"][0]["detail"],
Expand Down