Skip to content

Commit af6c595

Browse files
author
Rory O'Connell
committed
Merge remote-tracking branch 'larstobi/master'
2 parents a160b17 + 36b06f4 commit af6c595

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

lib/net/ldap.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,20 @@ def search(args = {})
14561456
result_code
14571457
end
14581458

1459+
def self.modify_ops args
1460+
modify_ops = []
1461+
a = args[:operations] and a.each {|op, attr, values|
1462+
# TODO, fix the following line, which gives a bogus error
1463+
# if the opcode is invalid.
1464+
op_1 = {:add => 0, :delete => 1, :replace => 2} [op.to_sym].to_ber_enumerated
1465+
values = [values].flatten.map { |v|
1466+
v.to_ber unless v.nil?
1467+
}.to_ber_set
1468+
modify_ops << [op_1,[attr.to_s.to_ber,values].to_ber_sequence].to_ber
1469+
}
1470+
modify_ops
1471+
end
1472+
14591473
#--
14601474
# TODO: need to support a time limit, in case the server fails to respond.
14611475
# TODO: We're throwing an exception here on empty DN. Should return a
@@ -1465,14 +1479,7 @@ def search(args = {})
14651479
#++
14661480
def modify(args)
14671481
modify_dn = args[:dn] or raise "Unable to modify empty DN"
1468-
modify_ops = []
1469-
a = args[:operations] and a.each { |op, attr, values|
1470-
# TODO, fix the following line, which gives a bogus error if the
1471-
# opcode is invalid.
1472-
op_1 = { :add => 0, :delete => 1, :replace => 2 }[op.to_sym].to_ber_enumerated
1473-
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
1474-
}
1475-
1482+
modify_ops = modify_ops args[:operations]
14761483
request = [modify_dn.to_ber,
14771484
modify_ops.to_ber_sequence].to_ber_appsequence(6)
14781485
pkt = [next_msgid.to_ber, request].to_ber_sequence

test/test_ldap_connection.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'common'
2+
3+
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
10+
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
17+
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
24+
end

0 commit comments

Comments
 (0)