Skip to content

Commit 6011737

Browse files
author
Austin Ziegler
committed
Bugfix requiring a 0.2.1 release.
Modify operations were broken, but now aren't. This version fixes the changes cleanly.
1 parent 8b46fdf commit 6011737

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

History.rdoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
=== Net::LDAP 0.2.1 / 2011-03-23
2+
* Bug Fixes:
3+
* Net::LDAP.modify_ops was broken and is now fixed.
4+
15
=== Net::LDAP 0.2 / 2011-03-22
26
* Major Enhancements:
37
* Net::LDAP::Filter changes:

lib/net/ldap.rb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class LDAP
241241
# and then keeps it open while it executes a user-supplied block.
242242
# Net::LDAP#open closes the connection on completion of the block.
243243
class Net::LDAP
244-
VERSION = "0.2"
244+
VERSION = "0.2.1"
245245

246246
class LdapError < StandardError; end
247247

@@ -1452,18 +1452,25 @@ def search(args = {})
14521452
result_code
14531453
end
14541454

1455-
def self.modify_ops args
1456-
modify_ops = []
1457-
a = args[:operations] and a.each {|op, attr, values|
1458-
# TODO, fix the following line, which gives a bogus error
1459-
# if the opcode is invalid.
1460-
op_1 = {:add => 0, :delete => 1, :replace => 2} [op.to_sym].to_ber_enumerated
1461-
values = [values].flatten.map { |v|
1462-
v.to_ber unless v.nil?
1463-
}.to_ber_set
1464-
modify_ops << [op_1,[attr.to_s.to_ber,values].to_ber_sequence].to_ber
1455+
MODIFY_OPERATIONS = { #:nodoc:
1456+
:add => 0,
1457+
:delete => 1,
1458+
:replace => 2
1459+
}
1460+
1461+
def self.modify_ops(operations)
1462+
modify_ops = []
1463+
if operations
1464+
operations.each { |op, attrib, values|
1465+
# TODO, fix the following line, which gives a bogus error if the
1466+
# opcode is invalid.
1467+
op_ber = MODIFY_OPERATIONS[op.to_sym].to_ber_enumerated
1468+
values = [ values ].flatten.map { |v| v.to_ber if v }.to_ber_set
1469+
values = [ attrib.to_s.to_ber, values ].to_ber_sequence
1470+
modify_ops << [ op_ber, values ].to_ber
14651471
}
1466-
modify_ops
1472+
end
1473+
modify_ops
14671474
end
14681475

14691476
#--
@@ -1476,9 +1483,9 @@ def self.modify_ops args
14761483
def modify(args)
14771484
modify_dn = args[:dn] or raise "Unable to modify empty DN"
14781485
modify_ops = modify_ops args[:operations]
1479-
request = [modify_dn.to_ber,
1480-
modify_ops.to_ber_sequence].to_ber_appsequence(6)
1481-
pkt = [next_msgid.to_ber, request].to_ber_sequence
1486+
request = [ modify_dn.to_ber,
1487+
modify_ops.to_ber_sequence ].to_ber_appsequence(6)
1488+
pkt = [ next_msgid.to_ber, request ].to_ber_sequence
14821489
@conn.write pkt
14831490

14841491
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 7) or raise Net::LDAP::LdapError, "response missing or invalid"

test/test_ldap_connection.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
require 'common'
22

33
class TestLDAP < Test::Unit::TestCase
4-
def test_modify_ops_delete
5-
args = {:operations=>[[:delete, "mail"]]}
6-
result = Net::LDAP::Connection.modify_ops(args)
7-
expected = ["0\r\n\x01\x010\b\x04\x04mail1\x00"]
8-
assert_equal(expected, result)
9-
end
4+
def test_modify_ops_delete
5+
args = { :operations => [ [ :delete, "mail" ] ] }
6+
result = Net::LDAP::Connection.modify_ops(args[:operations])
7+
expected = [ "0\r\n\x01\x010\b\x04\x04mail1\x00" ]
8+
assert_equal(expected, result)
9+
end
1010

11-
def test_modify_ops_add
12-
args = {:operations=>[[:add, "mail", "[email protected]"]]}
13-
result = Net::LDAP::Connection.modify_ops(args)
14-
expected = ["0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14[email protected]"]
15-
assert_equal(expected, result)
16-
end
11+
def test_modify_ops_add
12+
args = { :operations => [ [ :add, "mail", "[email protected]" ] ] }
13+
result = Net::LDAP::Connection.modify_ops(args[:operations])
14+
expected = [ "0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14[email protected]" ]
15+
assert_equal(expected, result)
16+
end
1717

18-
def test_modify_ops_replace
19-
args = {:operations=>[[:replace, "mail", "[email protected]"]]}
20-
result = Net::LDAP::Connection.modify_ops(args)
21-
expected = ["0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14[email protected]"]
22-
assert_equal(expected, result)
23-
end
18+
def test_modify_ops_replace
19+
args = { :operations =>[ [ :replace, "mail", "[email protected]" ] ] }
20+
result = Net::LDAP::Connection.modify_ops(args[:operations])
21+
expected = [ "0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14[email protected]" ]
22+
assert_equal(expected, result)
23+
end
2424
end

0 commit comments

Comments
 (0)