Skip to content

Commit 3e6fda1

Browse files
Test for multiple requests with cert in InputStream
Both testing contexts are failing. The serial one is to demonstrate that the InputStream cannot be read twice without resetting, which obviously is not done by Netty/Aleph. This is also the case in the concurrent context, which was intended to resemble the original report in clj-commons#728 and is a more likely scenario, since it doesn't disable keep-alive. IIUC, the concurrent scenario could fail in an even more unpleasant way, if the test certificate file was greater than the 8192-byte buffer used to read it, but ours is not (the fix would be the same). NB: `with-http-ssl-servers` already runs things twice, so `repeatedly` is not required to make it fail, but that would be harder to read and wouldn't cover (at some level, at least) both servers.
1 parent cd42a65 commit 3e6fda1

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/aleph/http_test.clj

+31
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,37 @@
445445
:body
446446
bs/to-string))))))
447447

448+
(deftest using-input-stream-as-ssl-context-trust-store
449+
(let [num-requests 2
450+
file-name "test/ca_cert.pem"
451+
client-options (fn [stream]
452+
{:connection-options {:ssl-context {:private-key test-ssl/client-key
453+
:certificate-chain [test-ssl/client-cert]
454+
:trust-store stream}}})
455+
requests (fn [pool]
456+
(repeatedly num-requests #(http-post "/"
457+
{:body "hello!"
458+
:pool pool})))]
459+
(testing "multiple serial requests without connection reuse"
460+
(with-open [stream (io/input-stream file-name)]
461+
(let [client-pool (http/connection-pool (-> (client-options stream)
462+
(assoc-in [:connection-options :keep-alive?] false)))]
463+
(with-http-ssl-servers echo-handler {}
464+
(is (every?
465+
#{"hello!"}
466+
(->> (requests client-pool)
467+
(mapv (comp bs/to-string :body deref)))))))))
468+
469+
(testing "multiple concurrent requests"
470+
(with-open [stream (io/input-stream file-name)]
471+
(let [client-pool (http/connection-pool (client-options stream))]
472+
(with-http-ssl-servers echo-handler {}
473+
(is (every?
474+
#{"hello!"}
475+
(->> (requests client-pool)
476+
(doall)
477+
(mapv (comp bs/to-string :body deref)))))))))))
478+
448479
(defn ssl-session-capture-handler [ssl-session-atom]
449480
(fn [req]
450481
(reset! ssl-session-atom (http.core/ring-request-ssl-session req))

test/ca_cert.pem

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDyjCCArKgAwIBAgIJAPj8IfB83MXVMA0GCSqGSIb3DQEBCwUAMHIxCzAJBgNV
3+
BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlDdXBlcnRpbm8x
4+
GDAWBgNVBAoMD0JGUCBDb3Jwb3JhdGlvbjEOMAwGA1UECwwFQWxlcGgxEDAOBgNV
5+
BAMMB1Jvb3QgQ0EwHhcNMTYxMTIxMjEzMTIzWhcNMzcwMjI0MjEzMTIzWjByMQsw
6+
CQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJQ3VwZXJ0
7+
aW5vMRgwFgYDVQQKDA9CRlAgQ29ycG9yYXRpb24xDjAMBgNVBAsMBUFsZXBoMRAw
8+
DgYDVQQDDAdSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
9+
1kKISz7cCJIU7pk+JBOH8+6UfvtR7BS1hTkWMw+IsTa9O1EJJqEtiJZTF267nLog
10+
+jfUr8AHSTR+qtKkbs77XrOMlaa6Zyq3Z2d/p8R3oUdurg6T3JECGwilYDsEMLNL
11+
XnqnUdkeWQJ7ea7UzgJ7ACZ61I4+Dv9xJQ+5BGMRkH+SUTDQ/um8UmrPxbDDljR7
12+
TbTY7WtAPbxbALrEKA5EfNS1vdcYCfguN0BUcHaHEiBDAIU7IXZigdPBnSTDHhqB
13+
YHjmgQZ9U/ojrvmjG9lsG6X5WGj5H1SZCmpWbp+WiNEgHckzhRkCKU5V53mpqcrF
14+
Q5WJjAHGQrBF7CD1IUj6VwIDAQABo2MwYTAdBgNVHQ4EFgQUHZFU7TsvVmLorae0
15+
LntY0bhIRwIwHwYDVR0jBBgwFoAUHZFU7TsvVmLorae0LntY0bhIRwIwDwYDVR0T
16+
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