Merge remote-tracking branch 'larstobi/master'

This commit is contained in:
Rory O'Connell 2011-03-16 15:15:43 -05:00
commit af6c595793
2 changed files with 39 additions and 8 deletions

View file

@ -1456,6 +1456,20 @@ class Net::LDAP::Connection #:nodoc:
result_code result_code
end 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_ops
end
#-- #--
# TODO: need to support a time limit, in case the server fails to respond. # TODO: need to support a time limit, in case the server fails to respond.
# TODO: We're throwing an exception here on empty DN. Should return a # TODO: We're throwing an exception here on empty DN. Should return a
@ -1465,14 +1479,7 @@ 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 = modify_ops args[:operations]
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
modify_ops << [op_1, [attr.to_s.to_ber, Array(values).map { |v| v.to_ber}.to_ber_set].to_ber_sequence].to_ber_sequence
}
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

View file

@ -0,0 +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_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_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
end