|
12 | 12 |
|
13 | 13 | (set! *warn-on-reflection* false)
|
14 | 14 |
|
15 |
| -(defn ssl-echo-handler |
16 |
| - [s c] |
17 |
| - (is (some? (:ssl-session c)) "SSL session should be defined") |
18 |
| - (s/connect |
19 |
| - ; note we need to inspect the SSL session *after* we start reading |
20 |
| - ; data. Otherwise, the session might not be set up yet. |
21 |
| - (s/map (fn [msg] |
22 |
| - (is (= (.getSubjectDN ^X509Certificate ssl/client-cert) |
23 |
| - (.getSubjectDN ^X509Certificate (first (.getPeerCertificates (:ssl-session c)))))) |
24 |
| - msg) |
25 |
| - s) |
26 |
| - s)) |
| 15 | +(defn ssl-echo-handler [ssl-session] |
| 16 | + (fn [s c] |
| 17 | + (s/connect |
| 18 | + ;; note we need to capture the SSL session *after* we start |
| 19 | + ;; reading data. Otherwise, the session might not be set up yet. |
| 20 | + (s/map (fn [msg] |
| 21 | + (reset! ssl-session (:ssl-session c)) |
| 22 | + msg) |
| 23 | + s) |
| 24 | + s))) |
27 | 25 |
|
28 | 26 | (deftest test-ssl-echo
|
29 |
| - (with-server (tcp/start-server ssl-echo-handler |
30 |
| - {:port 10001 |
31 |
| - :ssl-context ssl/server-ssl-context}) |
32 |
| - (let [c @(tcp/client {:host "localhost" |
33 |
| - :port 10001 |
34 |
| - :ssl-context ssl/client-ssl-context})] |
35 |
| - (s/put! c "foo") |
36 |
| - (is (= "foo" (bs/to-string @(s/take! c))))))) |
| 27 | + (let [ssl-session (atom nil)] |
| 28 | + (with-server (tcp/start-server (ssl-echo-handler ssl-session) |
| 29 | + {:port 10001 |
| 30 | + :ssl-context ssl/server-ssl-context}) |
| 31 | + (let [c @(tcp/client {:host "localhost" |
| 32 | + :port 10001 |
| 33 | + :ssl-context ssl/client-ssl-context})] |
| 34 | + (s/put! c "foo") |
| 35 | + (is (= "foo" (bs/to-string @(s/take! c)))) |
| 36 | + (is (some? @ssl-session) "SSL session should be defined") |
| 37 | + (is (= (.getSubjectDN ^X509Certificate ssl/client-cert) |
| 38 | + (.getSubjectDN ^X509Certificate (first (.getPeerCertificates @ssl-session))))))))) |
0 commit comments