 (ns puppetlabs.puppetdb.middleware-test
   (:import [java.io ByteArrayInputStream])
   (:require [puppetlabs.kitchensink.core :as kitchensink]
-            [puppetlabs.i18n.core :as i18n]
             [puppetlabs.puppetdb.http :as http]
             [ring.util.response :as rr]
             [cheshire.core :as json]

        (is (= :authorized (authorizer-fn {:ssl-client-cn "foobar"})))
        (with-log-output logz
          (is (string? (authorizer-fn {:ssl-client-cn "badguy"})))
          (is (= 1 (count (logs-matching #"^badguy rejected by certificate whitelist " @logz))))))))

  (let [es (i18n/string-as-locale "es")]
    (with-system-locale es
      (testing "should log in Spanish on reject"
        (let [wl (temp-file "whitelist-log-reject")]
          (spit wl "foobar")
          (let [authorizer-fn (build-whitelist-authorizer (fs/absolute-path wl))]
            (is (= :authorized (authorizer-fn {:ssl-client-cn "foobar"})))
            (with-log-output logz
              (is (string? (authorizer-fn {:ssl-client-cn "badguy"})))
              (is (= 1 (count (logs-matching #"^badguy fue rechazado por el certificado de la lista blanca " @logz)))))))))))

(deftest test-fail-when-payload-too-large
  (testing "max-command-size-fail disabled should allow commands of any size"

    (testing "should return an error response if unknown parameters are present"
      (let [{:keys [status body]} (wrapped-fn {:params {"foo" 1 "bar" 2 "wazzup" 3}})]
        (is (= http/status-bad-request status))
        (is (= "Unsupported query parameter 'wazzup'" body))))))

(deftest verify-content-type-test
  (testing "with content-type of application/json"
