                             " #bar"
                             "bar "
                             " bar"]]
-        (let [whitelist (tmp-whitelist "foo"
-                                       invalid-line
-                                       "qux")]
+        (let [whitelist (tmp-whitelist! "foo"
+                                        invalid-line
+                                        "qux")]
           (assert-autosign whitelist "foo")
           (logutils/with-log-output logs
             (assert-no-autosign whitelist invalid-line)

  (testing "Certs can be written to an inventory file."
    (let [first-cert     (utils/pem->cert cacert)
          second-cert    (utils/pem->cert (path-to-cert signeddir "localhost"))
          inventory-file (:cert-inventory (ca-test-settings))]
      (write-cert-to-inventory! first-cert inventory-file)
      (write-cert-to-inventory! second-cert inventory-file)


            "/CN=localhost"))))))

(deftest process-csr-submission!-test
  (let [settings (assoc (ca-test-settings)
                   :serial (tmp-serial-file!)
                   :cert-inventory (str (ks/temp-file)))]
    (testing "throws an exception if a CSR already exists for that subject"
      (is (thrown-with-slingshot?
           {:type    :duplicate-cert
            :message "test-agent already has a requested certificate; ignoring certificate request"}
           (process-csr-submission! "test-agent" (csr-stream "test-agent") settings)))

      (testing "unless $allow-duplicate-certs is true"
        (let [settings  (assoc settings :allow-duplicate-certs true)
              cert-path (path-to-cert (:signeddir settings) "test-agent")]
          (logutils/with-test-logging
            (is (false? (fs/exists? cert-path)))
            (process-csr-submission! "test-agent" (csr-stream "test-agent") settings)
            (is (logged? #"test-agent already has a requested certificate; new certificate will overwrite it" :info))
            (is (true? (fs/exists? cert-path))))
          (fs/delete cert-path))))

    (testing "throws an exception if a certificate already exists for that subject"
      (is (thrown-with-slingshot?
           {:type    :duplicate-cert
            :message "localhost already has a signed certificate; ignoring certificate request"}
           (process-csr-submission! "localhost" (csr-stream "test-agent") settings)))

      (testing "unless $allow-duplicate-certs is true"
        (let [settings (assoc settings :allow-duplicate-certs true :autosign false)
              csr-path (path-to-cert-request (:csrdir settings) "localhost")]
          (logutils/with-test-logging
            (is (false? (fs/exists? csr-path)))
            (process-csr-submission! "localhost" (csr-stream "test-agent") settings)
            (is (logged? #"localhost already has a signed certificate; new certificate will overwrite it" :info))
            (is (true? (fs/exists? csr-path))))
          (fs/delete csr-path))))))
