spec/support/dummy_server.rb in http-0.8.0.pre4 vs spec/support/dummy_server.rb in http-0.8.0.pre5
- old
+ new
@@ -3,10 +3,11 @@
require "support/black_hole"
require "support/dummy_server/servlet"
require "support/servers/config"
require "support/servers/runner"
+require "support/ssl_helper"
class DummyServer < WEBrick::HTTPServer
include ServerConfig
CONFIG = {
@@ -14,39 +15,27 @@
:Port => 0,
:AccessLog => BlackHole,
:Logger => BlackHole
}.freeze
- def initialize(options = {})
- if options[:ssl]
- override_config = {
- :SSLEnable => true,
- :SSLStartImmediately => true
- }
- else
- override_config = {}
- end
+ SSL_CONFIG = CONFIG.merge(
+ :SSLEnable => true,
+ :SSLStartImmediately => true
+ ).freeze
- super CONFIG.merge(override_config)
-
+ def initialize(options = {})
+ super(options[:ssl] ? SSL_CONFIG : CONFIG)
mount("/", Servlet)
end
def endpoint
- "#{ssl? ? 'https' : 'http'}://#{addr}:#{port}"
+ "#{scheme}://#{addr}:#{port}"
end
+ def scheme
+ config[:SSLEnable] ? "https" : "http"
+ end
+
def ssl_context
- @ssl_context ||= begin
- context = OpenSSL::SSL::SSLContext.new
- context.verify_mode = OpenSSL::SSL::VERIFY_PEER
- context.key = OpenSSL::PKey::RSA.new(
- File.read(File.join(certs_dir, "server.key"))
- )
- context.cert = OpenSSL::X509::Certificate.new(
- File.read(File.join(certs_dir, "server.crt"))
- )
- context.ca_file = File.join(certs_dir, "ca.crt")
- context
- end
+ @ssl_context ||= SSLHelper.server_context
end
end