Skip to content
Snippets Groups Projects
Commit d92ef39d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Fixed test and travis

parent f038dd85
No related branches found
No related tags found
No related merge requests found
branches:
only:
- 'master'
rvm:
- 1.9.2
script: "bundle exec rspec spec"
Loading
@@ -3,9 +3,8 @@ source 'http://rubygems.org'
Loading
@@ -3,9 +3,8 @@ source 'http://rubygems.org'
gemspec gemspec
   
group :development, :test do group :development, :test do
gem 'guard' gem 'rspec'
gem 'guard-rspec' gem 'pry'
gem 'guard-bundler' gem 'rake'
gem 'growl' gem 'rack-test'
gem 'rb-fsevent'
end end
PATH PATH
remote: . remote: .
specs: specs:
omniauth-ldap (1.0.2) gitlab_omniauth-ldap (1.0.2)
net-ldap (~> 0.2.2) net-ldap (~> 0.2.2)
omniauth (~> 1.0) omniauth (~> 1.0)
pyu-ruby-sasl (~> 0.0.3.1) pyu-ruby-sasl (~> 0.0.3.1)
Loading
@@ -10,70 +10,40 @@ PATH
Loading
@@ -10,70 +10,40 @@ PATH
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
archive-tar-minitar (0.5.2) coderay (1.0.8)
columnize (0.3.4)
diff-lcs (1.1.3) diff-lcs (1.1.3)
ffi (1.0.9)
growl (1.0.3)
guard (0.8.8)
thor (~> 0.14.6)
guard-bundler (0.1.3)
bundler (>= 1.0.0)
guard (>= 0.2.2)
guard-rspec (0.5.0)
guard (>= 0.8.4)
hashie (1.2.0) hashie (1.2.0)
libnotify (0.5.7) method_source (0.8.1)
ffi (= 1.0.9)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
multi_json (1.0.3)
net-ldap (0.2.2) net-ldap (0.2.2)
omniauth (1.0.1) omniauth (1.1.1)
hashie (~> 1.2) hashie (~> 1.2)
rack rack
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
pyu-ruby-sasl (0.0.3.3) pyu-ruby-sasl (0.0.3.3)
rack (1.3.5) rack (1.4.1)
rack-test (0.6.1) rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
rb-fsevent (0.4.3.1) rake (10.0.3)
rspec (2.7.0) rspec (2.12.0)
rspec-core (~> 2.7.0) rspec-core (~> 2.12.0)
rspec-expectations (~> 2.7.0) rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.7.0) rspec-mocks (~> 2.12.0)
rspec-core (2.7.1) rspec-core (2.12.2)
rspec-expectations (2.7.0) rspec-expectations (2.12.1)
diff-lcs (~> 1.1.2) diff-lcs (~> 1.1.3)
rspec-mocks (2.7.0) rspec-mocks (2.12.1)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyntlm (0.1.1) rubyntlm (0.1.1)
simplecov (0.5.4) slop (3.3.3)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
thor (0.14.6)
   
PLATFORMS PLATFORMS
ruby ruby
   
DEPENDENCIES DEPENDENCIES
growl gitlab_omniauth-ldap!
guard pry
guard-bundler
guard-rspec
libnotify
omniauth-ldap!
rack-test rack-test
rb-fsevent rake
rspec (~> 2.7) rspec
ruby-debug19
simplecov
Loading
@@ -49,10 +49,10 @@ module OmniAuth
Loading
@@ -49,10 +49,10 @@ module OmniAuth
:base => @base :base => @base
} }
@uri = construct_uri(@host, @port, @method != :plain) @uri = construct_uri(@host, @port, @method != :plain)
@bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple) @bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple)
@auth = sasl_auths({:username => @bind_dn, :password => @password}).first if @bind_method == :sasl @auth = sasl_auths({:username => @bind_dn, :password => @password}).first if @bind_method == :sasl
@auth ||= { :method => @bind_method, @auth ||= { :method => @bind_method,
:username => @bind_dn, :username => @bind_dn,
Loading
@@ -61,11 +61,11 @@ module OmniAuth
Loading
@@ -61,11 +61,11 @@ module OmniAuth
config[:auth] = @auth config[:auth] = @auth
@connection = Net::LDAP.new(config) @connection = Net::LDAP.new(config)
end end
#:base => "dc=yourcompany, dc=com", #:base => "dc=yourcompany, dc=com",
# :filter => "(mail=#{user})", # :filter => "(mail=#{user})",
# :password => psw # :password => psw
def bind_as(args = {}) def bind_as(args = {})
result = false result = false
@connection.open do |me| @connection.open do |me|
rs = me.search args rs = me.search args
Loading
Loading
Loading
@@ -6,22 +6,17 @@ Gem::Specification.new do |gem|
Loading
@@ -6,22 +6,17 @@ Gem::Specification.new do |gem|
gem.email = ["ping@intridea.com"] gem.email = ["ping@intridea.com"]
gem.description = %q{A LDAP strategy for OmniAuth.} gem.description = %q{A LDAP strategy for OmniAuth.}
gem.summary = %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.add_runtime_dependency 'omniauth', '~> 1.0' gem.add_runtime_dependency 'omniauth', '~> 1.0'
gem.add_runtime_dependency 'net-ldap', '~> 0.2.2' gem.add_runtime_dependency 'net-ldap', '~> 0.2.2'
gem.add_runtime_dependency 'pyu-ruby-sasl', '~> 0.0.3.1' gem.add_runtime_dependency 'pyu-ruby-sasl', '~> 0.0.3.1'
gem.add_runtime_dependency 'rubyntlm', '~> 0.1.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.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n") gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.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.require_paths = ["lib"]
gem.version = OmniAuth::LDAP::VERSION gem.version = OmniAuth::LDAP::VERSION
end end
require 'spec_helper' require 'spec_helper'
describe "OmniAuth::Strategies::LDAP" do describe "OmniAuth::Strategies::LDAP" do
# :title => "My LDAP", # :title => "My LDAP",
# :host => '10.101.10.1', # :host => '10.101.10.1',
# :port => 389, # :port => 389,
# :method => :plain, # :method => :plain,
Loading
@@ -8,12 +9,13 @@ describe "OmniAuth::Strategies::LDAP" do
Loading
@@ -8,12 +9,13 @@ describe "OmniAuth::Strategies::LDAP" do
# :uid => 'sAMAccountName', # :uid => 'sAMAccountName',
# :name_proc => Proc.new {|name| name.gsub(/@.*$/,'')} # :name_proc => Proc.new {|name| name.gsub(/@.*$/,'')}
# :bind_dn => 'default_bind_dn' # :bind_dn => 'default_bind_dn'
# :password => 'password' # :password => 'password'
class MyLdapProvider < OmniAuth::Strategies::LDAP; end class MyLdapProvider < OmniAuth::Strategies::LDAP; end
def app def app
Rack::Builder.new { Rack::Builder.new {
use OmniAuth::Test::PhonySession use OmniAuth::Test::PhonySession
use MyLdapProvider, :name => 'ldap', :title => 'MyLdap Form', :host => '192.168.1.145', :base => 'dc=score, dc=local', :name_proc => Proc.new {|name| name.gsub(/@.*$/,'')} use MyLdapProvider, :name => 'ldap', :title => 'MyLdap Form', :host => '192.168.1.145', :base => 'dc=score, dc=local', :name_proc => Proc.new {|name| name.gsub(/@.*$/,'')}
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] } run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
}.to_app }.to_app
end end
Loading
@@ -52,36 +54,42 @@ describe "OmniAuth::Strategies::LDAP" do
Loading
@@ -52,36 +54,42 @@ describe "OmniAuth::Strategies::LDAP" do
@adaptor = mock(OmniAuth::LDAP::Adaptor, {:uid => 'ping'}) @adaptor = mock(OmniAuth::LDAP::Adaptor, {:uid => 'ping'})
OmniAuth::LDAP::Adaptor.stub(:new).and_return(@adaptor) OmniAuth::LDAP::Adaptor.stub(:new).and_return(@adaptor)
end end
context 'failure' do context 'failure' do
before(:each) do before(:each) do
@adaptor.stub(:bind_as).and_return(false) @adaptor.stub(:bind_as).and_return(false)
end end
it 'should raise MissingCredentialsError' do it 'should raise MissingCredentialsError' do
lambda{post('/auth/ldap/callback', {})}.should raise_error OmniAuth::Strategies::LDAP::MissingCredentialsError post('/auth/ldap/callback', {})
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{ldap_error}
end end
it 'should redirect to error page' do
it 'should redirect to error page' do
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
last_response.should be_redirect last_response.should be_redirect
last_response.headers['Location'].should =~ %r{invalid_credentials} last_response.headers['Location'].should =~ %r{invalid_credentials}
end end
it 'should redirect to error page when there is exception' do
it 'should redirect to error page when there is exception' do
@adaptor.stub(:bind_as).and_throw(Exception.new('connection_error')) @adaptor.stub(:bind_as).and_throw(Exception.new('connection_error'))
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
last_response.should be_redirect last_response.should be_redirect
last_response.headers['Location'].should =~ %r{ldap_error} last_response.headers['Location'].should =~ %r{ldap_error}
end end
end end
context 'success' do context 'success' do
let(:auth_hash){ last_request.env['omniauth.auth'] } let(:auth_hash){ last_request.env['omniauth.auth'] }
before(:each) do before(:each) do
@adaptor.stub(:bind_as).and_return({:dn => ['cn=ping, dc=intridea, dc=com'], :mail => ['ping@intridea.com'], :givenname => ['Ping'], :sn => ['Yu'], @adaptor.stub(:bind_as).and_return({:dn => ['cn=ping, dc=intridea, dc=com'], :mail => ['ping@intridea.com'], :givenname => ['Ping'], :sn => ['Yu'],
:telephonenumber => ['555-555-5555'], :mobile => ['444-444-4444'], :uid => ['ping'], :title => ['dev'], :address =>[ 'k street'], :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'], :l => ['Washington'], :st => ['DC'], :co => ["U.S.A"], :postofficebox => ['20001'], :wwwhomepage => ['www.intridea.com'],
:jpegphoto => ['http://www.intridea.com/ping.jpg'], :description => ['omniauth-ldap']}) :jpegphoto => ['http://www.intridea.com/ping.jpg'], :description => ['omniauth-ldap']})
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
end end
it 'should raise MissingCredentialsError' do it 'should raise MissingCredentialsError' do
should_not raise_error OmniAuth::Strategies::LDAP::MissingCredentialsError should_not raise_error OmniAuth::Strategies::LDAP::MissingCredentialsError
end end
Loading
Loading
$:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
SimpleCov.start
require 'rspec' require 'rspec'
require 'rack/test' require 'rack/test'
require 'omniauth' require 'omniauth'
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment