From 480bd1706a19f2c9f0525d9c241f3bb126c45361 Mon Sep 17 00:00:00 2001 From: Matt Todd Date: Wed, 22 Oct 2014 00:18:25 -0700 Subject: [PATCH 1/3] Encode true as xFF According to the spec: http://tools.ietf.org/html/rfc4511#section-5.1 --- lib/net/ber/core_ext/true_class.rb | 5 ++--- test/ber/test_ber.rb | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/net/ber/core_ext/true_class.rb b/lib/net/ber/core_ext/true_class.rb index ac66c926..d6a8c8f7 100644 --- a/lib/net/ber/core_ext/true_class.rb +++ b/lib/net/ber/core_ext/true_class.rb @@ -5,8 +5,7 @@ module Net::BER::Extensions::TrueClass ## # Converts +true+ to the BER wireline representation of +true+. def to_ber - # 20100319 AZ: Note that this may not be the completely correct value, - # per some test documentation. We need to determine the truth of this. - "\001\001\001" + # http://tools.ietf.org/html/rfc4511#section-5.1 + "\001\001\xFF" end end diff --git a/test/ber/test_ber.rb b/test/ber/test_ber.rb index 6f641bb4..c2b0ef17 100644 --- a/test/ber/test_ber.rb +++ b/test/ber/test_ber.rb @@ -12,8 +12,9 @@ def test_array assert_equal ary, encoded_ary.read_ber end + # http://tools.ietf.org/html/rfc4511#section-5.1 def test_true - assert_equal "\x01\x01\x01", true.to_ber + assert_equal "\x01\x01\xFF", true.to_ber end def test_false From ab7b60c0d5508dfea24cbe30491719fceb833d66 Mon Sep 17 00:00:00 2001 From: Matt Todd Date: Wed, 22 Oct 2014 00:32:29 -0700 Subject: [PATCH 2/3] Force encoding to ASCII-8BIT We allow this since the library requires Ruby 1.9+ --- lib/net/ber/core_ext/true_class.rb | 2 +- test/ber/test_ber.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/net/ber/core_ext/true_class.rb b/lib/net/ber/core_ext/true_class.rb index d6a8c8f7..bf199d1e 100644 --- a/lib/net/ber/core_ext/true_class.rb +++ b/lib/net/ber/core_ext/true_class.rb @@ -6,6 +6,6 @@ module Net::BER::Extensions::TrueClass # Converts +true+ to the BER wireline representation of +true+. def to_ber # http://tools.ietf.org/html/rfc4511#section-5.1 - "\001\001\xFF" + "\001\001\xFF".force_encoding("ASCII-8BIT") end end diff --git a/test/ber/test_ber.rb b/test/ber/test_ber.rb index c2b0ef17..7eade7c2 100644 --- a/test/ber/test_ber.rb +++ b/test/ber/test_ber.rb @@ -14,7 +14,7 @@ def test_array # http://tools.ietf.org/html/rfc4511#section-5.1 def test_true - assert_equal "\x01\x01\xFF", true.to_ber + assert_equal "\x01\x01\xFF".b, true.to_ber end def test_false From f658a86649e32f4336a4614ea1baa85d311ee046 Mon Sep 17 00:00:00 2001 From: Matt Todd Date: Fri, 24 Oct 2014 15:02:42 -0700 Subject: [PATCH 3/3] Add BER integration test for true value --- test/integration/test_ber.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/integration/test_ber.rb diff --git a/test/integration/test_ber.rb b/test/integration/test_ber.rb new file mode 100644 index 00000000..8fb4d374 --- /dev/null +++ b/test/integration/test_ber.rb @@ -0,0 +1,30 @@ +require_relative '../test_helper' + +class TestBERIntegration < LDAPIntegrationTestCase + # Test whether the TRUE boolean value is encoded correctly by performing a + # search operation. + def test_true_ber_encoding + # request these attrs to simplify test; use symbols to match Entry#attribute_names + attrs = [:dn, :uid, :cn, :mail] + + assert types_entry = @ldap.search( + base: "dc=rubyldap,dc=com", + filter: "(uid=user1)", + size: 1, + attributes: attrs, + attributes_only: true + ).first + + # matches attributes we requested + assert_equal attrs, types_entry.attribute_names + + # assert values are empty + types_entry.each do |name, values| + next if name == :dn + assert values.empty? + end + + assert_includes Net::LDAP::ResultCodesSearchSuccess, + @ldap.get_operation_result.code, "should be a successful search operation" + end +end