Browse Source

fix: route deep invalid volume paths like go

rust-volume-server
Chris Lu 2 days ago
parent
commit
ffdf46b387
  1. 4
      seaweed-volume/src/server/volume_server.rs
  2. 18
      seaweed-volume/tests/http_integration.rs

4
seaweed-volume/src/server/volume_server.rs

@ -211,7 +211,8 @@ pub fn build_admin_router_with_ui(state: Arc<VolumeServerState>, ui_enabled: boo
.route("/", any(admin_store_handler))
.route("/:path", any(admin_store_handler))
.route("/:vid/:fid", any(admin_store_handler))
.route("/:vid/:fid/:filename", any(admin_store_handler));
.route("/:vid/:fid/:filename", any(admin_store_handler))
.fallback(admin_store_handler);
if ui_enabled {
router = router.route("/ui/index.html", get(handlers::ui_handler));
}
@ -232,6 +233,7 @@ pub fn build_public_router(state: Arc<VolumeServerState>) -> Router {
.route("/:path", any(public_store_handler))
.route("/:vid/:fid", any(public_store_handler))
.route("/:vid/:fid/:filename", any(public_store_handler))
.fallback(public_store_handler)
.layer(middleware::from_fn(common_headers_middleware))
.with_state(state)
}

18
seaweed-volume/tests/http_integration.rs

@ -402,6 +402,24 @@ async fn invalid_url_path_returns_400() {
);
}
#[tokio::test]
async fn deep_invalid_url_path_returns_400() {
let (state, _tmp) = test_state();
let app = build_admin_router(state);
let response = app
.oneshot(
Request::builder()
.uri("/not/a/valid/volume/path")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
}
#[tokio::test]
async fn admin_root_get_returns_400() {
let (state, _tmp) = test_state();

Loading…
Cancel
Save