Skip to content

handle base64 encoded dn attr #94

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 4 additions & 2 deletions lib/net/ldap/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 : $'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming unpack('m') is used here because it's also used below? Should be using Base64.decode64 but that can be polished separately, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @@ -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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert ... is equivalent to assert_equal true, ..., but also check out assert_predicate.

I see that this is just based off other tests in the file, though. I'm happy to take care of cleaning those up separately.

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