Skip to content

handle base64 encoded dn attr #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/net/ldap/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ def read_ldif(io)
elsif line =~ /^version:[\s]*([0-9]+)$/i
ds.version = $1
yield :version, 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
# Avoid the Base64 class because not all Ruby versions have it.
dn = ($1 == ":") ? $'.unpack('m').shift : $'
ds[dn] = Hash.new { |k,v| k[v] = [] }
yield :dn, dn if block_given?
elsif line.empty?
Expand Down
12 changes: 12 additions & 0 deletions test/test_ldif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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
Expand Down