Skip to content

Commit 7a605f5

Browse files
thriqonJonas Weber
authored and
Jonas Weber
committed
Send DN and newPassword with password_modify request
1 parent e4c46a2 commit 7a605f5

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/net/ldap/connection.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ def password_modify(args)
593593

594594
ext_seq = [Net::LDAP::PasswdModifyOid.to_ber_contextspecific(0)]
595595

596-
unless args[:old_password].nil?
597-
pwd_seq = [args[:old_password].to_ber(0x81)]
598-
pwd_seq << args[:new_password].to_ber(0x82) unless args[:new_password].nil?
599-
ext_seq << pwd_seq.to_ber_sequence.to_ber(0x81)
600-
end
596+
pwd_seq = []
597+
pwd_seq << dn.to_ber(0x80)
598+
pwd_seq << args[:old_password].to_ber(0x81) unless args[:old_password].nil?
599+
pwd_seq << args[:new_password].to_ber(0x82) unless args[:new_password].nil?
600+
ext_seq << pwd_seq.to_ber_sequence.to_ber(0x81)
601601

602602
request = ext_seq.to_ber_appsequence(Net::LDAP::PDU::ExtendedRequest)
603603

test/integration/test_password_modify.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
class TestPasswordModifyIntegration < LDAPIntegrationTestCase
44
def setup
55
super
6-
@ldap.authenticate 'cn=admin,dc=rubyldap,dc=com', 'passworD1'
6+
@admin_account = {dn: 'cn=admin,dc=rubyldap,dc=com', password: 'passworD1', method: :simple}
7+
@ldap.authenticate @admin_account[:dn], @admin_account[:password]
78

89
@dn = 'uid=modify-password-user1,ou=People,dc=rubyldap,dc=com'
910

@@ -74,6 +75,18 @@ def test_password_modify_generate_no_old_password
7475
'New password should be valid'
7576
end
7677

78+
def test_password_modify_overwrite_old_password
79+
assert @ldap.password_modify(dn: @dn,
80+
auth: @admin_account,
81+
new_password: 'passworD3')
82+
83+
refute @ldap.bind(username: @dn, password: 'passworD1', method: :simple),
84+
'Old password should no longer be valid'
85+
86+
assert @ldap.bind(username: @dn, password: 'passworD3', method: :simple),
87+
'New password should be valid'
88+
end
89+
7790
def teardown
7891
@ldap.delete dn: @dn
7992
end

0 commit comments

Comments
 (0)