Commit 1d1ad7e0 authored by Michael Kozono's avatar Michael Kozono

Refactor DN error classes

parent 1c945de9
...@@ -10,10 +10,11 @@ module Gitlab ...@@ -10,10 +10,11 @@ module Gitlab
# accompanied by another migration. # accompanied by another migration.
module Gitlab module Gitlab
module LDAP module LDAP
MalformedDnError = Class.new(StandardError)
UnsupportedDnFormatError = Class.new(StandardError)
class DN class DN
FormatError = Class.new(StandardError)
MalformedError = Class.new(FormatError)
UnsupportedError = Class.new(FormatError)
def self.normalize_value(given_value) def self.normalize_value(given_value)
dummy_dn = "placeholder=#{given_value}" dummy_dn = "placeholder=#{given_value}"
normalized_dn = new(*dummy_dn).to_normalized_s normalized_dn = new(*dummy_dn).to_normalized_s
...@@ -79,19 +80,19 @@ module Gitlab ...@@ -79,19 +80,19 @@ module Gitlab
state = :key_oid state = :key_oid
key << char key << char
when ' ' then state = :key when ' ' then state = :key
else raise(MalformedDnError, "Unrecognized first character of an RDN attribute type name \"#{char}\"") else raise(MalformedError, "Unrecognized first character of an RDN attribute type name \"#{char}\"")
end end
when :key_normal then when :key_normal then
case char case char
when '=' then state = :value when '=' then state = :value
when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char
else raise(MalformedDnError, "Unrecognized RDN attribute type name character \"#{char}\"") else raise(MalformedError, "Unrecognized RDN attribute type name character \"#{char}\"")
end end
when :key_oid then when :key_oid then
case char case char
when '=' then state = :value when '=' then state = :value
when '0'..'9', '.', ' ' then key << char when '0'..'9', '.', ' ' then key << char
else raise(MalformedDnError, "Unrecognized RDN OID attribute type name character \"#{char}\"") else raise(MalformedError, "Unrecognized RDN OID attribute type name character \"#{char}\"")
end end
when :value then when :value then
case char case char
...@@ -118,7 +119,7 @@ module Gitlab ...@@ -118,7 +119,7 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
when '+' then raise(UnsupportedDnFormatError, "Multivalued RDNs are not supported") when '+' then raise(UnsupportedError, "Multivalued RDNs are not supported")
else value << char else value << char
end end
when :value_normal_escape then when :value_normal_escape then
...@@ -135,7 +136,7 @@ module Gitlab ...@@ -135,7 +136,7 @@ module Gitlab
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_normal state = :value_normal
value << "#{hex_buffer}#{char}".to_i(16).chr value << "#{hex_buffer}#{char}".to_i(16).chr
else raise(MalformedDnError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"") else raise(MalformedError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"")
end end
when :value_quoted then when :value_quoted then
case char case char
...@@ -157,7 +158,7 @@ module Gitlab ...@@ -157,7 +158,7 @@ module Gitlab
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_quoted state = :value_quoted
value << "#{hex_buffer}#{char}".to_i(16).chr value << "#{hex_buffer}#{char}".to_i(16).chr
else raise(MalformedDnError, "Expected the second character of a hex pair inside a double quoted value, but got \"#{char}\"") else raise(MalformedError, "Expected the second character of a hex pair inside a double quoted value, but got \"#{char}\"")
end end
when :value_hexstring then when :value_hexstring then
case char case char
...@@ -170,14 +171,14 @@ module Gitlab ...@@ -170,14 +171,14 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
else raise(MalformedDnError, "Expected the first character of a hex pair, but got \"#{char}\"") else raise(MalformedError, "Expected the first character of a hex pair, but got \"#{char}\"")
end end
when :value_hexstring_hex then when :value_hexstring_hex then
case char case char
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_hexstring state = :value_hexstring
value << char value << char
else raise(MalformedDnError, "Expected the second character of a hex pair, but got \"#{char}\"") else raise(MalformedError, "Expected the second character of a hex pair, but got \"#{char}\"")
end end
when :value_end then when :value_end then
case char case char
...@@ -187,14 +188,14 @@ module Gitlab ...@@ -187,14 +188,14 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
else raise(MalformedDnError, "Expected the end of an attribute value, but got \"#{char}\"") else raise(MalformedError, "Expected the end of an attribute value, but got \"#{char}\"")
end end
else raise "Fell out of state machine" else raise "Fell out of state machine"
end end
end end
# Last pair # Last pair
raise(MalformedDnError, 'DN string ended unexpectedly') unless raise(MalformedError, 'DN string ended unexpectedly') unless
[:value, :value_normal, :value_hexstring, :value_end].include? state [:value, :value_normal, :value_hexstring, :value_end].include? state
yield key.string.strip, rstrip_except_escaped(value.string, @dn.length) yield key.string.strip, rstrip_except_escaped(value.string, @dn.length)
...@@ -290,7 +291,7 @@ module Gitlab ...@@ -290,7 +291,7 @@ module Gitlab
unless identity.save unless identity.save
Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\". Skipping." Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\". Skipping."
end end
rescue Gitlab::LDAP::MalformedDnError, Gitlab::LDAP::UnsupportedDnFormatError => e rescue Gitlab::LDAP::DN::FormatError => e
Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\" due to \"#{e.message}\". Skipping." Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\" due to \"#{e.message}\". Skipping."
end end
end end
......
...@@ -21,10 +21,11 @@ ...@@ -21,10 +21,11 @@
# class also helps take care of that. # class also helps take care of that.
module Gitlab module Gitlab
module LDAP module LDAP
MalformedDnError = Class.new(StandardError)
UnsupportedDnFormatError = Class.new(StandardError)
class DN class DN
FormatError = Class.new(StandardError)
MalformedError = Class.new(FormatError)
UnsupportedError = Class.new(FormatError)
def self.normalize_value(given_value) def self.normalize_value(given_value)
dummy_dn = "placeholder=#{given_value}" dummy_dn = "placeholder=#{given_value}"
normalized_dn = new(*dummy_dn).to_normalized_s normalized_dn = new(*dummy_dn).to_normalized_s
...@@ -90,19 +91,19 @@ module Gitlab ...@@ -90,19 +91,19 @@ module Gitlab
state = :key_oid state = :key_oid
key << char key << char
when ' ' then state = :key when ' ' then state = :key
else raise(MalformedDnError, "Unrecognized first character of an RDN attribute type name \"#{char}\"") else raise(MalformedError, "Unrecognized first character of an RDN attribute type name \"#{char}\"")
end end
when :key_normal then when :key_normal then
case char case char
when '=' then state = :value when '=' then state = :value
when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char when 'a'..'z', 'A'..'Z', '0'..'9', '-', ' ' then key << char
else raise(MalformedDnError, "Unrecognized RDN attribute type name character \"#{char}\"") else raise(MalformedError, "Unrecognized RDN attribute type name character \"#{char}\"")
end end
when :key_oid then when :key_oid then
case char case char
when '=' then state = :value when '=' then state = :value
when '0'..'9', '.', ' ' then key << char when '0'..'9', '.', ' ' then key << char
else raise(MalformedDnError, "Unrecognized RDN OID attribute type name character \"#{char}\"") else raise(MalformedError, "Unrecognized RDN OID attribute type name character \"#{char}\"")
end end
when :value then when :value then
case char case char
...@@ -129,7 +130,7 @@ module Gitlab ...@@ -129,7 +130,7 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
when '+' then raise(UnsupportedDnFormatError, "Multivalued RDNs are not supported") when '+' then raise(UnsupportedError, "Multivalued RDNs are not supported")
else value << char else value << char
end end
when :value_normal_escape then when :value_normal_escape then
...@@ -146,7 +147,7 @@ module Gitlab ...@@ -146,7 +147,7 @@ module Gitlab
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_normal state = :value_normal
value << "#{hex_buffer}#{char}".to_i(16).chr value << "#{hex_buffer}#{char}".to_i(16).chr
else raise(MalformedDnError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"") else raise(MalformedError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"")
end end
when :value_quoted then when :value_quoted then
case char case char
...@@ -168,7 +169,7 @@ module Gitlab ...@@ -168,7 +169,7 @@ module Gitlab
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_quoted state = :value_quoted
value << "#{hex_buffer}#{char}".to_i(16).chr value << "#{hex_buffer}#{char}".to_i(16).chr
else raise(MalformedDnError, "Expected the second character of a hex pair inside a double quoted value, but got \"#{char}\"") else raise(MalformedError, "Expected the second character of a hex pair inside a double quoted value, but got \"#{char}\"")
end end
when :value_hexstring then when :value_hexstring then
case char case char
...@@ -181,14 +182,14 @@ module Gitlab ...@@ -181,14 +182,14 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
else raise(MalformedDnError, "Expected the first character of a hex pair, but got \"#{char}\"") else raise(MalformedError, "Expected the first character of a hex pair, but got \"#{char}\"")
end end
when :value_hexstring_hex then when :value_hexstring_hex then
case char case char
when '0'..'9', 'a'..'f', 'A'..'F' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_hexstring state = :value_hexstring
value << char value << char
else raise(MalformedDnError, "Expected the second character of a hex pair, but got \"#{char}\"") else raise(MalformedError, "Expected the second character of a hex pair, but got \"#{char}\"")
end end
when :value_end then when :value_end then
case char case char
...@@ -198,14 +199,14 @@ module Gitlab ...@@ -198,14 +199,14 @@ module Gitlab
yield key.string.strip, rstrip_except_escaped(value.string, dn_index) yield key.string.strip, rstrip_except_escaped(value.string, dn_index)
key = StringIO.new key = StringIO.new
value = StringIO.new value = StringIO.new
else raise(MalformedDnError, "Expected the end of an attribute value, but got \"#{char}\"") else raise(MalformedError, "Expected the end of an attribute value, but got \"#{char}\"")
end end
else raise "Fell out of state machine" else raise "Fell out of state machine"
end end
end end
# Last pair # Last pair
raise(MalformedDnError, 'DN string ended unexpectedly') unless raise(MalformedError, 'DN string ended unexpectedly') unless
[:value, :value_normal, :value_hexstring, :value_end].include? state [:value, :value_normal, :value_hexstring, :value_end].include? state
yield key.string.strip, rstrip_except_escaped(value.string, @dn.length) yield key.string.strip, rstrip_except_escaped(value.string, @dn.length)
......
...@@ -42,7 +42,7 @@ module Gitlab ...@@ -42,7 +42,7 @@ module Gitlab
# 2. The string is downcased (for case-insensitivity) # 2. The string is downcased (for case-insensitivity)
def self.normalize_uid(uid) def self.normalize_uid(uid)
::Gitlab::LDAP::DN.normalize_value(uid) ::Gitlab::LDAP::DN.normalize_value(uid)
rescue ::Gitlab::LDAP::MalformedDnError, ::Gitlab::LDAP::UnsupportedDnFormatError => e rescue ::Gitlab::LDAP::DN::FormatError => e
Rails.logger.info("Returning original UID \"#{uid}\" due to error during normalization attempt: #{e.message}") Rails.logger.info("Returning original UID \"#{uid}\" due to error during normalization attempt: #{e.message}")
Rails.logger.info(e.backtrace.join("\n")) Rails.logger.info(e.backtrace.join("\n"))
......
...@@ -12,64 +12,64 @@ describe Gitlab::LDAP::DN do ...@@ -12,64 +12,64 @@ describe Gitlab::LDAP::DN do
context 'when ending with a comma' do context 'when ending with a comma' do
let(:given) { 'John Smith,' } let(:given) { 'John Smith,' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'when given a BER encoded attribute value with a space in it' do context 'when given a BER encoded attribute value with a space in it' do
let(:given) { '#aa aa' } let(:given) { '#aa aa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the end of an attribute value, but got \"a\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the end of an attribute value, but got \"a\"")
end end
end end
context 'when given a BER encoded attribute value with a non-hex character in it' do context 'when given a BER encoded attribute value with a non-hex character in it' do
let(:given) { '#aaXaaa' } let(:given) { '#aaXaaa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the first character of a hex pair, but got \"X\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the first character of a hex pair, but got \"X\"")
end end
end end
context 'when given a BER encoded attribute value with a non-hex character in it' do context 'when given a BER encoded attribute value with a non-hex character in it' do
let(:given) { '#aaaYaa' } let(:given) { '#aaaYaa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the second character of a hex pair, but got \"Y\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the second character of a hex pair, but got \"Y\"")
end end
end end
context 'when given a hex pair with a non-hex character in it, inside double quotes' do context 'when given a hex pair with a non-hex character in it, inside double quotes' do
let(:given) { '"Sebasti\\cX\\a1n"' } let(:given) { '"Sebasti\\cX\\a1n"' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the second character of a hex pair inside a double quoted value, but got \"X\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the second character of a hex pair inside a double quoted value, but got \"X\"")
end end
end end
context 'with an open (as opposed to closed) double quote' do context 'with an open (as opposed to closed) double quote' do
let(:given) { '"James' } let(:given) { '"James' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'with an invalid escaped hex code' do context 'with an invalid escaped hex code' do
let(:given) { 'J\ames' } let(:given) { 'J\ames' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Invalid escaped hex code "\am"') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Invalid escaped hex code "\am"')
end end
end end
context 'with a value ending with the escape character' do context 'with a value ending with the escape character' do
let(:given) { 'foo\\' } let(:given) { 'foo\\' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
end end
...@@ -119,8 +119,8 @@ describe Gitlab::LDAP::DN do ...@@ -119,8 +119,8 @@ describe Gitlab::LDAP::DN do
context 'without extraneous whitespace' do context 'without extraneous whitespace' do
let(:given) { 'uid=john smith+telephonenumber=+1 555-555-5555,ou=people,dc=example,dc=com' } let(:given) { 'uid=john smith+telephonenumber=+1 555-555-5555,ou=people,dc=example,dc=com' }
it 'raises UnsupportedDnFormatError' do it 'raises UnsupportedError' do
expect { subject }.to raise_error(Gitlab::LDAP::UnsupportedDnFormatError) expect { subject }.to raise_error(Gitlab::LDAP::DN::UnsupportedError)
end end
end end
...@@ -128,16 +128,16 @@ describe Gitlab::LDAP::DN do ...@@ -128,16 +128,16 @@ describe Gitlab::LDAP::DN do
context 'around the phone number plus sign' do context 'around the phone number plus sign' do
let(:given) { 'uid = John Smith + telephoneNumber = + 1 555-555-5555 , ou = People,dc=example,dc=com' } let(:given) { 'uid = John Smith + telephoneNumber = + 1 555-555-5555 , ou = People,dc=example,dc=com' }
it 'raises UnsupportedDnFormatError' do it 'raises UnsupportedError' do
expect { subject }.to raise_error(Gitlab::LDAP::UnsupportedDnFormatError) expect { subject }.to raise_error(Gitlab::LDAP::DN::UnsupportedError)
end end
end end
context 'not around the phone number plus sign' do context 'not around the phone number plus sign' do
let(:given) { 'uid = John Smith + telephoneNumber = +1 555-555-5555 , ou = People,dc=example,dc=com' } let(:given) { 'uid = John Smith + telephoneNumber = +1 555-555-5555 , ou = People,dc=example,dc=com' }
it 'raises UnsupportedDnFormatError' do it 'raises UnsupportedError' do
expect { subject }.to raise_error(Gitlab::LDAP::UnsupportedDnFormatError) expect { subject }.to raise_error(Gitlab::LDAP::DN::UnsupportedError)
end end
end end
end end
...@@ -148,104 +148,104 @@ describe Gitlab::LDAP::DN do ...@@ -148,104 +148,104 @@ describe Gitlab::LDAP::DN do
context 'when ending with a comma' do context 'when ending with a comma' do
let(:given) { 'uid=John Smith,' } let(:given) { 'uid=John Smith,' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'when given a BER encoded attribute value with a space in it' do context 'when given a BER encoded attribute value with a space in it' do
let(:given) { '0.9.2342.19200300.100.1.25=#aa aa' } let(:given) { '0.9.2342.19200300.100.1.25=#aa aa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the end of an attribute value, but got \"a\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the end of an attribute value, but got \"a\"")
end end
end end
context 'when given a BER encoded attribute value with a non-hex character in it' do context 'when given a BER encoded attribute value with a non-hex character in it' do
let(:given) { '0.9.2342.19200300.100.1.25=#aaXaaa' } let(:given) { '0.9.2342.19200300.100.1.25=#aaXaaa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the first character of a hex pair, but got \"X\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the first character of a hex pair, but got \"X\"")
end end
end end
context 'when given a BER encoded attribute value with a non-hex character in it' do context 'when given a BER encoded attribute value with a non-hex character in it' do
let(:given) { '0.9.2342.19200300.100.1.25=#aaaYaa' } let(:given) { '0.9.2342.19200300.100.1.25=#aaaYaa' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the second character of a hex pair, but got \"Y\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the second character of a hex pair, but got \"Y\"")
end end
end end
context 'when given a hex pair with a non-hex character in it, inside double quotes' do context 'when given a hex pair with a non-hex character in it, inside double quotes' do
let(:given) { 'uid="Sebasti\\cX\\a1n"' } let(:given) { 'uid="Sebasti\\cX\\a1n"' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, "Expected the second character of a hex pair inside a double quoted value, but got \"X\"") expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, "Expected the second character of a hex pair inside a double quoted value, but got \"X\"")
end end
end end
context 'without a name value pair' do context 'without a name value pair' do
let(:given) { 'John' } let(:given) { 'John' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'with an open (as opposed to closed) double quote' do context 'with an open (as opposed to closed) double quote' do
let(:given) { 'cn="James' } let(:given) { 'cn="James' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'with an invalid escaped hex code' do context 'with an invalid escaped hex code' do
let(:given) { 'cn=J\ames' } let(:given) { 'cn=J\ames' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Invalid escaped hex code "\am"') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Invalid escaped hex code "\am"')
end end
end end
context 'with a value ending with the escape character' do context 'with a value ending with the escape character' do
let(:given) { 'cn=\\' } let(:given) { 'cn=\\' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'DN string ended unexpectedly') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'DN string ended unexpectedly')
end end
end end
context 'with an invalid OID attribute type name' do context 'with an invalid OID attribute type name' do
let(:given) { '1.2.d=Value' } let(:given) { '1.2.d=Value' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Unrecognized RDN OID attribute type name character "d"') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Unrecognized RDN OID attribute type name character "d"')
end end
end end
context 'with a period in a non-OID attribute type name' do context 'with a period in a non-OID attribute type name' do
let(:given) { 'd1.2=Value' } let(:given) { 'd1.2=Value' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Unrecognized RDN attribute type name character "."') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Unrecognized RDN attribute type name character "."')
end end
end end
context 'when starting with non-space, non-alphanumeric character' do context 'when starting with non-space, non-alphanumeric character' do
let(:given) { ' -uid=John Smith' } let(:given) { ' -uid=John Smith' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Unrecognized first character of an RDN attribute type name "-"') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Unrecognized first character of an RDN attribute type name "-"')
end end
end end
context 'when given a UID with an escaped equal sign' do context 'when given a UID with an escaped equal sign' do
let(:given) { 'uid\\=john' } let(:given) { 'uid\\=john' }
it 'raises MalformedDnError' do it 'raises MalformedError' do
expect { subject }.to raise_error(Gitlab::LDAP::MalformedDnError, 'Unrecognized RDN attribute type name character "\\"') expect { subject }.to raise_error(Gitlab::LDAP::DN::MalformedError, 'Unrecognized RDN attribute type name character "\\"')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment