Skip to content

Commit 37ae001

Browse files
committed
➖ nkf not needed
1 parent c722c80 commit 37ae001

File tree

10 files changed

+182
-197
lines changed

10 files changed

+182
-197
lines changed

.rubocop_gradual.lock

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"lib/omniauth-ldap/adaptor.rb:2352927785": [
3-
[36, 7, 413, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 105664470],
4-
[86, 17, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806],
5-
[86, 30, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806],
6-
[86, 37, 1, "Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional", 177560]
2+
"lib/omniauth-ldap/adaptor.rb:3906050285": [
3+
[64, 7, 413, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 105664470],
4+
[114, 17, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806],
5+
[114, 30, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806],
6+
[114, 37, 1, "Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional", 177560]
77
],
88
"spec/integration/middleware_spec.rb:4062046892": [
99
[3, 16, 39, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 638096201],
@@ -15,29 +15,30 @@
1515
[4, 3, 12, "RSpec/BeforeAfterAll: Beware of using `before(:all)` as it may cause state to leak between tests. If you are using `rspec-rails`, and `use_transactional_fixtures` is enabled, then records created in `before(:all)` are not automatically rolled back.", 86334566],
1616
[70, 16, 5, "RSpec/ExpectActual: Provide the actual value you are testing to `expect(...)`.", 237881235]
1717
],
18-
"spec/omniauth-ldap/adaptor_spec.rb:3624298807": [
19-
[72, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
20-
[73, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
21-
[74, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
22-
[80, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
23-
[81, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
24-
[82, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310]
18+
"spec/omniauth-ldap/adaptor_spec.rb:2715031579": [
19+
[3, 1, 38, "RSpec/SpecFilePathFormat: Spec path should end with `omni_auth/ldap/adaptor*_spec.rb`.", 1973618936],
20+
[206, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
21+
[207, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
22+
[208, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
23+
[214, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
24+
[215, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
25+
[216, 7, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310]
2526
],
26-
"spec/omniauth/adaptor_spec.rb:3492754784": [
27+
"spec/omniauth/adaptor_spec.rb:1168013709": [
2728
[3, 1, 38, "RSpec/SpecFilePathFormat: Spec path should end with `omni_auth/ldap/adaptor*_spec.rb`.", 1973618936],
28-
[42, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
29-
[43, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
30-
[80, 7, 48, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 2759780562]
29+
[46, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
30+
[47, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
31+
[84, 7, 48, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 2759780562]
3132
],
32-
"spec/omniauth/strategies/ldap_spec.rb:3760791626": [
33-
[13, 3, 54, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 2419068710],
34-
[76, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
35-
[101, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
36-
[110, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
37-
[121, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
38-
[129, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
39-
[141, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
40-
[156, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
41-
[189, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
33+
"spec/omniauth/strategies/ldap_spec.rb:86189447": [
34+
[14, 3, 54, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 2419068710],
35+
[90, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
36+
[145, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
37+
[154, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
38+
[165, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
39+
[174, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
40+
[187, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
41+
[202, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
42+
[235, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
4243
]
4344
}

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ GEM
157157
net-ldap (0.20.0)
158158
base64
159159
ostruct
160-
nkf (0.2.0)
161160
nokogiri (1.18.10-x86_64-linux-gnu)
162161
racc (~> 1.4)
163162
notiffany (0.1.3)
@@ -393,7 +392,6 @@ DEPENDENCIES
393392
kramdown-parser-gfm (~> 1.1)
394393
logger (~> 1.7)
395394
mutex_m (~> 0.2)
396-
nkf
397395
omniauth-ldap!
398396
rack-test (~> 2.2)
399397
rake (~> 13.0)

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ use OmniAuth::Strategies::LDAP,
6464
bind_dn: "default_bind_dn",
6565
password: "password",
6666
tls_options: {
67-
ssl_version: 'TLSv1_2',
68-
ciphers: ["AES-128-CBC", "AES-128-CBC-HMAC-SHA1", "AES-128-CBC-HMAC-SHA256"]
67+
ssl_version: "TLSv1_2",
68+
ciphers: ["AES-128-CBC", "AES-128-CBC-HMAC-SHA1", "AES-128-CBC-HMAC-SHA256"],
6969
}
7070
# Or, alternatively:
7171
# use OmniAuth::Strategies::LDAP, filter: '(&(uid=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))'
@@ -97,20 +97,6 @@ Compatible with MRI Ruby 2.0+, and concordant releases of JRuby, and TruffleRuby
9797
|------------------------------------------------|--------------------------------------------------------|
9898
| 👟 Check it out! |[github.com/appraisal-rb/appraisal2][💎appraisal2]|
9999

100-
#### Ruby 3.4
101-
102-
nkf/kconv has been part of Ruby since long ago.
103-
Eventually it became a standard gem, but was changed to a bundled gem in Ruby 3.4.
104-
In general, kconv and iconv have been superseded since Ruby 1.9 by the built-in
105-
encoding support provided by String#encode, String#force_encoding, and similar methods.
106-
But this gem has not yet been updated to remove its dependency on nkf/kconv.
107-
108-
As a result of all this you should add `nkf` to your Gemfile if you are using Ruby 3.4 or later.
109-
110-
```ruby
111-
gem "nkf", "~> 0.1"
112-
```
113-
114100
### Enterprise Support [![Tidelift](https://tidelift.com/badges/package/rubygems/omniauth-ldap)](https://tidelift.com/subscription/pkg/rubygems-omniauth-ldap?utm_source=rubygems-omniauth-ldap&utm_medium=referral&utm_campaign=readme)
115101

116102
Available as part of the Tidelift Subscription.

gemfiles/modular/optional.gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@
33
# Required for kettle-pre-release
44
# URL parsing with Unicode support (falls back to URI if not available)
55
gem "addressable", ">= 2.8", "< 3" # ruby >= 2.2
6-
7-
# nkf/kconv has been part of Ruby since long ago.
8-
# Eventually it became a standard gem, but was changed to a bundled gem in Ruby 3.4.
9-
# In general, kconv and iconv have been superseded since Ruby 1.9 by the built-in
10-
# encoding support provided by String#encode, String#force_encoding, and similar methods.
11-
gem "nkf" # ruby >= 2.3

gitlab_omniauth-ldap.gemspec

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ Gem::Specification.new do |spec|
9898
spec.executables = []
9999

100100
spec.add_dependency("net-ldap", "~> 0.16", "< 1") # ruby >= 2.0
101-
# nkf/kconv has been part of Ruby since long ago.
102-
# Eventually it became a standard gem, but was changed to a bundled gem in Ruby 3.4.
103-
# In general, kconv and iconv have been superseded since Ruby 1.9 by the built-in
104-
# encoding support provided by String#encode, String#force_encoding, and similar methods.
105-
# spec.add_dependency("nkf") # ruby >= 2.3
106101
spec.add_dependency("omniauth", ">= 1", "< 3") # ruby >= 0.0
107102
spec.add_dependency("pyu-ruby-sasl", ">= 0.0.3.3", "< 0.1") # ruby >= 0.0
108103
spec.add_dependency("rack", ">= 1", "< 4") # ruby >= 0.0

lib/omniauth-ldap/adaptor.rb

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
# this code borrowed pieces from activeldap and net-ldap
1+
# frozen_string_literal: true
22

3-
# nkf/kconv has been part of Ruby since long ago.
4-
# Eventually it became a standard gem, but was changed to a bundled gem in Ruby 3.4.
5-
# In general, kconv and iconv have been superseded since Ruby 1.9 by the built-in
6-
# encoding support provided by String#encode, String#force_encoding, and similar methods.
7-
require "nkf"
3+
# this code borrowed pieces from activeldap and net-ldap
84

95
# External Gems
106
require "net/ldap"
@@ -21,8 +17,20 @@ class AuthenticationError < StandardError; end
2117
class ConnectionError < StandardError; end
2218

2319
VALID_ADAPTER_CONFIGURATION_KEYS = [
24-
:hosts, :host, :port, :encryption, :disable_verify_certificates, :bind_dn, :password, :try_sasl,
25-
:sasl_mechanisms, :uid, :base, :allow_anonymous, :filter, :tls_options,
20+
:hosts,
21+
:host,
22+
:port,
23+
:encryption,
24+
:disable_verify_certificates,
25+
:bind_dn,
26+
:password,
27+
:try_sasl,
28+
:sasl_mechanisms,
29+
:uid,
30+
:base,
31+
:allow_anonymous,
32+
:filter,
33+
:tls_options,
2634

2735
# Deprecated
2836
:method,
@@ -78,9 +86,13 @@ def initialize(configuration = {})
7886
hosts: @hosts,
7987
host: @host,
8088
port: @port,
81-
encryption: encryption_options
89+
encryption: encryption_options,
8290
}
83-
@bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple)
91+
@bind_method = if @try_sasl
92+
:sasl
93+
else
94+
((@allow_anonymous || !@bind_dn || !@password) ? :anonymous : :simple)
95+
end
8496

8597
@auth = sasl_auths({username: @bind_dn, password: @password}).first if @bind_method == :sasl
8698
@auth ||= {
@@ -121,11 +133,11 @@ def bind_as(args = {})
121133

122134
def encryption_options
123135
translated_method = translate_method
124-
return nil unless translated_method
136+
return unless translated_method
125137

126138
{
127139
method: translated_method,
128-
tls_options: tls_options(translated_method)
140+
tls_options: tls_options(translated_method),
129141
}
130142
end
131143

@@ -135,17 +147,16 @@ def translate_method
135147
normalized_method = method.to_s.downcase.to_sym
136148

137149
unless ENCRYPTION_METHOD.has_key?(normalized_method)
138-
available_methods = ENCRYPTION_METHOD.keys.collect {|m| m.inspect}.join(", ")
150+
available_methods = ENCRYPTION_METHOD.keys.collect { |m| m.inspect }.join(", ")
139151
format = "%s is not one of the available connect methods: %s"
140152
raise ConfigurationError, format % [method.inspect, available_methods]
141153
end
142154

143155
ENCRYPTION_METHOD[normalized_method]
144156
end
145157

146-
147158
def tls_options(translated_method)
148-
return {} if translated_method == nil # (plain)
159+
return {} if translated_method.nil? # (plain)
149160

150161
options = default_options
151162

@@ -217,7 +228,7 @@ def default_options
217228
# 1. The behavior of OpenSSL is undefined when verify_mode is not set.
218229
# 2. The net-ldap gem implementation verifies the certificate hostname
219230
# unless verify_mode is set to VERIFY_NONE.
220-
{ verify_mode: OpenSSL::SSL::VERIFY_NONE }
231+
{verify_mode: OpenSSL::SSL::VERIFY_NONE}
221232
else
222233
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.dup
223234
end
@@ -230,7 +241,7 @@ def default_options
230241
def sanitize_hash_values(hash)
231242
hash.delete_if do |_, value|
232243
value.nil? ||
233-
(value.is_a?(String) && value !~ /\S/)
244+
(value.is_a?(String) && value !~ /\S/)
234245
end
235246
end
236247

lib/omniauth/strategies/ldap.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def callback_phase
7171
@ldap_user_info = @adaptor.bind_as(filter: filter(@adaptor), size: 1, password: request.params["password"])
7272

7373
unless @ldap_user_info
74-
return fail!(:invalid_credentials, InvalidCredentialsError.new("Invalid credentials for #{request.params['username']}"))
74+
return fail!(:invalid_credentials, InvalidCredentialsError.new("Invalid credentials for #{request.params["username"]}"))
7575
end
7676

7777
@user_info = self.class.map_user(CONFIG, @ldap_user_info)
@@ -83,8 +83,8 @@ def callback_phase
8383

8484
def filter(adaptor)
8585
if adaptor.filter && !adaptor.filter.empty?
86-
username = Net::LDAP::Filter.escape(@options[:name_proc].call(request.params['username']))
87-
Net::LDAP::Filter.construct(adaptor.filter % { username: username })
86+
username = Net::LDAP::Filter.escape(@options[:name_proc].call(request.params["username"]))
87+
Net::LDAP::Filter.construct(adaptor.filter % {username: username})
8888
else
8989
Net::LDAP::Filter.equals(adaptor.uid, @options[:name_proc].call(request.params["username"]))
9090
end
@@ -140,7 +140,7 @@ def map_user(mapper, object)
140140
protected
141141

142142
def valid_request_method?
143-
request.env['REQUEST_METHOD'] == 'POST'
143+
request.env["REQUEST_METHOD"] == "POST"
144144
end
145145

146146
def missing_credentials?

0 commit comments

Comments
 (0)