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:
parent
8b46fdf349
commit
57a356d556
|
@ -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
|
||||
* Major Enhancements:
|
||||
* Net::LDAP::Filter changes:
|
||||
|
|
|
@ -241,7 +241,7 @@ require 'net/ldap/entry'
|
|||
# and then keeps it open while it executes a user-supplied block.
|
||||
# Net::LDAP#open closes the connection on completion of the block.
|
||||
class Net::LDAP
|
||||
VERSION = "0.2"
|
||||
VERSION = "0.2.1"
|
||||
|
||||
class LdapError < StandardError; end
|
||||
|
||||
|
@ -1452,18 +1452,25 @@ class Net::LDAP::Connection #:nodoc:
|
|||
result_code
|
||||
end
|
||||
|
||||
def self.modify_ops args
|
||||
modify_ops = []
|
||||
a = args[:operations] and a.each {|op, attr, values|
|
||||
# TODO, fix the following line, which gives a bogus error
|
||||
# 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
|
||||
MODIFY_OPERATIONS = { #:nodoc:
|
||||
:add => 0,
|
||||
:delete => 1,
|
||||
:replace => 2
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
modify_ops
|
||||
end
|
||||
modify_ops
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -1476,9 +1483,9 @@ class Net::LDAP::Connection #:nodoc:
|
|||
def modify(args)
|
||||
modify_dn = args[:dn] or raise "Unable to modify empty DN"
|
||||
modify_ops = modify_ops args[:operations]
|
||||
request = [modify_dn.to_ber,
|
||||
modify_ops.to_ber_sequence].to_ber_appsequence(6)
|
||||
pkt = [next_msgid.to_ber, request].to_ber_sequence
|
||||
request = [ modify_dn.to_ber,
|
||||
modify_ops.to_ber_sequence ].to_ber_appsequence(6)
|
||||
pkt = [ next_msgid.to_ber, request ].to_ber_sequence
|
||||
@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"
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
require 'common'
|
||||
|
||||
class TestLDAP < Test::Unit::TestCase
|
||||
def test_modify_ops_delete
|
||||
args = {:operations=>[[:delete, "mail"]]}
|
||||
result = Net::LDAP::Connection.modify_ops(args)
|
||||
expected = ["0\r\n\x01\x010\b\x04\x04mail1\x00"]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
def test_modify_ops_delete
|
||||
args = { :operations => [ [ :delete, "mail" ] ] }
|
||||
result = Net::LDAP::Connection.modify_ops(args[:operations])
|
||||
expected = [ "0\r\n\x01\x010\b\x04\x04mail1\x00" ]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
|
||||
def test_modify_ops_add
|
||||
args = {:operations=>[[:add, "mail", "testuser@example.com"]]}
|
||||
result = Net::LDAP::Connection.modify_ops(args)
|
||||
expected = ["0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14testuser@example.com"]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
def test_modify_ops_add
|
||||
args = { :operations => [ [ :add, "mail", "testuser@example.com" ] ] }
|
||||
result = Net::LDAP::Connection.modify_ops(args[:operations])
|
||||
expected = [ "0#\n\x01\x000\x1E\x04\x04mail1\x16\x04\x14testuser@example.com" ]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
|
||||
def test_modify_ops_replace
|
||||
args = {:operations=>[[:replace, "mail", "testuser@example.com"]]}
|
||||
result = Net::LDAP::Connection.modify_ops(args)
|
||||
expected = ["0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14testuser@example.com"]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
def test_modify_ops_replace
|
||||
args = { :operations =>[ [ :replace, "mail", "testuser@example.com" ] ] }
|
||||
result = Net::LDAP::Connection.modify_ops(args[:operations])
|
||||
expected = [ "0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14testuser@example.com" ]
|
||||
assert_equal(expected, result)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue