clj-http-client/test/puppetlabs/http/client/async_ssl_config_test.clj
Chris Price 186b226512 (TK-23) Port to apache HttpAsyncClient
* Ports the code over to use the Apache HttpAsyncClient library
  instead of http-kit, as we were getting some weird and inconsistent
  SSL errors from http-kit, and
* Simplify the API (by eliminating a lot of the supported configuration
  options).  Some of these options we'll eventually want to add back in,
  but for now, getting rid of them makes the API less cluttered and
  also gives us the opportunity to do a better job writing tests
  for new options when we do add support for them.

For now it only supports constructing a new client on every request.
I intend to add API for creating a client explicitly, and a protocol
for how to interact with the client.  This will allow users to
re-use an existing client as they see fit... but this hasn't been
implemented yet.
2014-07-03 08:58:46 -07:00

49 lines
No EOL
1.9 KiB
Clojure

(ns puppetlabs.http.client.async-ssl-config-test
(:require [clojure.test :refer :all]
[clojure.java.io :refer [resource]]
[puppetlabs.certificate-authority.core :as ssl]
[puppetlabs.http.client.async :as http]
[schema.test :as schema-test])
(:import [javax.net.ssl SSLContext]))
(use-fixtures :once schema-test/validate-schemas)
(deftest ssl-config-with-files
(let [opts {:ssl-cert (resource "ssl/cert.pem")
:ssl-key (resource "ssl/key.pem")
:ssl-ca-cert (resource "ssl/ca.pem")}
configured-opts (http/configure-ssl opts)]
(testing "configure-ssl sets up an SSLContext when given cert, key, ca-cert"
(is (instance? SSLContext (:ssl-context configured-opts))))
(testing "removes ssl-cert, ssl-key, ssl-ca-cert"
(is (not (:ssl-cert configured-opts)))
(is (not (:ssl-key configured-opts)))
(is (not (:ssl-ca-cert configured-opts))))))
(deftest ssl-config-with-ca-file
(let [opts {:ssl-ca-cert (resource "ssl/ca.pem")}
configured-opts (http/configure-ssl opts)]
(testing "configure-ssl sets up an SSLContext when given ca-cert"
(is (instance? SSLContext (:ssl-context configured-opts))))
(testing "removes ssl-ca-cert"
(is (not (:ssl-ca-cert configured-opts))))))
(deftest ssl-config-without-ssl-params
(let [configured-opts (http/configure-ssl {})]
(testing "configure-ssl does nothing when given no ssl parameters"
(is (= {} configured-opts)))))
(deftest ssl-config-with-context
(let [opts {:ssl-context (ssl/pems->ssl-context
(resource "ssl/cert.pem")
(resource "ssl/key.pem")
(resource "ssl/ca.pem"))}
configured-opts (http/configure-ssl opts)]
(testing "configure-ssl uses an existing ssl context"
(is (instance? SSLContext (:ssl-context configured-opts))))))