Commit b3d61832 authored by Michael Kozono's avatar Michael Kozono

Move downcasing to normalize method

parent e610332e
...@@ -40,7 +40,7 @@ module Gitlab ...@@ -40,7 +40,7 @@ module Gitlab
buffer << "=" if index.odd? buffer << "=" if index.odd?
buffer << "," if index.even? && index != 0 buffer << "," if index.even? && index != 0
arg = args[index].downcase arg = args[index]
buffer << if index < args.length - 1 || index.odd? buffer << if index < args.length - 1 || index.odd?
self.class.escape(arg) self.class.escape(arg)
...@@ -68,7 +68,7 @@ module Gitlab ...@@ -68,7 +68,7 @@ module Gitlab
case state case state
when :key then when :key then
case char case char
when 'a'..'z' then when 'a'..'z', 'A'..'Z' then
state = :key_normal state = :key_normal
key << char key << char
when '0'..'9' then when '0'..'9' then
...@@ -80,7 +80,7 @@ module Gitlab ...@@ -80,7 +80,7 @@ module Gitlab
when :key_normal then when :key_normal then
case char case char
when '=' then state = :value when '=' then state = :value
when '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(MalformedDnError, "Unrecognized RDN attribute type name character \"#{char}\"")
end end
when :key_oid then when :key_oid then
...@@ -119,7 +119,7 @@ module Gitlab ...@@ -119,7 +119,7 @@ module Gitlab
end end
when :value_normal_escape then when :value_normal_escape then
case char case char
when '0'..'9', 'a'..'f' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_normal_escape_hex state = :value_normal_escape_hex
hex_buffer = char hex_buffer = char
when /\s/ then when /\s/ then
...@@ -131,7 +131,7 @@ module Gitlab ...@@ -131,7 +131,7 @@ module Gitlab
end end
when :value_normal_escape_hex then when :value_normal_escape_hex then
case char case char
when '0'..'9', '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(MalformedDnError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"")
...@@ -155,7 +155,7 @@ module Gitlab ...@@ -155,7 +155,7 @@ module Gitlab
end end
when :value_quoted_escape then when :value_quoted_escape then
case char case char
when '0'..'9', 'a'..'f' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_quoted_escape_hex state = :value_quoted_escape_hex
hex_buffer = char hex_buffer = char
else else
...@@ -164,14 +164,14 @@ module Gitlab ...@@ -164,14 +164,14 @@ module Gitlab
end end
when :value_quoted_escape_hex then when :value_quoted_escape_hex then
case char case char
when '0'..'9', '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(MalformedDnError, "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
when '0'..'9', 'a'..'f' then when '0'..'9', 'a'..'f', 'A'..'F' then
state = :value_hexstring_hex state = :value_hexstring_hex
value << char value << char
when ' ' then state = :value_end when ' ' then state = :value_end
...@@ -184,7 +184,7 @@ module Gitlab ...@@ -184,7 +184,7 @@ module Gitlab
end end
when :value_hexstring_hex then when :value_hexstring_hex then
case char case char
when '0'..'9', '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(MalformedDnError, "Expected the second character of a hex pair, but got \"#{char}\"")
...@@ -227,7 +227,7 @@ module Gitlab ...@@ -227,7 +227,7 @@ module Gitlab
## ##
# Return the DN as an escaped and normalized string. # Return the DN as an escaped and normalized string.
def to_s_normalized def to_s_normalized
self.class.new(*to_a).to_s self.class.new(*to_a).to_s.downcase
end end
# https://tools.ietf.org/html/rfc4514 section 2.4 lists these exceptions # https://tools.ietf.org/html/rfc4514 section 2.4 lists these exceptions
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::LDAP::DN do describe Gitlab::LDAP::DN do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
describe '#initialize' do describe '#to_s_normalized' do
subject { described_class.new(given).to_s_normalized } subject { described_class.new(given).to_s_normalized }
# Regarding the telephoneNumber test: # Regarding the telephoneNumber test:
...@@ -93,7 +93,7 @@ describe Gitlab::LDAP::DN do ...@@ -93,7 +93,7 @@ describe Gitlab::LDAP::DN 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 MalformedDnError' 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::MalformedDnError, "Expected the first character of a hex pair, but got \"X\"")
end end
end end
...@@ -101,7 +101,7 @@ describe Gitlab::LDAP::DN do ...@@ -101,7 +101,7 @@ describe Gitlab::LDAP::DN 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 MalformedDnError' 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::MalformedDnError, "Expected the second character of a hex pair, but got \"Y\"")
end end
end end
...@@ -109,7 +109,7 @@ describe Gitlab::LDAP::DN do ...@@ -109,7 +109,7 @@ describe Gitlab::LDAP::DN do
let(:given) { 'uid="Sebasti\\cX\\a1n"' } let(:given) { 'uid="Sebasti\\cX\\a1n"' }
it 'raises MalformedDnError' do it 'raises MalformedDnError' 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::MalformedDnError, "Expected the second character of a hex pair inside a double quoted value, but got \"X\"")
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