Skip to content

Commit 36815b5

Browse files
authored
Merge pull request #271 from thriqon/modify-password-without-old-password
Send DN and newPassword with password_modify request
2 parents 78e97ed + 7a605f5 commit 36815b5

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/net/ldap/connection.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,11 @@ def password_modify(args)
592592

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

595-
unless args[:old_password].nil?
596-
pwd_seq = [args[:old_password].to_ber(0x81)]
597-
pwd_seq << args[:new_password].to_ber(0x82) unless args[:new_password].nil?
598-
ext_seq << pwd_seq.to_ber_sequence.to_ber(0x81)
599-
end
595+
pwd_seq = []
596+
pwd_seq << dn.to_ber(0x80)
597+
pwd_seq << args[:old_password].to_ber(0x81) unless args[:old_password].nil?
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)
600600

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

test/integration/test_password_modify.rb

+14-1
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)