Skip to content
Browse files

Merge remote-tracking branch 'larstobi/master'

  • Loading branch information...
2 parents a160b17 + 36b06f4 commit af6c59579373694f2e23cba36220b01b7a52dd42 Rory O'Connell committed Mar 16, 2011
Showing with 39 additions and 8 deletions.
  1. +15 −8 lib/net/ldap.rb
  2. +24 −0 test/test_ldap_connection.rb
View
23 lib/net/ldap.rb
@@ -1456,6 +1456,20 @@ def search(args = {})
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_ops
+ end
+
#--
# 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
@@ -1465,14 +1479,7 @@ def search(args = {})
#++
def modify(args)
modify_dn = args[:dn] or raise "Unable to modify empty DN"
- 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
- 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
- }
-
+ 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
View
24 test/test_ldap_connection.rb
@@ -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

0 comments on commit af6c595

Please sign in to comment.
Something went wrong with that request. Please try again.