Skip to content

Commit 78d9df8

Browse files
Add Net::LDAP::InvalidDNError
1 parent 8ef75a0 commit 78d9df8

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lib/net/ldap/dn.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ def each_pair
5757
state = :key_oid
5858
key << char
5959
when ' ' then state = :key
60-
else raise "DN badly formed"
60+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
6161
end
6262
when :key_normal then
6363
case char
6464
when '=' then state = :value
6565
when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char
66-
else raise "DN badly formed"
66+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
6767
end
6868
when :key_oid then
6969
case char
7070
when '=' then state = :value
7171
when '0'..'9', '.', ' ' then key << char
72-
else raise "DN badly formed"
72+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
7373
end
7474
when :value then
7575
case char
@@ -110,7 +110,7 @@ def each_pair
110110
when '0'..'9', 'a'..'f', 'A'..'F' then
111111
state = :value_normal
112112
value << "#{hex_buffer}#{char}".to_i(16).chr
113-
else raise "DN badly formed"
113+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
114114
end
115115
when :value_quoted then
116116
case char
@@ -132,7 +132,7 @@ def each_pair
132132
when '0'..'9', 'a'..'f', 'A'..'F' then
133133
state = :value_quoted
134134
value << "#{hex_buffer}#{char}".to_i(16).chr
135-
else raise "DN badly formed"
135+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
136136
end
137137
when :value_hexstring then
138138
case char
@@ -145,14 +145,14 @@ def each_pair
145145
yield key.string.strip, value.string.rstrip
146146
key = StringIO.new
147147
value = StringIO.new;
148-
else raise "DN badly formed"
148+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
149149
end
150150
when :value_hexstring_hex then
151151
case char
152152
when '0'..'9', 'a'..'f', 'A'..'F' then
153153
state = :value_hexstring
154154
value << char
155-
else raise "DN badly formed"
155+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
156156
end
157157
when :value_end then
158158
case char
@@ -162,14 +162,14 @@ def each_pair
162162
yield key.string.strip, value.string.rstrip
163163
key = StringIO.new
164164
value = StringIO.new;
165-
else raise "DN badly formed"
165+
else raise Net::LDAP::InvalidDNError, "DN badly formed"
166166
end
167-
else raise "Fell out of state machine"
167+
else raise Net::LDAP::InvalidDNError, "Fell out of state machine"
168168
end
169169
end
170170

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

175175
yield key.string.strip, value.string.rstrip

lib/net/ldap/error.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SearchScopeInvalidError < Error; end
6060
class ResponseTypeInvalidError < Error; end
6161
class ResponseMissingOrInvalidError < Error; end
6262
class EmptyDNError < Error; end
63+
class InvalidDNError < Error; end
6364
class HashTypeUnsupportedError < Error; end
6465
class OperatorError < Error; end
6566
class SubstringFilterError < Error; end

test/test_dn.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def test_to_a_hash_symbol
2626
assert_equal ['1.23.4', '#A3B4D5', 'ou', 'Company'], dn.to_a
2727
end
2828

29-
# TODO: raise a more specific exception than RuntimeError
3029
def test_bad_input_raises_error
3130
[
3231
'cn=James,',
@@ -38,7 +37,7 @@ def test_bad_input_raises_error
3837
'd1.2=Value',
3938
].each do |input|
4039
dn = Net::LDAP::DN.new(input)
41-
assert_raises(RuntimeError) { dn.to_a }
40+
assert_raises(Net::LDAP::InvalidDNError) { dn.to_a }
4241
end
4342
end
4443
end

0 commit comments

Comments
 (0)