Skip to content
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
88 changes: 35 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ aws-credential-types = { version = "=1.2.1", features = ["hardcoded-credentials"
aws-ip-ranges = "=0.964.0"
aws-sdk-cloudfront = "=1.59.0"
aws-sdk-sqs = "=1.53.0"
axum = { version = "=0.7.9", features = ["macros", "matched-path"] }
axum-extra = { version = "=0.9.6", features = ["erased-json", "query", "typed-header"] }
axum = { version = "=0.8.1", features = ["macros", "matched-path"] }
axum-extra = { version = "=0.10.0", features = ["erased-json", "query", "typed-header"] }
base64 = "=0.22.1"
bigdecimal = { version = "=0.4.7", features = ["serde"] }
bon = "=3.3.2"
Expand Down Expand Up @@ -107,7 +107,7 @@ reqwest = { version = "=0.12.12", features = ["gzip", "json"] }
rss = { version = "=2.0.11", default-features = false, features = ["atom"] }
secrecy = "=0.10.3"
semver = { version = "=1.0.24", features = ["serde"] }
sentry = { version = "=0.35.0", features = ["tracing", "tower", "tower-axum-matched-path", "tower-http"] }
sentry = { version = "=0.36.0", features = ["tracing", "tower", "tower-axum-matched-path", "tower-http"] }
serde = { version = "=1.0.217", features = ["derive"] }
serde_json = "=1.0.135"
sha2 = "=0.10.8"
Expand All @@ -127,8 +127,8 @@ tracing-subscriber = { version = "=0.3.19", features = ["env-filter", "json"] }
typomania = { version = "=0.1.2", default-features = false }
url = "=2.5.4"
unicode-xid = "=0.2.6"
utoipa = { version = "=5.3.0", features = ["chrono"] }
utoipa-axum = "=0.1.3"
utoipa = { version = "=5.3.1", features = ["chrono"] }
utoipa-axum = "=0.1.4"

[dev-dependencies]
bytes = "=1.9.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/crates_io_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
workspace = true

[dependencies]
axum = { version = "=0.7.9", features = ["macros"] }
axum-extra = { version = "=0.9.6", features = ["cookie-signed"] }
axum = { version = "=0.8.1", features = ["macros"] }
axum-extra = { version = "=0.10.0", features = ["cookie-signed"] }
base64 = "=0.22.1"
cookie = { version = "=0.18.1", features = ["secure"] }
parking_lot = "=0.12.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ deadpool-diesel = { version = "=0.6.1", features = ["postgres", "tracing"] }
diesel = { version = "=2.2.6", features = ["postgres", "serde_json"] }
diesel-async = { version = "=0.5.2", features = ["async-connection-wrapper", "deadpool", "postgres"] }
futures-util = "=0.3.31"
sentry-core = { version = "=0.35.0", features = ["client"] }
sentry-core = { version = "=0.36.0", features = ["client"] }
serde = { version = "=1.0.217", features = ["derive"] }
serde_json = "=1.0.135"
thiserror = "=2.0.9"
Expand Down
2 changes: 1 addition & 1 deletion src/config/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Server {
/// - `FORCE_UNCONDITIONAL_REDIRECTS`: Whether to force unconditional redirects in the download
/// endpoint even with a healthy database pool.
/// - `BLOCKED_ROUTES`: A comma separated list of HTTP route patterns that are manually blocked
/// by an operator (e.g. `/crates/:crate_id/:version/download`).
/// by an operator (e.g. `/crates/{crate_id}/{version}/download`).
///
/// # Panics
///
Expand Down
16 changes: 8 additions & 8 deletions src/controllers/helpers/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ mod tests {
fn page_param_parsing() {
let error = |query| pagination_error(PaginationOptions::builder(), query);

assert_snapshot!(error("page="), @"Failed to deserialize query string: cannot parse integer from empty string");
assert_snapshot!(error("page=not_a_number"), @"Failed to deserialize query string: invalid digit found in string");
assert_snapshot!(error("page=1.0"), @"Failed to deserialize query string: invalid digit found in string");
assert_snapshot!(error("page=0"), @"Failed to deserialize query string: invalid value: integer `0`, expected a nonzero u32");
assert_snapshot!(error("page="), @"Failed to deserialize query string: page: cannot parse integer from empty string");
assert_snapshot!(error("page=not_a_number"), @"Failed to deserialize query string: page: invalid digit found in string");
assert_snapshot!(error("page=1.0"), @"Failed to deserialize query string: page: invalid digit found in string");
assert_snapshot!(error("page=0"), @"Failed to deserialize query string: page: invalid value: integer `0`, expected a nonzero u32");

let pagination = PaginationOptions::builder()
.gather(&mock("page=5"))
Expand All @@ -573,11 +573,11 @@ mod tests {
fn per_page_param_parsing() {
let error = |query| pagination_error(PaginationOptions::builder(), query);

assert_snapshot!(error("per_page="), @"Failed to deserialize query string: cannot parse integer from empty string");
assert_snapshot!(error("per_page=not_a_number"), @"Failed to deserialize query string: invalid digit found in string");
assert_snapshot!(error("per_page=1.0"), @"Failed to deserialize query string: invalid digit found in string");
assert_snapshot!(error("per_page="), @"Failed to deserialize query string: per_page: cannot parse integer from empty string");
assert_snapshot!(error("per_page=not_a_number"), @"Failed to deserialize query string: per_page: invalid digit found in string");
assert_snapshot!(error("per_page=1.0"), @"Failed to deserialize query string: per_page: invalid digit found in string");
assert_snapshot!(error("per_page=101"), @"cannot request more than 100 items");
assert_snapshot!(error("per_page=0"), @"Failed to deserialize query string: invalid value: integer `0`, expected a nonzero u32");
assert_snapshot!(error("per_page=0"), @"Failed to deserialize query string: per_page: invalid value: integer `0`, expected a nonzero u32");

let pagination = PaginationOptions::builder()
.gather(&mock("per_page=5"))
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use http::request::Parts;
use http::{header, StatusCode};
use prometheus::TextEncoder;

/// Handles the `GET /api/private/metrics/:kind` endpoint.
/// Handles the `GET /api/private/metrics/{kind}` endpoint.
pub async fn prometheus(app: AppState, Path(kind): Path<String>, req: Parts) -> AppResult<String> {
if let Some(expected_token) = &app.config.metrics_authorization_token {
let provided_token = req
Expand Down
19 changes: 10 additions & 9 deletions src/middleware/cargo_compat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::extract::{MatchedPath, Request, State};
use axum::middleware::Next;
use axum::response::{IntoResponse, Response};
use axum::{Extension, Json};
use axum::Json;
use http::{header, Method, StatusCode};
use std::str::FromStr;

Expand Down Expand Up @@ -36,12 +36,13 @@ impl FromStr for StatusCodeConfig {
/// Convert plain text errors into JSON errors and adjust status codes.
pub async fn middleware(
State(config): State<StatusCodeConfig>,
matched_path: Option<Extension<MatchedPath>>,
req: Request,
next: Next,
) -> Response {
let is_api_request = req.uri().path().starts_with("/api/");
let is_cargo_endpoint = matched_path
let is_cargo_endpoint = req
.extensions()
.get::<MatchedPath>()
.map(|m| is_cargo_endpoint(req.method(), m.as_str()))
.unwrap_or(false);

Expand Down Expand Up @@ -75,11 +76,11 @@ pub async fn middleware(
fn is_cargo_endpoint(method: &Method, path: &str) -> bool {
const CARGO_ENDPOINTS: &[(Method, &str)] = &[
(Method::PUT, "/api/v1/crates/new"),
(Method::DELETE, "/api/v1/crates/:crate_id/:version/yank"),
(Method::PUT, "/api/v1/crates/:crate_id/:version/unyank"),
(Method::GET, "/api/v1/crates/:crate_id/owners"),
(Method::PUT, "/api/v1/crates/:crate_id/owners"),
(Method::DELETE, "/api/v1/crates/:crate_id/owners"),
(Method::DELETE, "/api/v1/crates/{crate_id}/{version}/yank"),
(Method::PUT, "/api/v1/crates/{crate_id}/{version}/unyank"),
(Method::GET, "/api/v1/crates/{crate_id}/owners"),
(Method::PUT, "/api/v1/crates/{crate_id}/owners"),
(Method::DELETE, "/api/v1/crates/{crate_id}/owners"),
(Method::GET, "/api/v1/crates"),
];

Expand Down Expand Up @@ -154,7 +155,7 @@ mod tests {
.route("/500", internal)
.route("/api/v1/crates/new", put(|| async { StatusCode::CREATED }))
.route(
"/api/v1/crates/:crate_id/owners",
"/api/v1/crates/{crate_id}/owners",
get(|| async { StatusCode::INTERNAL_SERVER_ERROR }),
)
.layer(from_fn_with_state(StatusCodeConfig::AdjustAll, middleware))
Expand Down
Loading