Skip to content
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

Add Net::LDAP::InvalidDNError #371

Merged
merged 1 commit into from
Aug 18, 2020
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
20 changes: 10 additions & 10 deletions lib/net/ldap/dn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ def each_pair
state = :key_oid
key << char
when ' ' then state = :key
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :key_normal then
case char
when '=' then state = :value
when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :key_oid then
case char
when '=' then state = :value
when '0'..'9', '.', ' ' then key << char
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :value then
case char
Expand Down Expand Up @@ -110,7 +110,7 @@ def each_pair
when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_normal
value << "#{hex_buffer}#{char}".to_i(16).chr
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :value_quoted then
case char
Expand All @@ -132,7 +132,7 @@ def each_pair
when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_quoted
value << "#{hex_buffer}#{char}".to_i(16).chr
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :value_hexstring then
case char
Expand All @@ -145,14 +145,14 @@ def each_pair
yield key.string.strip, value.string.rstrip
key = StringIO.new
value = StringIO.new;
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :value_hexstring_hex then
case char
when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_hexstring
value << char
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
when :value_end then
case char
Expand All @@ -162,14 +162,14 @@ def each_pair
yield key.string.strip, value.string.rstrip
key = StringIO.new
value = StringIO.new;
else raise "DN badly formed"
else raise Net::LDAP::InvalidDNError, "DN badly formed"
end
else raise "Fell out of state machine"
else raise Net::LDAP::InvalidDNError, "Fell out of state machine"
end
end

# Last pair
raise "DN badly formed" unless
raise Net::LDAP::InvalidDNError, "DN badly formed" unless
[:value, :value_normal, :value_hexstring, :value_end].include? state

yield key.string.strip, value.string.rstrip
Expand Down
1 change: 1 addition & 0 deletions lib/net/ldap/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SearchScopeInvalidError < Error; end
class ResponseTypeInvalidError < Error; end
class ResponseMissingOrInvalidError < Error; end
class EmptyDNError < Error; end
class InvalidDNError < Error; end
class HashTypeUnsupportedError < Error; end
class OperatorError < Error; end
class SubstringFilterError < Error; end
Expand Down
3 changes: 1 addition & 2 deletions test/test_dn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_to_a_hash_symbol
assert_equal ['1.23.4', '#A3B4D5', 'ou', 'Company'], dn.to_a
end

# TODO: raise a more specific exception than RuntimeError
def test_bad_input_raises_error
[
'cn=James,',
Expand All @@ -38,7 +37,7 @@ def test_bad_input_raises_error
'd1.2=Value',
].each do |input|
dn = Net::LDAP::DN.new(input)
assert_raises(RuntimeError) { dn.to_a }
assert_raises(Net::LDAP::InvalidDNError) { dn.to_a }
end
end
end