summaryrefslogtreecommitdiff
path: root/test/webrick/test_server.rb
diff options
context:
space:
mode:
authorJohn W Higgins <wishdev@gmail.com>2020-07-26 00:25:37 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-24 21:31:55 +0900
commit4715a24dd277515077af441c1d31aeb2431917f5 (patch)
treea0f0311426a9ef96d59366a7fa18333ed81e3bda /test/webrick/test_server.rb
parentc06eab13290757fc326bb2a6e3ac25cd53e00894 (diff)
[ruby/webrick] Ensure server port numbers are numeric and ensure they are stored as integers
https://github.com/ruby/webrick/commit/86ed621e11
Diffstat (limited to 'test/webrick/test_server.rb')
-rw-r--r--test/webrick/test_server.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb
index 9a3a8f1..aa40a72 100644
--- a/test/webrick/test_server.rb
+++ b/test/webrick/test_server.rb
@@ -172,4 +172,32 @@ class TestWEBrickServer < Test::Unit::TestCase
pipe.last.puts('')
assert_join_threads([server_thread])
end
+
+ def test_port_numbers
+ config = {
+ :BindAddress => '0.0.0.0',
+ :Logger => WEBrick::Log.new([], WEBrick::BasicLog::WARN),
+ }
+
+ ports = [0, "0"]
+
+ ports.each do |port|
+ config[:Port]= port
+ server = WEBrick::GenericServer.new(config)
+ server_thread = Thread.start { server.start }
+ client_thread = Thread.start {
+ sleep 0.1 until server.status == :Running || !server_thread.status
+ server_port = server.listeners[0].addr[1]
+ server.stop
+ assert_equal server.config[:Port], server_port
+ sleep 0.1 until server.status == :Stop || !server_thread.status
+ }
+ assert_join_threads([client_thread, server_thread])
+ end
+
+ assert_raise(ArgumentError) do
+ config[:Port]= "FOO"
+ WEBrick::GenericServer.new(config)
+ end
+ end
end