Skip to content

Commit 7b801fc

Browse files
committed
Merge pull request #142 from ruby-ldap/true-ber
Encode true as xFF
2 parents 0df44b0 + f658a86 commit 7b801fc

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

lib/net/ber/core_ext/true_class.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module Net::BER::Extensions::TrueClass
55
##
66
# Converts +true+ to the BER wireline representation of +true+.
77
def to_ber
8-
# 20100319 AZ: Note that this may not be the completely correct value,
9-
# per some test documentation. We need to determine the truth of this.
10-
"\001\001\001"
8+
# http://tools.ietf.org/html/rfc4511#section-5.1
9+
"\001\001\xFF".force_encoding("ASCII-8BIT")
1110
end
1211
end

test/ber/test_ber.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def test_array
1212
assert_equal ary, encoded_ary.read_ber
1313
end
1414

15+
# http://tools.ietf.org/html/rfc4511#section-5.1
1516
def test_true
16-
assert_equal "\x01\x01\x01", true.to_ber
17+
assert_equal "\x01\x01\xFF".b, true.to_ber
1718
end
1819

1920
def test_false

test/integration/test_ber.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require_relative '../test_helper'
2+
3+
class TestBERIntegration < LDAPIntegrationTestCase
4+
# Test whether the TRUE boolean value is encoded correctly by performing a
5+
# search operation.
6+
def test_true_ber_encoding
7+
# request these attrs to simplify test; use symbols to match Entry#attribute_names
8+
attrs = [:dn, :uid, :cn, :mail]
9+
10+
assert types_entry = @ldap.search(
11+
base: "dc=rubyldap,dc=com",
12+
filter: "(uid=user1)",
13+
size: 1,
14+
attributes: attrs,
15+
attributes_only: true
16+
).first
17+
18+
# matches attributes we requested
19+
assert_equal attrs, types_entry.attribute_names
20+
21+
# assert values are empty
22+
types_entry.each do |name, values|
23+
next if name == :dn
24+
assert values.empty?
25+
end
26+
27+
assert_includes Net::LDAP::ResultCodesSearchSuccess,
28+
@ldap.get_operation_result.code, "should be a successful search operation"
29+
end
30+
end

0 commit comments

Comments
 (0)