@@ -22,17 +22,24 @@
|
||||
body (assoc :body (ByteArrayInputStream. (.getBytes ^String body)))))))
|
||||
(cond-> @resp (string? (:body @resp)) (update :body edn/read-string)))))
|
||||
|
||||
(defn get-nrepl [app cookie]
|
||||
(let [resp (app {:request-method :get :uri "/nrepl"
|
||||
:headers (cond-> {} cookie (assoc "cookie" cookie))})]
|
||||
(cond-> resp (string? (:body resp)) (update :body edn/read-string))))
|
||||
|
||||
(deftest anonymous-test
|
||||
(let [app (t/make-app (t/gitea-stub "alice"))]
|
||||
(doseq [body ["{\"enabled\":true}" "{\"enabled\":\"junk\"}" nil]]
|
||||
(let [resp (post-nrepl app nil body)]
|
||||
(is (= 401 (:status resp)) (str "body: " body))))
|
||||
(is (= 401 (:status (get-nrepl app nil))))
|
||||
(is (= {:enabled false} (nrepl/status)) "nothing was started")))
|
||||
|
||||
(deftest non-admin-test
|
||||
(let [app (t/make-app (t/gitea-stub "mallory"))
|
||||
cookie (t/login! app)]
|
||||
(is (= 403 (:status (post-nrepl app cookie "{\"enabled\":true}"))))
|
||||
(is (= 403 (:status (get-nrepl app cookie))))
|
||||
(is (= {:enabled false} (nrepl/status)) "nothing was started")))
|
||||
|
||||
(deftest empty-allowlist-test
|
||||
@@ -60,6 +67,24 @@
|
||||
(is (= 200 (:status resp)))
|
||||
(is (true? (get-in resp [:body :enabled])))))))
|
||||
|
||||
(deftest status-test
|
||||
(let [app (t/make-app (t/gitea-stub "alice"))
|
||||
cookie (t/login! app)]
|
||||
(testing "off"
|
||||
(let [resp (get-nrepl app cookie)]
|
||||
(is (= 200 (:status resp)))
|
||||
(is (= "application/edn; charset=utf-8" (get-in resp [:headers "Content-Type"])))
|
||||
(is (= {:enabled false} (:body resp)))))
|
||||
(testing "on"
|
||||
(with-out-str (post-nrepl app cookie "{\"enabled\":true}"))
|
||||
(let [resp (get-nrepl app cookie)]
|
||||
(is (= 200 (:status resp)))
|
||||
(is (= {:enabled true :bind "127.0.0.1"} (dissoc (:body resp) :port)))
|
||||
(is (= (:body resp) (nrepl/status)))))
|
||||
(testing "off again"
|
||||
(with-out-str (post-nrepl app cookie "{\"enabled\":false}"))
|
||||
(is (= {:enabled false} (:body (get-nrepl app cookie)))))))
|
||||
|
||||
(deftest invalid-body-test
|
||||
(let [app (t/make-app (t/gitea-stub "alice"))
|
||||
cookie (t/login! app)]
|
||||
@@ -89,4 +114,5 @@
|
||||
(->> (m/decode "application/json")))
|
||||
paths (into {} (map (fn [[k v]] [(str (namespace k) "/" (name k)) v])) (:paths spec))]
|
||||
(is (contains? (get-in paths ["/nrepl"]) :post) "documented")
|
||||
(is (contains? (get-in paths ["/nrepl"]) :get) "documented")
|
||||
(is (contains? paths "/auth/login"))))
|
||||
|
||||
Reference in New Issue
Block a user