Skip to content

Commit

Permalink
test/test_puma_server_ssl.rb - add test_http_rejection
Browse files Browse the repository at this point in the history
Add History.md item
  • Loading branch information
MSP-Greg committed May 13, 2020
1 parent ee85962 commit 1f439c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -26,6 +26,7 @@
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022)

* Bugfixes
* Close client http connections made to an ssl server with TLSv1.3 (#2116)
* Do not set user_config to quiet by default to allow for file config (#2074)
* Always close SSL connection in Puma::ControlCLI (#2211)
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
Expand Down
38 changes: 38 additions & 0 deletions test/test_puma_server_ssl.rb
Expand Up @@ -203,6 +203,44 @@ def test_tls_v1_1_rejection
assert_match(msg, @events.error.message) if @events.error
end
end

def test_http_rejection
body_http = nil
body_https = nil

start_server

http = Net::HTTP.new @host, @server.connected_ports[0]
http.use_ssl = false
http.read_timeout = 6

tcp = Thread.new do
req_http = Net::HTTP::Get.new "/", {}
assert_raises(Errno::ECONNREFUSED, EOFError) do
http.start.request(req_http) { |rep| body_http = rep.body }
end
end

ssl = Thread.new do
@http.start do
req_https = Net::HTTP::Get.new "/", {}
@http.request(req_https) { |rep_https| body_https = rep_https.body }
end
end

tcp.join
ssl.join
http.finish
sleep 1.0

assert_nil body_http
assert_equal "https", body_https

thread_pool = @server.instance_variable_get(:@thread_pool)
busy_threads = thread_pool.spawned - thread_pool.waiting

assert busy_threads.zero?, "Our connection is wasn't dropped"
end
end unless DISABLE_SSL

# client-side TLS authentication tests
Expand Down

0 comments on commit 1f439c0

Please sign in to comment.