From 0487992f834d05726c64990d501fdfb03e256c94 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Wed, 5 Jul 2023 15:10:10 +1200 Subject: [PATCH] Expand wrap-validation schema to allow string values for :request-method --- CHANGES.md | 9 ++++++++- src/aleph/http/schema.clj | 2 +- test/aleph/http/client_middleware_test.clj | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6444b20a..4dfaa4ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +### Unreleased + +* Loosen `wrap-validation` validation to support strings in :request-method. (See release in 0.6.2 for more information). + ### 0.7.1 * Bump Manifold to 0.4.2 to fix Promesa print-method hierarchy bug @@ -34,11 +38,14 @@ Contributions by Matthew Davidson and Stefan van den Oord. * Fix backwards-compatibility for transport options * Bump Netty to 4.1.89.Final, and io_uring to 0.0.18.Final -* Add `wrap-validation` middleware to validate Ring maps * Bump deps and example deps * Upgrade CircleCI instance size * Switch to pedantic deps for CircleCI +### Breaking changes + +* Add `wrap-validation` middleware to validate Ring maps [#679](https://github.com/clj-commons/aleph/pull/679). This adds a stricter interpretation of the ring spec, which may fail on previously valid input. For example, strings (e.g. `"GET"`) and keywords (e.g. `:get`) were both accepted values for `:request-method`, but now only keywords are accepted. This will be fixed in the release after 0.7.1. + Contributions by Arnaud Geiser, Ertuğrul Çetin, Jeroen van Dijk, David Ongaro, Matthew Davidson, and Moritz Heidkamp. diff --git a/src/aleph/http/schema.clj b/src/aleph/http/schema.clj index 8b2cd436..8614d191 100644 --- a/src/aleph/http/schema.clj +++ b/src/aleph/http/schema.clj @@ -7,7 +7,7 @@ (def uri [:maybe :string]) (def query-string [:maybe :string]) (def scheme [:enum :http :https]) -(def request-method :keyword) +(def request-method [:or :string :keyword]) (def content-type [:maybe [:or :string :keyword]]) (def content-length [:maybe :int]) (def character-encoding [:maybe :string]) diff --git a/test/aleph/http/client_middleware_test.clj b/test/aleph/http/client_middleware_test.clj index 7d9a627b..9f7f9083 100644 --- a/test/aleph/http/client_middleware_test.clj +++ b/test/aleph/http/client_middleware_test.clj @@ -183,6 +183,12 @@ (doseq [req (mg/sample schema/ring-request)] (is (middleware/wrap-validation req))) + (testing "Request methods can be strings" + (is (middleware/wrap-validation {:remote-addr "localhost" + :server-name "computer" + :scheme :http + :request-method "GET"}))) + (is (thrown-with-msg? IllegalArgumentException #"Invalid spec.*:in \[:request-method\].*:type :malli.core/missing-key"