From 09b054264181225fdfd7f28095bb6c5272990a1e Mon Sep 17 00:00:00 2001 From: Mattias Ohlsson Date: Tue, 1 Jul 2014 09:58:55 +0200 Subject: [PATCH 1/2] handle base64 encoded dn attr --- lib/net/ldap/dataset.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net/ldap/dataset.rb b/lib/net/ldap/dataset.rb index ffdee11f..2f924b34 100644 --- a/lib/net/ldap/dataset.rb +++ b/lib/net/ldap/dataset.rb @@ -125,8 +125,10 @@ def read_ldif(io) if line =~ /^#/ ds.comments << line yield :comment, line if block_given? - elsif line =~ /^dn:[\s]*/i - dn = $' + elsif line =~ /^dn:([\:]?)[\s]*/i + # $1 is a colon if the dn-value is base-64 encoded + # $' is the dn-value + dn = ($1 == ":") ? $'.unpack('m').shift : $' ds[dn] = Hash.new { |k,v| k[v] = [] } yield :dn, dn if block_given? elsif line.empty? From 456cd55988454f89f365b9f667ccfeabc564c0f7 Mon Sep 17 00:00:00 2001 From: Mattias Ohlsson Date: Thu, 9 Oct 2014 21:38:04 +0200 Subject: [PATCH 2/2] Add test cases for base64 dn --- test/test_ldif.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_ldif.rb b/test/test_ldif.rb index fb4d5ee9..0f4dae4e 100644 --- a/test/test_ldif.rb +++ b/test/test_ldif.rb @@ -47,6 +47,18 @@ def test_ldif_tab_is_not_continuation assert_equal(true, ds.has_key?("key")) end + def test_ldif_with_base64_dn + str = "dn:: Q049QmFzZTY0IGRuIHRlc3QsT1U9VGVzdCxPVT1Vbml0cyxEQz1leGFtcGxlLERDPWNvbQ==\r\n\r\n" + ds = Net::LDAP::Dataset::read_ldif(StringIO.new(str)) + assert_equal(true, ds.has_key?("CN=Base64 dn test,OU=Test,OU=Units,DC=example,DC=com")) + end + + def test_ldif_with_base64_dn_and_continuation_lines + str = "dn:: Q049QmFzZTY0IGRuIHRlc3Qgd2l0aCBjb250aW51YXRpb24gbGluZSxPVT1UZXN0LE9VPVVua\r\n XRzLERDPWV4YW1wbGUsREM9Y29t\r\n\r\n" + ds = Net::LDAP::Dataset::read_ldif(StringIO.new(str)) + assert_equal(true, ds.has_key?("CN=Base64 dn test with continuation line,OU=Test,OU=Units,DC=example,DC=com")) + end + # TODO, INADEQUATE. We need some more tests # to verify the content. def test_ldif