rack-auth-ldap 1.2 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,11 @@
1
- # coding: utf-8
2
1
  # Author : Romain GEORGES
3
-
2
+ require 'version'
4
3
  # the Rack module from Rack Sources
5
4
  module Rack
6
-
7
- # the Rack::Auth module from Rack Sources
5
+ # the Rack::Auth module from Rack Sources
8
6
  module Auth
9
7
  # the current version for Rack::Auth::Ldap => gem rack-auth-ldap
10
8
  # used by gemspec
11
- LDAP_VERSION = "1.2"
9
+ LDAP_VERSION = Version.current
12
10
  end
13
11
  end
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- #inhibit warning : due to net-ldap warning on Socket.tcp
1
+ # inhibit warning : due to net-ldap warning on Socket.tcp
4
2
  $-w = nil
5
3
 
6
4
  require 'rack'
@@ -11,66 +9,62 @@ require 'yaml'
11
9
 
12
10
  # the rack module from Rack Sources
13
11
  module Rack
14
-
15
12
  # the auth module from Rack Sources
16
13
  module Auth
17
-
18
14
  # class Config provide Yaml config mapping for Rack::Auth::Module
19
15
  # the class map ldap configurations values
20
16
  # @note this class is not provide to be used standalone
21
17
  class Config
22
-
23
18
  # initializer for Config class
24
19
  # @param [Hash<Symbol>] options initialisation options
25
20
  # @option options [Symbol] :file The YAML filename (default to ./ldap.yml, the config.ru path)
26
21
  # @return [Config] object himself
27
- def initialize(options = { :file => './ldap.yml'})
22
+ def initialize(options = { file: './ldap.yml' })
28
23
  @values = defaults
29
- target = (ENV['RACK_ENV'])? ENV['RACK_ENV'] : 'test'
24
+ options.merge!(file: './ldap.yml') { |_key, oldval, _newval| oldval }
25
+ target = ENV['RACK_ENV'] || 'test'
30
26
  config_values = load_yaml(::File.expand_path(options[:file], Dir.pwd))[target]
31
- debug = ::File.open("/tmp/test.txt",'a+')
32
- debug.puts ENV['RACK_ENV']
27
+ debug = ::File.open('/tmp/test.txt', 'a+')
28
+ debug.puts ENV.fetch('RACK_ENV', nil)
33
29
  debug.close
34
30
  config_values.keys.each do |key|
35
31
  config_values[key.to_sym] = config_values.delete(key)
36
32
  end
37
33
  @values.merge! config_values
38
34
  @values.keys.each do |meth|
39
- bloc = Proc.new {@values[meth] }
40
- self.class.send :define_method, meth, &bloc
35
+ bloc = proc { @values[meth] }
36
+ self.class.send :define_method, meth, &bloc
41
37
  end
42
38
  end
43
39
 
44
40
  private
45
41
 
46
42
  def load_yaml(file)
47
- if ::File.exist?(file)
48
- ::YAML.load ::ERB.new(IO.read(file)).result
49
- else
50
- raise "Could not load ldap configuration. No such file - #{file}"
51
- end
43
+ raise "Could not load ldap configuration. No such file - #{file}" unless ::File.exist?(file)
44
+
45
+ ::YAML.load ::ERB.new(IO.read(file)).result
52
46
  rescue ::Psych::SyntaxError => e
53
47
  raise "YAML syntax error occurred while parsing #{file}. " \
54
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
48
+ 'Please note that YAML must be consistently indented using spaces. Tabs are not allowed. ' \
55
49
  "Error: #{e.message}"
56
50
  end
57
51
 
58
52
  # private method with default configuration values for LDAP
59
53
  # @return [Hash<Symbol>] the default values of LDAP configuration
60
54
  def defaults
61
- return {
62
- :hostname => 'localhost',
63
- :basedn => 'dc=domain,dc=tld',
64
- :rootdn => '',
65
- :passdn => '',
66
- :auth => false,
67
- :port => 389,
68
- :scope => :subtree,
69
- :username_ldap_attribute => 'uid',
70
- :ldaps => false,
71
- :starttls => false,
72
- :tls_options => nil,
73
- :debug => false
55
+ {
56
+ hostname: 'localhost',
57
+ basedn: 'dc=domain,dc=tld',
58
+ rootdn: '',
59
+ passdn: '',
60
+ auth: false,
61
+ port: 389,
62
+ scope: :subtree,
63
+ username_ldap_attribute: 'uid',
64
+ ldaps: false,
65
+ starttls: false,
66
+ tls_options: nil,
67
+ debug: false
74
68
  }
75
69
  end
76
70
  end
@@ -84,7 +78,6 @@ module Rack
84
78
  # require 'rack/auth/ldap'
85
79
  # use Rack::Auth::Ldap
86
80
  class Ldap < AbstractHandler
87
-
88
81
  # the config read accessor
89
82
  # @attr [Rack::Auth::Config] the read accessor to the LDAP Config object
90
83
  attr_reader :config
@@ -108,6 +101,7 @@ module Rack
108
101
  auth = Ldap::Request.new(env)
109
102
  return unauthorized unless auth.provided?
110
103
  return bad_request unless auth.basic?
104
+
111
105
  if valid?(auth)
112
106
  env['REMOTE_USER'] = auth.username
113
107
  return @app.call(env)
@@ -115,7 +109,6 @@ module Rack
115
109
  unauthorized
116
110
  end
117
111
 
118
-
119
112
  private
120
113
 
121
114
  # forge a challange header for HTTP basic auth with the realm attribut
@@ -130,16 +123,16 @@ module Rack
130
123
  def valid?(auth)
131
124
  # how to connect to the ldap server: ldap, ldaps, ldap + starttls
132
125
  if @config.ldaps
133
- enc = { :method => :simple_tls }
126
+ enc = { method: :simple_tls }
134
127
  elsif @config.starttls
135
- enc = { :method => :start_tls }
128
+ enc = { method: :start_tls }
136
129
  enc[:tls_options] = @config.tls_options if @config.tls_options
137
130
  else
138
- enc = nil # just straight ldap
131
+ enc = nil # just straight ldap
139
132
  end
140
- conn = Net::LDAP.new( :host => @config.hostname, :port => @config.port,
141
- :base => @config.basedn,
142
- :encryption => enc )
133
+ conn = Net::LDAP.new(host: @config.hostname, port: @config.port,
134
+ base: @config.basedn,
135
+ encryption: enc)
143
136
 
144
137
  $stdout.puts "Net::LDAP.new => #{conn.inspect}" if @config.debug
145
138
 
@@ -156,30 +149,26 @@ module Rack
156
149
  $stdout.puts "Net::LDAP::Filter.eq => #{filter.inspect}" if @config.debug
157
150
 
158
151
  # find the user and rebind as them to test the password
159
- #return conn.bind_as(:filter => filter, :password => auth.password)
152
+ # return conn.bind_as(:filter => filter, :password => auth.password)
160
153
  $stdout.puts "doing bind_as password.size: #{auth.password.size}..." if @config.debug
161
- ret = conn.bind_as(:filter => filter, :password => auth.password)
154
+ ret = conn.bind_as(filter: filter, password: auth.password)
162
155
  $stdout.puts "bind_as => #{ret.inspect}" if @config.debug
163
156
  ret
164
157
  end
165
158
 
166
- private
167
-
168
-
169
159
  # Request class the LDAP credentials authenticator
170
160
  # @note please do not instantiate manually, used by Rack::Auth:Ldap
171
161
  class Request < Auth::AbstractRequest
172
-
173
162
  # return true if the auth scheme provide is really a basic scheme
174
163
  # @return [FalseClass,TrueClass] the result
175
164
  def basic?
176
- !parts.first.nil? && "basic" == scheme
165
+ !parts.first.nil? && 'basic' == scheme
177
166
  end
178
167
 
179
168
  # return an array of the two credentials [username,password]
180
169
  # @return [Array] the couple [username,password]
181
170
  def credentials
182
- @credentials ||= params.unpack("m*").first.split(/:/, 2)
171
+ @credentials ||= params.unpack1('m*').split(':', 2)
183
172
  end
184
173
 
185
174
  # read accessor on the first credentials, username
@@ -193,9 +182,7 @@ module Rack
193
182
  def password
194
183
  credentials.last
195
184
  end
196
-
197
185
  end
198
-
199
186
  end
200
187
  end
201
188
  end
@@ -1,32 +1,32 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'rack/auth/ldap/version'
4
4
 
5
-
6
5
  Gem::Specification.new do |s|
7
- s.name = "rack-auth-ldap"
8
- s.summary = %Q{Rack middleware providing LDAP authentication}
9
- s.email = "romain@ultragreen.net"
10
- s.homepage = "http://www.github.com/lecid/rack-auth-ldap"
11
- s.authors = ["Romain GEORGES"]
6
+ s.name = 'rack-auth-ldap'
7
+ s.summary = %(Rack middleware providing LDAP authentication)
8
+ s.email = 'romain@ultragreen.net'
9
+ s.homepage = 'http://www.github.com/lecid/rack-auth-ldap'
10
+ s.authors = ['Romain GEORGES']
12
11
  s.version = Rack::Auth::LDAP_VERSION
13
12
 
14
-
15
- s.description = %q{rack-auth-ldap : provide LDAP authentication for Rack middelware}
16
- s.add_development_dependency 'rspec', '~> 3.9.0'
17
- s.add_development_dependency 'yard', '~> 0.9.24'
18
- s.add_development_dependency 'rdoc', '~> 6.2.1'
19
- s.add_development_dependency 'roodi', '~> 5.0.0'
13
+ s.description = 'rack-auth-ldap : provide LDAP authentication for Rack middelware'
14
+ s.add_development_dependency 'bundle-audit', '~> 0.1.0'
20
15
  s.add_development_dependency 'code_statistics', '~> 0.2.13'
21
- s.add_development_dependency 'yard-rspec', '~> 0.1'
22
16
  s.add_development_dependency 'ladle', '~> 1.0.1'
23
17
  s.add_development_dependency 'rake', '~> 13.0.1'
18
+ s.add_development_dependency 'rspec', '~> 3.12.0'
19
+ s.add_development_dependency 'rubocop', '~> 1.54'
20
+ s.add_development_dependency 'version', '~> 1.1'
21
+ s.add_development_dependency 'yard', '~> 0.9.24'
22
+ s.add_development_dependency 'yard-rspec', '~> 0.1'
24
23
 
24
+ s.add_development_dependency 'cyclonedx-ruby', '~> 1.1'
25
+ s.add_development_dependency 'debride', '~> 1.12'
25
26
 
26
-
27
-
28
- s.add_dependency 'net-ldap', '~> 0.16.2'
29
- s.add_dependency 'rack', '~> 2.2.2'
30
- s.license = "BSD-2-Clause"
27
+ s.add_dependency 'net-ldap', '~> 0.18'
28
+ s.add_dependency 'rack', '~> 3.0'
29
+ s.license = 'BSD-2-Clause'
31
30
  s.files = `git ls-files`.split($/)
31
+ s.metadata['rubygems_mfa_required'] = 'true'
32
32
  end
@@ -1,24 +1,21 @@
1
- # coding: utf-8
2
1
  require 'ladle'
3
2
  require 'rack/auth/ldap'
4
3
  require 'rack/lint'
5
4
  require 'rack/mock'
6
5
 
7
6
  describe Rack::Auth::Ldap do
7
+ before :all do
8
+ @ldap_server = Ladle::Server.new({
9
+ quiet: true, port: 3897,
10
+ ldif: './spec/config/users.ldif',
11
+ domain: 'dc=test',
12
+ tmpdir: '/tmp'
13
+ }).start
14
+ end
8
15
 
9
- before :all do
10
- @ldap_server = Ladle::Server.new({
11
- :quiet => true, :port => 3897,
12
- :ldif => "./spec/config/users.ldif",
13
- :domain => "dc=test",
14
- :tmpdir => '/tmp'
15
- }).start
16
- end
17
-
18
- after :all do
19
- @ldap_server.stop if @ldap_server
20
- end
21
-
16
+ after :all do
17
+ @ldap_server.stop if @ldap_server
18
+ end
22
19
 
23
20
  def realm
24
21
  'test'
@@ -26,12 +23,12 @@ describe Rack::Auth::Ldap do
26
23
 
27
24
  def unprotected_app
28
25
  Rack::Lint.new lambda { |env|
29
- [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ]
26
+ [200, { 'content-type' => 'text/plain' }, ["Hi #{env['REMOTE_USER']}"]]
30
27
  }
31
28
  end
32
29
 
33
30
  def protected_app
34
- app = Rack::Auth::Ldap.new(unprotected_app,{:file => "./spec/config/ldap.yml"})
31
+ app = Rack::Auth::Ldap.new(unprotected_app, { file: './spec/config/ldap.yml' })
35
32
  app.realm = realm
36
33
  app
37
34
  end
@@ -41,7 +38,7 @@ describe Rack::Auth::Ldap do
41
38
  end
42
39
 
43
40
  def request_with_basic_auth(username, password, &block)
44
- request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
41
+ request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack('m*'), &block
45
42
  end
46
43
 
47
44
  def request(headers = {})
@@ -52,18 +49,18 @@ describe Rack::Auth::Ldap do
52
49
  expect(response.client_error?).to be true
53
50
  expect(response.status).to eq 401
54
51
  expect(response).to include 'WWW-Authenticate'
55
- expect(response.headers['WWW-Authenticate']).to match /Basic realm="#{Regexp.escape(realm)}"/
52
+ expect(response.headers['WWW-Authenticate']).to match(/Basic realm="#{Regexp.escape(realm)}"/)
56
53
  expect(response.body).to be_empty
57
54
  end
58
55
 
59
56
  it 'should render ldap.yaml with erb and use env vars' do
60
- allow(ENV).to receive(:[]).with('RACK_ENV')
61
- allow(ENV).to receive(:[]).with('HOSTNAME').and_return('localhost.local')
62
- allow(ENV).to receive(:[]).with('PORT').and_return('9090')
57
+ allow(ENV).to receive(:[]).with('RACK_ENV')
58
+ allow(ENV).to receive(:[]).with('HOSTNAME').and_return('localhost.local')
59
+ allow(ENV).to receive(:[]).with('PORT').and_return('9090')
63
60
 
64
- app = Rack::Auth::Ldap.new(unprotected_app,{:file => './spec/config/ldap.yml'})
65
- expect(app.config.hostname).to eq('localhost.local')
66
- expect(app.config.port).to eq(9090)
61
+ app = Rack::Auth::Ldap.new(unprotected_app, { file: './spec/config/ldap.yml' })
62
+ expect(app.config.hostname).to eq('localhost.local')
63
+ expect(app.config.port).to eq(9090)
67
64
  end
68
65
 
69
66
  it 'should challenge correctly when no credentials are specified' do
metadata CHANGED
@@ -1,85 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-auth-ldap
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: bundle-audit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.9.0
19
+ version: 0.1.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.9.0
26
+ version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: yard
28
+ name: code_statistics
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.24
33
+ version: 0.2.13
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.24
40
+ version: 0.2.13
41
41
  - !ruby/object:Gem::Dependency
42
- name: rdoc
42
+ name: ladle
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 6.2.1
47
+ version: 1.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 6.2.1
54
+ version: 1.0.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: roodi
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 5.0.0
61
+ version: 13.0.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 5.0.0
68
+ version: 13.0.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: code_statistics
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.13
75
+ version: 3.12.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.13
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.54'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.54'
97
+ - !ruby/object:Gem::Dependency
98
+ name: version
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.24
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.24
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: yard-rspec
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -95,72 +137,76 @@ dependencies:
95
137
  - !ruby/object:Gem::Version
96
138
  version: '0.1'
97
139
  - !ruby/object:Gem::Dependency
98
- name: ladle
140
+ name: cyclonedx-ruby
99
141
  requirement: !ruby/object:Gem::Requirement
100
142
  requirements:
101
143
  - - "~>"
102
144
  - !ruby/object:Gem::Version
103
- version: 1.0.1
145
+ version: '1.1'
104
146
  type: :development
105
147
  prerelease: false
106
148
  version_requirements: !ruby/object:Gem::Requirement
107
149
  requirements:
108
150
  - - "~>"
109
151
  - !ruby/object:Gem::Version
110
- version: 1.0.1
152
+ version: '1.1'
111
153
  - !ruby/object:Gem::Dependency
112
- name: rake
154
+ name: debride
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
157
  - - "~>"
116
158
  - !ruby/object:Gem::Version
117
- version: 13.0.1
159
+ version: '1.12'
118
160
  type: :development
119
161
  prerelease: false
120
162
  version_requirements: !ruby/object:Gem::Requirement
121
163
  requirements:
122
164
  - - "~>"
123
165
  - !ruby/object:Gem::Version
124
- version: 13.0.1
166
+ version: '1.12'
125
167
  - !ruby/object:Gem::Dependency
126
168
  name: net-ldap
127
169
  requirement: !ruby/object:Gem::Requirement
128
170
  requirements:
129
171
  - - "~>"
130
172
  - !ruby/object:Gem::Version
131
- version: 0.16.2
173
+ version: '0.18'
132
174
  type: :runtime
133
175
  prerelease: false
134
176
  version_requirements: !ruby/object:Gem::Requirement
135
177
  requirements:
136
178
  - - "~>"
137
179
  - !ruby/object:Gem::Version
138
- version: 0.16.2
180
+ version: '0.18'
139
181
  - !ruby/object:Gem::Dependency
140
182
  name: rack
141
183
  requirement: !ruby/object:Gem::Requirement
142
184
  requirements:
143
185
  - - "~>"
144
186
  - !ruby/object:Gem::Version
145
- version: 2.2.2
187
+ version: '3.0'
146
188
  type: :runtime
147
189
  prerelease: false
148
190
  version_requirements: !ruby/object:Gem::Requirement
149
191
  requirements:
150
192
  - - "~>"
151
193
  - !ruby/object:Gem::Version
152
- version: 2.2.2
194
+ version: '3.0'
153
195
  description: 'rack-auth-ldap : provide LDAP authentication for Rack middelware'
154
196
  email: romain@ultragreen.net
155
197
  executables: []
156
198
  extensions: []
157
199
  extra_rdoc_files: []
158
200
  files:
201
+ - ".debride-whitelist"
159
202
  - ".gitignore"
160
- - COPYRIGHT
203
+ - ".rubocop.yml"
161
204
  - Gemfile
205
+ - LICENSE.txt
162
206
  - README.rdoc
163
207
  - Rakefile
208
+ - VERSION
209
+ - bom.xml
164
210
  - examples/Gemfile
165
211
  - examples/config.ru
166
212
  - examples/ldap.yml
@@ -174,7 +220,8 @@ files:
174
220
  homepage: http://www.github.com/lecid/rack-auth-ldap
175
221
  licenses:
176
222
  - BSD-2-Clause
177
- metadata: {}
223
+ metadata:
224
+ rubygems_mfa_required: 'true'
178
225
  post_install_message:
179
226
  rdoc_options: []
180
227
  require_paths:
@@ -190,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
237
  - !ruby/object:Gem::Version
191
238
  version: '0'
192
239
  requirements: []
193
- rubygems_version: 3.1.2
240
+ rubygems_version: 3.3.5
194
241
  signing_key:
195
242
  specification_version: 4
196
243
  summary: Rack middleware providing LDAP authentication
File without changes