Permalink
Browse files

Merge pull request #146 from johncant/master

Added test for NTLM authentication
  • Loading branch information...
2 parents 4a5b8d8 + 25548cb commit 0f6d1d1036b3fd6e738fbb4fa97d704407a5923d @nahi committed Dec 2, 2013
Showing with 32 additions and 0 deletions.
  1. +5 −0 Gemfile
  2. +27 −0 test/test_auth.rb
View
@@ -12,6 +12,11 @@ group :development do
gem 'test-unit'
gem 'ci_reporter'
gem 'simplecov-rcov'
+ gem 'pry'
+ gem 'rack'
+ gem 'rubysspi'
+ gem 'rubyntlm'
+ gem 'rack-ntlm-test-service'
end
gemspec
View
@@ -1,5 +1,9 @@
require File.expand_path('helper', File.dirname(__FILE__))
require 'digest/md5'
+require 'rack'
+require 'rack/lint'
+require 'rack/showexceptions'
+require 'rack-ntlm'
class TestAuth < Test::Unit::TestCase
include Helper
@@ -34,6 +38,22 @@ def setup_server
'/digest_sess_auth',
WEBrick::HTTPServlet::ProcHandler.new(method(:do_digest_sess_auth).to_proc)
)
+ # NTLM endpoint
+ ntlm_handler = Rack::Handler::WEBrick.new(@server,
+ Rack::Builder.app do
+ use Rack::ShowExceptions
+ use Rack::ContentLength
+ use Rack::Ntlm, {:uri_pattern => /.*/, :auth => {:username => "admin", :password => "admin"}}
+ run lambda { |env| [200, { 'Content-Type' => 'text/html' }, ['ntlm_auth OK']] }
+ end
+ )
+ @server.mount(
+ '/ntlm_auth',
+ WEBrick::HTTPServlet::ProcHandler.new(Proc.new do |req, res|
+ ntlm_handler.service(req, res)
+ end)
+ )
+ # Htpasswd
htpasswd = File.join(File.dirname(__FILE__), 'htpasswd')
htpasswd_userdb = WEBrick::HTTPAuth::Htpasswd.new(htpasswd)
htdigest = File.join(File.dirname(__FILE__), 'htdigest')
@@ -95,6 +115,13 @@ def do_digest_sess_auth(req, res)
res.body = 'digest_sess_auth OK' + req.query_string.to_s
end
+ def test_ntlm_auth
+ c = HTTPClient.new
+ c.set_auth("http://localhost:#{serverport}/ntlm_auth", 'admin', 'admin')
+ assert_equal('ntlm_auth OK', c.get_content("http://localhost:#{serverport}/ntlm_auth"))
+ puts c.inspect
+ end
+
def test_basic_auth
c = HTTPClient.new
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')

0 comments on commit 0f6d1d1

Please sign in to comment.