Skip to content

[wishlist] merge changes from gitlab_omniauth-ldap #82

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7edf27d
Fix ldap blank password
Jun 26, 2012
536c321
Report missing credentials to the Rails application.
patthoyts Jul 20, 2012
f038dd8
Merge pull request #1 from patthoyts/pt/failure-reporting
dzaporozhets Jul 21, 2012
d92ef39
Fixed test and travis
dzaporozhets Dec 30, 2012
2d45b8d
badge addded
dzaporozhets Dec 30, 2012
8e4ceb5
rename gemspec
dzaporozhets Dec 30, 2012
ed838fc
Update net-ldap dependency
dzaporozhets Apr 26, 2013
8c50f19
Gemfile.lock: update net-ldap to fix LDAP authentication issues
davvid Jun 13, 2013
b8c5e41
Merge pull request #5 from davvid/net-ldap
dzaporozhets Jun 13, 2013
daa9b62
version up to 1.0.3
dzaporozhets Jun 13, 2013
76d7754
Merge branch 'master' of https://github.com/intridea/omniauth-ldap
Jan 31, 2014
e728b00
Merge pull request #10 from jhollingsworth/sync-intridea-omniauth-ldap
dzaporozhets Feb 1, 2014
80f438f
Push version of net-ldap dependency to get rid of utf-8 bug:
JanBessai Aug 27, 2014
54a6021
push versions in Gemfile.lock
JanBessai Sep 2, 2014
62a43f4
Merge branch 'master' into 'master'
jacobvosmaer Sep 8, 2014
aaac562
Bump VERSION to 1.1.0
jacobvosmaer Sep 8, 2014
14f97bd
Bump dependencies
dzaporozhets Oct 29, 2014
a225c09
Merge branch 'bump-net-ldap' into 'master'
dzaporozhets Oct 29, 2014
cfbb904
Bump version
dzaporozhets Oct 29, 2014
7c37690
Merge branch 'bump-net-ldap'
dzaporozhets Oct 29, 2014
f2acd1f
Escape wildcards in username.
DouweM Mar 6, 2015
1bfda92
Add ruby 2.1.5 to travis
dzaporozhets Mar 7, 2015
5af0071
Merge branch 'ldap-filter-eq' into 'master'
dzaporozhets Mar 10, 2015
2dd5b77
Bump version to 1.2.1.
DouweM Mar 17, 2015
81d2e68
Update gems.
DouweM Mar 17, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.project
coverage
/Gemfile.lock
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
branches:
only:
- 'master'
rvm:
- 2.0.0
- 2.1.5
script: "bundle exec rspec spec"
9 changes: 4 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ source 'http://rubygems.org'
gemspec

group :development, :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'growl'
gem 'rb-fsevent'
gem 'rspec'
gem 'pry'
gem 'rake'
gem 'rack-test'
end
49 changes: 49 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
PATH
remote: .
specs:
gitlab_omniauth-ldap (1.2.1)
net-ldap (~> 0.9)
omniauth (~> 1.0)
pyu-ruby-sasl (~> 0.0.3.1)
rubyntlm (~> 0.3)

GEM
remote: http://rubygems.org/
specs:
coderay (1.0.8)
diff-lcs (1.1.3)
hashie (3.4.0)
method_source (0.8.1)
net-ldap (0.11)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
pyu-ruby-sasl (0.0.3.3)
rack (1.4.1)
rack-test (0.6.2)
rack (>= 1.0)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.1)
rubyntlm (0.5.0)
slop (3.3.3)

PLATFORMS
ruby

DEPENDENCIES
gitlab_omniauth-ldap!
pry
rack-test
rake
rspec
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OmniAuth LDAP
# GitLab fork | OmniAuth LDAP [![build status](https://secure.travis-ci.org/gitlabhq/omniauth-ldap.png)](https://travis-ci.org/gitlabhq/omniauth-ldap)

== LDAP
### LDAP

Use the LDAP strategy as a middleware in your application:

Expand Down
13 changes: 4 additions & 9 deletions omniauth-ldap.gemspec → gitlab_omniauth-ldap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ Gem::Specification.new do |gem|
gem.email = ["[email protected]"]
gem.description = %q{A LDAP strategy for OmniAuth.}
gem.summary = %q{A LDAP strategy for OmniAuth.}
gem.homepage = "https://github.com/intridea/omniauth-ldap"
gem.homepage = "https://github.com/gitlabhq/omniauth-ldap"
gem.license = "MIT"

gem.add_runtime_dependency 'omniauth', '~> 1.0'
gem.add_runtime_dependency 'net-ldap', '~> 0.3.1'
gem.add_runtime_dependency 'net-ldap', '~> 0.9'
gem.add_runtime_dependency 'pyu-ruby-sasl', '~> 0.0.3.1'
gem.add_runtime_dependency 'rubyntlm', '~> 0.1.1'
gem.add_development_dependency 'rspec', '~> 2.7'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'libnotify'
gem.add_development_dependency 'ruby-debug19'
gem.add_runtime_dependency 'rubyntlm', '~> 0.3'

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "omniauth-ldap"
gem.name = "gitlab_omniauth-ldap"
gem.require_paths = ["lib"]
gem.version = OmniAuth::LDAP::VERSION
end
1 change: 1 addition & 0 deletions lib/omniauth-ldap/adaptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def initialize(configuration={})
:encryption => method,
:base => @base
}

@bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple)


Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth-ldap/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module LDAP
VERSION = "1.0.4"
VERSION = "1.2.1"
end
end
6 changes: 4 additions & 2 deletions lib/omniauth/strategies/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def callback_phase
return fail!(:missing_credentials) if missing_credentials?
begin
@ldap_user_info = @adaptor.bind_as(:filter => filter(@adaptor), :size => 1, :password => request['password'])

return fail!(:invalid_credentials) if !@ldap_user_info

@user_info = self.class.map_user(@@config, @ldap_user_info)
Expand All @@ -51,9 +52,10 @@ def callback_phase

def filter adaptor
if adaptor.filter and !adaptor.filter.empty?
Net::LDAP::Filter.construct(adaptor.filter % {username: @options[:name_proc].call(request['username'])})
username = Net::LDAP::Filter.escape(@options[:name_proc].call(request['username']))
Net::LDAP::Filter.construct(adaptor.filter % { username: username })
else
Net::LDAP::Filter.eq(adaptor.uid, @options[:name_proc].call(request['username']))
Net::LDAP::Filter.equals(adaptor.uid, @options[:name_proc].call(request['username']))
end
end

Expand Down
65 changes: 64 additions & 1 deletion spec/omniauth/strategies/ldap_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'

describe "OmniAuth::Strategies::LDAP" do
# :title => "My LDAP",
# :host => '10.101.10.1',
Expand Down Expand Up @@ -59,6 +60,25 @@ class MyLdapProvider < OmniAuth::Strategies::LDAP; end
@adaptor.stub(:bind_as).and_return(false)
end

it 'should fail with missing_credentials' do
post('/auth/ldap/callback', {})
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{missing_credentials}
end

it 'should redirect to error page' do
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{invalid_credentials}
end

it 'should redirect to error page when there is exception' do
@adaptor.stub(:bind_as).and_throw(Exception.new('connection_error'))
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{ldap_error}
end

context "when username is not preset" do
it 'should redirect to error page' do
post('/auth/ldap/callback', {})
Expand Down Expand Up @@ -139,7 +159,7 @@ class MyLdapProvider < OmniAuth::Strategies::LDAP; end
before(:each) do
@adaptor.stub(:filter)
@adaptor.stub(:bind_as).and_return(Net::LDAP::Entry.from_single_ldif_string(
%Q{dn: cn=ping, dc=intridea, dc=com
%Q{dn: cn=ping, dc=intridea, dc=com
mail: [email protected]
givenname: Ping
sn: Yu
Expand Down Expand Up @@ -190,5 +210,48 @@ class MyLdapProvider < OmniAuth::Strategies::LDAP; end
auth_hash.info.description.should == 'omniauth-ldap'
end
end

context 'alternate fields' do
let(:auth_hash){ last_request.env['omniauth.auth'] }

before(:each) do
@adaptor.stub(:filter)
@adaptor.stub(:bind_as).and_return(Net::LDAP::Entry.from_single_ldif_string(
%Q{dn: cn=ping, dc=intridea, dc=com
userprincipalname: [email protected]
givenname: Ping
sn: Yu
telephonenumber: 555-555-5555
mobile: 444-444-4444
uid: ping
title: dev
address: k street
l: Washington
st: DC
co: U.S.A
postofficebox: 20001
wwwhomepage: www.intridea.com
jpegphoto: http://www.intridea.com/ping.jpg
description: omniauth-ldap
}
))
end

it 'should map user info to Auth Hash' do
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
auth_hash.uid.should == 'cn=ping, dc=intridea, dc=com'
auth_hash.info.email.should == '[email protected]'
auth_hash.info.first_name.should == 'Ping'
auth_hash.info.last_name.should == 'Yu'
auth_hash.info.phone.should == '555-555-5555'
auth_hash.info.mobile.should == '444-444-4444'
auth_hash.info.nickname.should == 'ping'
auth_hash.info.title.should == 'dev'
auth_hash.info.location.should == 'k street, Washington, DC, U.S.A 20001'
auth_hash.info.url.should == 'www.intridea.com'
auth_hash.info.image.should == 'http://www.intridea.com/ping.jpg'
auth_hash.info.description.should == 'omniauth-ldap'
end
end
end
end
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
$:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
SimpleCov.start
require 'rspec'
require 'rack/test'
require 'omniauth'
Expand Down