Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for NTLM authentication #146

Merged
merged 2 commits into from Dec 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gemfile
Expand Up @@ -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
27 changes: 27 additions & 0 deletions test/test_auth.rb
@@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down