reitit icon indicating copy to clipboard operation
reitit copied to clipboard

Middleware specs with s/keys :req fail with ring method-based routing

Open andrewsuzuki opened this issue 4 years ago • 2 comments

Reference test

If I turn :opt-un into :req-un (as the docs use), the spec fails ("should contain key :roles").

It works fine however if :roles is placed in any parent map.

andrewsuzuki avatar Apr 12 '20 21:04 andrewsuzuki

Good catch. having a middleware effecting all routes, all defined methods should have the :roles defined. Reitit creates an :options route for all routes and it doesn't have the :roles defined.

Good question is, should the generated :options be validated just like all other endpoints?

ikitommi avatar Apr 20 '20 14:04 ikitommi

the compiled routes for the given app:

(-> ["/api" {:get {:handler identity
                   :roles #{:admin}}}]
    (ring/router)
    (r/compiled-routes))
;[["/api"
;  {:get {:handler #object[clojure.core$identity], :roles #{:admin}}}
;  #Methods{:get #Endpoint{:data {:handler #object[clojure.core$identity],
;                                 :roles #{:admin}},
;                          :handler #object[clojure.core$identity],
;                          :path "/api",
;                          :method :get,
;                          :middleware []},
;           :head nil,
;           :post nil,
;           :put nil,
;           :delete nil,
;           :connect nil,
;           :options #Endpoint{:data {:no-doc true,
;                                     :handler #object[reitit.ring$fn__4208$fn__4217]},
;                              :handler #object[reitit.ring$fn__4208$fn__4217],
;                              :path "/api",
;                              :method :options,
;                              :middleware []},
;           :trace nil,
;           :patch nil}]]

ikitommi avatar Apr 20 '20 14:04 ikitommi