Bugfix requiring a 0.2.1 release.

Modify operations were broken, but now aren't. This version fixes the
changes cleanly.
This commit is contained in:
Austin Ziegler 2011-03-23 21:13:55 -04:00
parent 8b46fdf349
commit 57a356d556
3 changed files with 44 additions and 33 deletions

View file

@ -1,3 +1,7 @@
=== Net::LDAP 0.2.1 / 2011-03-23
* Bug Fixes:
* Net::LDAP.modify_ops was broken and is now fixed.
=== Net::LDAP 0.2 / 2011-03-22 === Net::LDAP 0.2 / 2011-03-22
* Major Enhancements: * Major Enhancements:
* Net::LDAP::Filter changes: * Net::LDAP::Filter changes:

View file

@ -241,7 +241,7 @@ require 'net/ldap/entry'
# and then keeps it open while it executes a user-supplied block. # and then keeps it open while it executes a user-supplied block.
# Net::LDAP#open closes the connection on completion of the block. # Net::LDAP#open closes the connection on completion of the block.
class Net::LDAP class Net::LDAP
VERSION = "0.2" VERSION = "0.2.1"
class LdapError < StandardError; end class LdapError < StandardError; end
@ -1452,18 +1452,25 @@ class Net::LDAP::Connection #:nodoc:
result_code result_code
end end
def self.modify_ops args MODIFY_OPERATIONS = { #:nodoc:
modify_ops = [] :add => 0,
a = args[:operations] and a.each {|op, attr, values| :delete => 1,
# TODO, fix the following line, which gives a bogus error :replace => 2
# if the opcode is invalid. }
op_1 = {:add => 0, :delete => 1, :replace => 2} [op.to_sym].to_ber_enumerated
values = [values].flatten.map { |v| def self.modify_ops(operations)
v.to_ber unless v.nil? modify_ops = []
}.to_ber_set if operations
modify_ops << [op_1,[attr.to_s.to_ber,values].to_ber_sequence].to_ber operations.each { |op, attrib, values|
# TODO, fix the following line, which gives a bogus error if the
# opcode is invalid.
op_ber = MODIFY_OPERATIONS[op.to_sym].to_ber_enumerated
values = [ values ].flatten.map { |v| v.to_ber if v }.to_ber_set
values = [ attrib.to_s.to_ber, values ].to_ber_sequence
modify_ops << [ op_ber, values ].to_ber
} }
modify_ops end
modify_ops
end end
#-- #--
@ -1476,9 +1483,9 @@ class Net::LDAP::Connection #:nodoc:
def modify(args) def modify(args)
modify_dn = args[:dn] or raise "Unable to modify empty DN" modify_dn = args[:dn] or raise "Unable to modify empty DN"
modify_ops = modify_ops args[:operations] modify_ops = modify_ops args[:operations]
request = [modify_dn.to_ber, request = [ modify_dn.to_ber,
modify_ops.to_ber_sequence].to_ber_appsequence(6) modify_ops.to_ber_sequence ].to_ber_appsequence(6)
pkt = [next_msgid.to_ber, request].to_ber_sequence pkt = [ next_msgid.to_ber, request ].to_ber_sequence
@conn.write pkt @conn.write pkt
(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" (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"

View file

@ -1,24 +1,24 @@
require 'common' require 'common'
class TestLDAP < Test::Unit::TestCase class TestLDAP < Test::Unit::TestCase
def test_modify_ops_delete def test_modify_ops_delete
args = {:operations=>[[:delete, "mail"]]} args = { :operations => [ [ :delete, "mail" ] ] }
result = Net::LDAP::Connection.modify_ops(args) result = Net::LDAP::Connection.modify_ops(args[:operations])
expected = ["0\r\n\x01\x010\b\x04\x04mail1\x00"] expected = [ "0\r\n\x01\x010\b\x04\x04mail1\x00" ]
assert_equal(expected, result) assert_equal(expected, result)
end end
def test_modify_ops_add def test_modify_ops_add
args = {:operations=>[[:add, "mail", "testuser@example.com"]]} args = { :operations => [ [ :add, "mail", "testuser@example.com" ] ] }
result = Net::LDAP::Connection.modify_ops(args) result = Net::LDAP::Connection.modify_ops(args[:operations])
expected = ["0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14testuser@example.com"] expected = [ "0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14testuser@example.com" ]
assert_equal(expected, result) assert_equal(expected, result)
end end
def test_modify_ops_replace def test_modify_ops_replace
args = {:operations=>[[:replace, "mail", "testuser@example.com"]]} args = { :operations =>[ [ :replace, "mail", "testuser@example.com" ] ] }
result = Net::LDAP::Connection.modify_ops(args) result = Net::LDAP::Connection.modify_ops(args[:operations])
expected = ["0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14testuser@example.com"] expected = [ "0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14testuser@example.com" ]
assert_equal(expected, result) assert_equal(expected, result)
end end
end end