Skip to content

Commit d3dc025

Browse files
authored
Merge pull request #607 from bevuta/fix-tcp-ssl-server-test
Fix assertions in aleph.tcp-ssl-test
2 parents 1e92640 + 6f97fa3 commit d3dc025

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

test/aleph/tcp_ssl_test.clj

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@
1212

1313
(set! *warn-on-reflection* false)
1414

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)))
2725

2826
(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

Comments
 (0)