Skip to content

Commit b6b7985

Browse files
author
Chris Dwan
committed
fixes based on comments for pull request
1 parent 463ac43 commit b6b7985

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

lib/net/ber/core_ext/array.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ def to_ber_oid
8686
# [['1.2.840.113556.1.4.805',true]]
8787
#
8888
def to_ber_control
89-
ary = self.collect do |control_sequence|
90-
control_sequence.collect{|element| element.to_ber}.to_ber_sequence
89+
#if our array does not contain at least one array then wrap it in an array before going forward
90+
ary = self[0].kind_of?(Array) ? self : [self]
91+
ary = ary.collect do |control_sequence|
92+
control_sequence.collect{|element| element.to_ber}.to_ber_sequence.reject_empty_ber_arrays
9193
end
92-
ary.to_ber_sequence #putting this on a new line to make it more readable.
94+
ary.to_ber_sequence.reject_empty_ber_arrays
9395
end
9496
end

lib/net/ber/core_ext/string.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ def to_ber_contextspecific(code)
4646
def read_ber(syntax = nil)
4747
StringIO.new(self).read_ber(syntax)
4848
end
49-
49+
5050
##
51-
# Destructively reads a BER object from the string.
51+
# Destructively reads a BER object from the string.
5252
def read_ber!(syntax = nil)
5353
io = StringIO.new(self)
5454

5555
result = io.read_ber(syntax)
5656
self.slice!(0...io.pos)
57-
57+
5858
return result
5959
end
60+
61+
def reject_empty_ber_arrays
62+
self.gsub(/0\000/n,'')
63+
end
6064
end

lib/net/ldap.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@ class LdapError < StandardError; end
334334
68 => "Entry Already Exists"
335335
}
336336

337-
module LdapControls
338-
PagedResults = "1.2.840.113556.1.4.319" # Microsoft evil from RFC 2696
337+
module LDAPControls
338+
PAGED_RESULTS = "1.2.840.113556.1.4.319" # Microsoft evil from RFC 2696
339+
DELETE_TREE = "1.2.840.113556.1.4.805"
339340
end
340341

341342
def self.result2string(code) #:nodoc:
@@ -552,7 +553,7 @@ def open
552553
# anything with the bind results. We then pass self to the caller's
553554
# block, where he will execute his LDAP operations. Of course they will
554555
# all generate auth failures if the bind was unsuccessful.
555-
raise Net::LDAP::LdapError, "Open already in progress" if @open_connection
556+
raise LdapError, "Open already in progress" if @open_connection
556557

557558
begin
558559
@open_connection = Net::LDAP::Connection.new(:host => @host,
@@ -1033,7 +1034,7 @@ def delete(args)
10331034
# dn = "[email protected], ou=people, dc=example, dc=com"
10341035
# ldap.delete_tree :dn => dn
10351036
def delete_tree(args)
1036-
delete(args.merge(:control_codes => [['1.2.840.113556.1.4.805',true]]))
1037+
delete(args.merge(:control_codes => [[LDAPControls::DELETE_TREE, true]]))
10371038
end
10381039
# This method is experimental and subject to change. Return the rootDSE
10391040
# record from the LDAP server as a Net::LDAP::Entry, or an empty Entry if
@@ -1105,7 +1106,7 @@ def search_subschema_entry
11051106
#++
11061107
def paged_searches_supported?
11071108
@server_caps ||= search_root_dse
1108-
@server_caps[:supportedcontrol].include?(Net::LDAP::LdapControls::PagedResults)
1109+
@server_caps[:supportedcontrol].include?(LDAPControls::PAGED_RESULTS)
11091110
end
11101111
end # class LDAP
11111112

@@ -1402,7 +1403,7 @@ def search(args = {})
14021403
controls = []
14031404
controls <<
14041405
[
1405-
Net::LDAP::LdapControls::PagedResults.to_ber,
1406+
LDAPControls::PAGED_RESULTS.to_ber,
14061407
# Criticality MUST be false to interoperate with normal LDAPs.
14071408
false.to_ber,
14081409
rfc2696_cookie.map{ |v| v.to_ber}.to_ber_sequence.to_s.to_ber
@@ -1450,7 +1451,7 @@ def search(args = {})
14501451
more_pages = false
14511452
if result_code == 0 and controls
14521453
controls.each do |c|
1453-
if c.oid == Net::LDAP::LdapControls::PagedResults
1454+
if c.oid == LDAPControls::PAGED_RESULTS
14541455
# just in case some bogus server sends us more than 1 of these.
14551456
more_pages = false
14561457
if c.value and c.value.length > 0

spec/unit/ber/core_ext/array_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@
1111
res = [['1.2.3', true],['1.7.9',false]].to_ber_control
1212
res.should eq(control_codes)
1313
end
14+
15+
it "should wrap the array in another array if a nested array is not passed" do
16+
result1 = ['1.2.3', true].to_ber_control
17+
result2 = [['1.2.3', true]].to_ber_control
18+
result1.should eq(result2)
19+
end
20+
21+
it "should return an empty string if an empty array is passed" do
22+
[].to_ber_control.should be_empty
23+
end
1424
end

0 commit comments

Comments
 (0)