Class: DigestAuthServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/mechanize/test_case.rb

Constant Summary collapse

@@authenticator =
WEBrick::HTTPAuth::DigestAuth.new({
  :UserDB => htpd,
  :Realm  => 'Blah',
  :Algorithm => 'MD5',
  :Logger => Logger.new(nil)
})

Instance Method Summary collapse

Instance Method Details

#do_GET(req, res) ⇒ Object Also known as: do_POST



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/mechanize/test_case.rb', line 168

def do_GET(req,res)
  def req.request_time; Time.now; end
  def req.request_uri; '/digest_auth'; end
  def req.request_method; "GET"; end

  begin
    @@authenticator.authenticate(req,res)
    res.body = 'You are authenticated'
  rescue WEBrick::HTTPStatus::Unauthorized
    res.status = 401
  end
  FileUtils.rm('digest.htpasswd') if File.exists?('digest.htpasswd')
end