rack-auth-ldap 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/examples/ldap.yml +2 -2
- data/lib/rack/auth/ldap.rb +10 -6
- data/lib/rack/auth/ldap/version.rb +1 -1
- data/rack-auth-ldap.gemspec +8 -0
- data/spec/config/ldap.yml +13 -0
- data/spec/config/users.ldif +14 -0
- data/spec/rack-auth-ldap_spec.rb +99 -0
- metadata +139 -5
- checksums.yaml +0 -15
data/Gemfile
ADDED
data/examples/ldap.yml
CHANGED
data/lib/rack/auth/ldap.rb
CHANGED
@@ -2,19 +2,23 @@ require 'rack'
|
|
2
2
|
require 'ldap'
|
3
3
|
require 'rack/auth/abstract/handler'
|
4
4
|
require 'rack/auth/abstract/request'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
module Rack
|
7
8
|
module Auth
|
8
9
|
|
9
10
|
class Config
|
10
|
-
def initialize(options = {})
|
11
|
+
def initialize(options = { :file => './ldap.yml'})
|
11
12
|
@values = defaults
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
target = (ENV['RACK_ENV'])? ENV['RACK_ENV'] : 'test'
|
14
|
+
config_values = ::YAML.load_file(::File.expand_path(options[:file], Dir.pwd))[target]
|
15
|
+
debug = ::File.open("/tmp/test.txt",'a+')
|
16
|
+
debug.puts ENV['RACK_ENV']
|
17
|
+
debug.close
|
18
|
+
config_values.keys.each do |key|
|
19
|
+
config_values[key.to_sym] = config_values.delete(key)
|
15
20
|
end
|
16
|
-
@values.merge!
|
17
|
-
@values.merge! config_options
|
21
|
+
@values.merge! config_values
|
18
22
|
@values.keys.each do |meth|
|
19
23
|
bloc = Proc.new {@values[meth] }
|
20
24
|
self.class.send :define_method, meth, &bloc
|
data/rack-auth-ldap.gemspec
CHANGED
@@ -14,6 +14,14 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.rubyforge_project = 'nowarning'
|
15
15
|
s.description = %q{rack-auth-ldap : provide LDAP authentication for Rack middelware}
|
16
16
|
s.has_rdoc = true
|
17
|
+
s.add_development_dependency('rspec')
|
18
|
+
s.add_development_dependency('yard')
|
19
|
+
s.add_development_dependency('rdoc')
|
20
|
+
s.add_development_dependency('roodi')
|
21
|
+
s.add_development_dependency('code_statistics')
|
22
|
+
s.add_development_dependency('yard-rspec')
|
23
|
+
s.add_dependency('ruby-ldap')
|
24
|
+
s.add_dependency('rack')
|
17
25
|
s.required_ruby_version = '>= 1.9.0'
|
18
26
|
s.license = "BSD"
|
19
27
|
s.files = `git ls-files`.split($/)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
dn: ou=users,dc=test
|
2
|
+
objectclass: top
|
3
|
+
objectclass: organizationalUnit
|
4
|
+
ou: users
|
5
|
+
|
6
|
+
dn: uid=testuser,ou=users,dc=test
|
7
|
+
objectclass: top
|
8
|
+
objectclass: person
|
9
|
+
objectclass: organizationalPerson
|
10
|
+
objectclass: inetOrgPerson
|
11
|
+
cn: LDAP test user
|
12
|
+
sn: TEST
|
13
|
+
uid: test
|
14
|
+
userPassword: testpassword
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'ladle'
|
2
|
+
require 'rack/auth/ldap'
|
3
|
+
require 'rack/lint'
|
4
|
+
require 'rack/mock'
|
5
|
+
|
6
|
+
describe Rack::Auth::Ldap do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
@ldap_server = Ladle::Server.new({
|
10
|
+
:quiet => true, :port => 3897,
|
11
|
+
:ldif => "./spec/config/users.ldif",
|
12
|
+
:domain => "dc=test",
|
13
|
+
:tmpdir => '/tmp'
|
14
|
+
}).start
|
15
|
+
end
|
16
|
+
|
17
|
+
after :all do
|
18
|
+
@ldap_server.stop if @ldap_server
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def realm
|
23
|
+
'test'
|
24
|
+
end
|
25
|
+
|
26
|
+
def unprotected_app
|
27
|
+
Rack::Lint.new lambda { |env|
|
28
|
+
[ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def protected_app
|
33
|
+
app = Rack::Auth::Ldap.new(unprotected_app,{:file => "./spec/config/ldap.yml"})
|
34
|
+
app.realm = realm
|
35
|
+
app
|
36
|
+
end
|
37
|
+
|
38
|
+
before do
|
39
|
+
@request = Rack::MockRequest.new(protected_app)
|
40
|
+
end
|
41
|
+
|
42
|
+
def request_with_basic_auth(username, password, &block)
|
43
|
+
request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
|
44
|
+
end
|
45
|
+
|
46
|
+
def request(headers = {})
|
47
|
+
yield @request.get('/', headers)
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_basic_auth_challenge(response)
|
51
|
+
response.client_error?.should be true
|
52
|
+
response.status.should == 401
|
53
|
+
response.should include 'WWW-Authenticate'
|
54
|
+
response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/
|
55
|
+
response.body.should be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should challenge correctly when no credentials are specified' do
|
59
|
+
request do |response|
|
60
|
+
assert_basic_auth_challenge response
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should rechallenge if incorrect credentials are specified' do
|
65
|
+
request_with_basic_auth 'falseuser', 'password' do |response|
|
66
|
+
response.client_error?.should be true
|
67
|
+
assert_basic_auth_challenge response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return application output if correct credentials are specified' do
|
72
|
+
request_with_basic_auth 'testuser', 'testpassword' do |response|
|
73
|
+
response.client_error?.should be false
|
74
|
+
response.status.should == 200
|
75
|
+
response.body.to_s.should eq 'Hi testuser'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return 400 Bad Request if different auth scheme used' do
|
80
|
+
request 'HTTP_AUTHORIZATION' => 'Digest params' do |response|
|
81
|
+
response.client_error?.should be true
|
82
|
+
response.status.should == 400
|
83
|
+
response.should_not include 'WWW-Authenticate'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return 400 Bad Request for a malformed authorization header' do
|
88
|
+
request 'HTTP_AUTHORIZATION' => '' do |response|
|
89
|
+
response.client_error?.should be true
|
90
|
+
response.status.should == 400
|
91
|
+
response.should_not include 'WWW-Authenticate'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should takes realm as optional constructor arg' do
|
96
|
+
app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
|
97
|
+
realm.should == app.realm
|
98
|
+
end
|
99
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-auth-ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Romain GEORGES
|
@@ -9,7 +10,135 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
date: 2014-04-29 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yard
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: roodi
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: code_statistics
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: ruby-ldap
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rack
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
13
142
|
description: ! 'rack-auth-ldap : provide LDAP authentication for Rack middelware'
|
14
143
|
email: romain@ultragreen.net
|
15
144
|
executables: []
|
@@ -17,6 +146,7 @@ extensions: []
|
|
17
146
|
extra_rdoc_files: []
|
18
147
|
files:
|
19
148
|
- COPYRIGHT
|
149
|
+
- Gemfile
|
20
150
|
- README.rdoc
|
21
151
|
- Rakefile
|
22
152
|
- examples/config.ru
|
@@ -25,29 +155,33 @@ files:
|
|
25
155
|
- lib/rack/auth/ldap.rb
|
26
156
|
- lib/rack/auth/ldap/version.rb
|
27
157
|
- rack-auth-ldap.gemspec
|
158
|
+
- spec/config/ldap.yml
|
159
|
+
- spec/config/users.ldif
|
160
|
+
- spec/rack-auth-ldap_spec.rb
|
28
161
|
homepage: http://www.github.com/lecid/rack-auth-ldap
|
29
162
|
licenses:
|
30
163
|
- BSD
|
31
|
-
metadata: {}
|
32
164
|
post_install_message:
|
33
165
|
rdoc_options: []
|
34
166
|
require_paths:
|
35
167
|
- lib
|
36
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
37
170
|
requirements:
|
38
171
|
- - ! '>='
|
39
172
|
- !ruby/object:Gem::Version
|
40
173
|
version: 1.9.0
|
41
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
42
176
|
requirements:
|
43
177
|
- - ! '>='
|
44
178
|
- !ruby/object:Gem::Version
|
45
179
|
version: '0'
|
46
180
|
requirements: []
|
47
181
|
rubyforge_project: nowarning
|
48
|
-
rubygems_version:
|
182
|
+
rubygems_version: 1.8.29
|
49
183
|
signing_key:
|
50
|
-
specification_version:
|
184
|
+
specification_version: 3
|
51
185
|
summary: Rack middleware providing LDAP authentication
|
52
186
|
test_files: []
|
53
187
|
has_rdoc: true
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ODg4YmYwN2IxMTUwMzNkN2E3NWIyZTY3ODAwZTg0NzQ2MmZkYTZhYw==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NjYwMjBlMmZmZDQxYjc2OWYxMGVhODFiNzEyMWMyNzU2ZTNhZWQ2Mg==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YWNjNjg4MzliN2M1MmZhNzJlMTE2NTYyODM1ZTVhMWJjZWMxMTA4ZTlkODUw
|
10
|
-
OTAyZWM0OGVlY2QwNjUzMjkzZjAyMzFhYTk2MWUwMGU0NTE1NTI0Njc3NDU3
|
11
|
-
YjAxNTYxNDI4Mjg5N2VjMGFkYzVjODQyYjFhNTk4Zjc0ZmMzMWM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODMyZWI1MTc1YTFhYWYyZjdjZTY0MTVhN2YxOGFlOWRhODhjODE4N2MzZjZk
|
14
|
-
N2IxYmY1MjViNGFhMTExMWE3MmZhMmEzOTYyODAxYzIzYWJmYTExNTRiNGE5
|
15
|
-
MTBlMzczYTA0MjJlMzU2NWRiOWRjYjQyNjE4ZjgwNDM5M2Q3NGM=
|