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,17 +1452,24 @@ 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|
v.to_ber unless v.nil?
}.to_ber_set
modify_ops << [op_1,[attr.to_s.to_ber,values].to_ber_sequence].to_ber
} }
def self.modify_ops(operations)
modify_ops = []
if operations
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
}
end
modify_ops modify_ops
end end

View file

@ -3,21 +3,21 @@ 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