Skip to content

Commit 55f550f

Browse files
committed
Fix processing password modify responses
Per RFC4511 section 4.12, the responseValue field of an ExtendedResponse object is an optional string. Per RFC3062 section 2, the response to a passsword modify request is a sequence. This means the extended response must be parsed.
1 parent c3320a0 commit 55f550f

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Diff for: lib/net/ldap.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class Net::LDAP
311311
0 => :array, # RFC-2251 Control and Filter-AND
312312
1 => :array, # SearchFilter-OR
313313
2 => :array, # SearchFilter-NOT
314-
3 => :array, # Seach referral
314+
3 => :array, # Search referral
315315
4 => :array, # unknown use in Microsoft Outlook
316316
5 => :array, # SearchFilter-GE
317317
6 => :array, # SearchFilter-LE

Diff for: lib/net/ldap/pdu.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def parse_extended_response(sequence)
200200
:matchedDN => sequence[1],
201201
:errorMessage => sequence[2],
202202
}
203-
@extended_response = sequence.last
203+
@extended_response = sequence.length == 3 ? nil : sequence.last
204204
end
205205
private :parse_extended_response
206206

Diff for: test/integration/test_password_modify.rb

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require_relative '../test_helper'
22

33
class TestPasswordModifyIntegration < LDAPIntegrationTestCase
4+
# see: https://www.rfc-editor.org/rfc/rfc3062#section-2
5+
PASSWORD_MODIFY_SYNTAX = Net::BER.compile_syntax(
6+
application: {},
7+
universal: {},
8+
context_specific: { primitive: { 0 => :string } },
9+
)
10+
411
def setup
512
super
613
@admin_account = { dn: 'cn=admin,dc=example,dc=org', password: 'admin', method: :simple }
@@ -49,7 +56,14 @@ def test_password_modify_generate
4956
auth: @auth,
5057
old_password: 'admin')
5158

52-
generated_password = @ldap.get_operation_result.extended_response[0][0]
59+
passwd_modify_response_value = @ldap.get_operation_result.extended_response
60+
Net::BER.compile_syntax(application: {}, universal: {}, context_specific: { primitive: { 0 => :string } })
61+
seq = Net::BER::BerIdentifiedArray.new
62+
sio = StringIO.new(passwd_modify_response_value)
63+
while (e = sio.read_ber(PASSWORD_MODIFY_SYNTAX)) != nil
64+
seq << e
65+
end
66+
generated_password = seq[0][0]
5367

5468
assert generated_password, 'Should have generated a password'
5569

@@ -64,8 +78,13 @@ def test_password_modify_generate_no_old_password
6478
assert @ldap.password_modify(dn: @dn,
6579
auth: @auth)
6680

67-
generated_password = @ldap.get_operation_result.extended_response[0][0]
68-
81+
passwd_modify_response_value = @ldap.get_operation_result.extended_response
82+
seq = Net::BER::BerIdentifiedArray.new
83+
sio = StringIO.new(passwd_modify_response_value)
84+
while (e = sio.read_ber(PASSWORD_MODIFY_SYNTAX)) != nil
85+
seq << e
86+
end
87+
generated_password = seq[0][0]
6988
assert generated_password, 'Should have generated a password'
7089

7190
refute @ldap.bind(username: @dn, password: 'admin', method: :simple),

0 commit comments

Comments
 (0)