Skip to content

Commit

Permalink
Test system selecting tls server socket port
Browse files Browse the repository at this point in the history
Call tls-bind with port 0, and get the bound port using sockaddr-port.

Related: #961
  • Loading branch information
shirok committed Nov 18, 2023
1 parent 2f70927 commit af81ddc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ext/tls/test.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(use gauche.test)
(use gauche.threads)
(use gauche.net)
(use gauche.connection)

(use file.util)

Expand Down Expand Up @@ -28,11 +29,15 @@
(build-path (sys-dirname (current-load-path)) "data" filename))

(let ((serv (make <mbed-tls> :server-name "localhost"))
(serv-port #f)
(serv-thread #f))
(unwind-protect
(begin
(test* "simple communication" #t
(is-a? (tls-bind serv #f 8087 'tcp) <mbed-tls>))
(test* "bind" #t
(begin
(tls-bind serv #f 0 'tcp)
(set! serv-port (sockaddr-port (connection-self-address serv)))
(and (integer? serv-port) (positive? serv-port))))
(test* "loading private key" #t
(boolean
(tls-load-private-key serv (datafile "test-key.pem")
Expand All @@ -47,11 +52,12 @@
(let1 clnt (make <mbed-tls> :server-name "localhost")
(unwind-protect
(begin
(tls-connect clnt "localhost" 8087 'tcp)
(tls-connect clnt "localhost" serv-port 'tcp)
(display "Aloha!\r\n" (tls-output-port clnt))
(flush (tls-output-port clnt))
(read-line (tls-input-port clnt)))
(tls-close clnt)))))
(thread-join! serv-thread)
)
(tls-close serv)))
]
Expand Down

0 comments on commit af81ddc

Please sign in to comment.