Sha256: b0f111cf2fa83ea1fbaacf15a6d27b24b4bf300bc7d13020e9bbecce6b44d911

Contents?: true

Size: 1.61 KB

Versions: 27

Compression:

Stored size: 1.61 KB

Contents

require "webrick"

include WEBrick

# Run WEBrick. Yields the server to a given block.
def run_webrick(config = {})
  config.update :Port => 8080
  server = HTTPServer.new config
  yield server if block_given?
  ["INT", "TERM"].each { |signal| trap(signal) { server.shutdown } }
  server.start
end

# Returns the SOAP response fixture for a given +file+.
def respond_with(file)
  response_path = File.dirname(__FILE__) + "/../fixtures/response/xml"
  File.read "#{response_path}/#{file}.xml"
end

# Returns HTML links for a given Hash of link URI's and names.
def link_to(links)
  links.map { |link| "<a href='#{link[:uri]}'>#{link[:name]}</a>" }.join("<br>")
end

run_webrick do |server|
  user, password, realm = "user", "password", "realm"

  htdigest = HTTPAuth::Htdigest.new "/tmp/webrick-htdigest"
  htdigest.set_passwd realm, user, password
  authenticator = HTTPAuth::DigestAuth.new :UserDB => htdigest, :Realm => realm

  # Homepage including links to subpages.
  server.mount_proc("/") do |request, response|
    response.body = link_to [
      { :uri => "http-basic-auth", :name => "HTTP basic auth" },
      { :uri => "http-digest-auth", :name => "HTTP digest auth" }
    ]
  end

  # HTTP basic authentication.
  server.mount_proc("/http-basic-auth") do |request, response|
    HTTPAuth.basic_auth(request, response, realm) { |u, p| u == user && p == password }
    response.body = respond_with :authentication
  end

  # HTTP digest authentication.
  server.mount_proc("/http-digest-auth") do |request, response|
    authenticator.authenticate request, response
    response.body = "HTTP digest authentication successfull"
  end
end

Version data entries

27 entries across 27 versions & 6 rubygems

Version Path
savon-xaop-0.7.2.7 spec/integration/server.rb
savon-xaop-0.7.2.6 spec/integration/server.rb
johnreitano-savon-0.7.7.5 spec/integration/server.rb
johnreitano-savon-0.7.7.4 spec/integration/server.rb
johnreitano-savon-0.7.7.3 spec/integration/server.rb
johnreitano-savon-0.7.7.2 spec/integration/server.rb
tictoc-savon-0.7.9 spec/integration/server.rb
savon-xaop-0.7.2.5 spec/integration/server.rb
pyu-savon-0.7.9.3 spec/integration/server.rb
johnreitano-savon-0.7.7.1 spec/integration/server.rb
johnreitano-savon-0.7.2.1 spec/integration/server.rb
savon-xaop-0.7.2.4 spec/integration/server.rb
savon-xaop-0.7.2.3 spec/integration/server.rb
hoopla-savon-0.7.9 spec/integration/server.rb
savon-0.7.9 spec/integration/server.rb
savon-0.7.8 spec/integration/server.rb
savon-0.7.7 spec/integration/server.rb
savon-xaop-0.7.2.2 spec/integration/server.rb
hoopla-savon-0.7.6 spec/integration/server.rb
savon-0.7.6 spec/integration/server.rb