🐛 Add minimum validation for total-chunks in upload session

The create-upload-session RPC method accepted total-chunks values of 0
or negative numbers without validation, creating inconsistent session
state. Add {:min 1} constraint to the schema to reject invalid values
at input validation.

Closes #11103

AI-assisted-by: qwen3.7-plus
This commit is contained in:
Andrey Antukh 2026-08-06 07:28:43 +00:00
parent a60b648c6c
commit 1968efadbf
2 changed files with 19 additions and 1 deletions

View File

@ -289,7 +289,7 @@
(def ^:private schema:create-upload-session
[:map {:title "create-upload-session"}
[:total-chunks ::sm/int]])
[:total-chunks [::sm/int {:min 1}]]])
(def ^:private schema:create-upload-session-result
[:map {:title "create-upload-session-result"}

View File

@ -683,6 +683,24 @@
(t/is (= :max-quote-reached (-> out :error ex-data :code)))
(t/is (= "upload-chunks-per-session" (-> out :error ex-data :target))))))
(t/deftest chunked-upload-invalid-total-chunks
;; total-chunks must be at least 1; zero and negative values are rejected
;; with a :validation error.
(let [prof (th/create-profile* 1)]
;; zero total-chunks
(let [out (th/command! {::th/type :create-upload-session
::rpc/profile-id (:id prof)
:total-chunks 0})]
(t/is (some? (:error out)))
(t/is (= :validation (-> out :error ex-data :type))))
;; negative total-chunks
(let [out (th/command! {::th/type :create-upload-session
::rpc/profile-id (:id prof)
:total-chunks -1})]
(t/is (some? (:error out)))
(t/is (= :validation (-> out :error ex-data :type))))))
(t/deftest chunked-upload-invalid-chunk-index
;; Both a negative index and an index >= total-chunks must be
;; rejected with a :validation / :invalid-chunk-index error.