From b3d61832c37b037f95dad619dd8c0680b6513818 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Mon, 2 Oct 2017 13:24:20 -0700 Subject: Move downcasing to normalize method --- lib/gitlab/ldap/dn.rb | 20 ++++++++++---------- spec/lib/gitlab/ldap/dn_spec.rb | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/gitlab/ldap/dn.rb b/lib/gitlab/ldap/dn.rb index 05252c75624..3766893ff6d 100644 --- a/lib/gitlab/ldap/dn.rb +++ b/lib/gitlab/ldap/dn.rb @@ -40,7 +40,7 @@ module Gitlab buffer << "=" if index.odd? buffer << "," if index.even? && index != 0 - arg = args[index].downcase + arg = args[index] buffer << if index < args.length - 1 || index.odd? self.class.escape(arg) @@ -68,7 +68,7 @@ module Gitlab case state when :key then case char - when 'a'..'z' then + when 'a'..'z', 'A'..'Z' then state = :key_normal key << char when '0'..'9' then @@ -80,7 +80,7 @@ module Gitlab when :key_normal then case char 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}\"") end when :key_oid then @@ -119,7 +119,7 @@ module Gitlab end when :value_normal_escape then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_normal_escape_hex hex_buffer = char when /\s/ then @@ -131,7 +131,7 @@ module Gitlab end when :value_normal_escape_hex then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_normal value << "#{hex_buffer}#{char}".to_i(16).chr else raise(MalformedDnError, "Invalid escaped hex code \"\\#{hex_buffer}#{char}\"") @@ -155,7 +155,7 @@ module Gitlab end when :value_quoted_escape then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_quoted_escape_hex hex_buffer = char else @@ -164,14 +164,14 @@ module Gitlab end when :value_quoted_escape_hex then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_quoted 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}\"") end when :value_hexstring then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_hexstring_hex value << char when ' ' then state = :value_end @@ -184,7 +184,7 @@ module Gitlab end when :value_hexstring_hex then case char - when '0'..'9', 'a'..'f' then + when '0'..'9', 'a'..'f', 'A'..'F' then state = :value_hexstring value << char else raise(MalformedDnError, "Expected the second character of a hex pair, but got \"#{char}\"") @@ -227,7 +227,7 @@ module Gitlab ## # Return the DN as an escaped and normalized string. def to_s_normalized - self.class.new(*to_a).to_s + self.class.new(*to_a).to_s.downcase end # https://tools.ietf.org/html/rfc4514 section 2.4 lists these exceptions diff --git a/spec/lib/gitlab/ldap/dn_spec.rb b/spec/lib/gitlab/ldap/dn_spec.rb index f923c67d922..67a561854aa 100644 --- a/spec/lib/gitlab/ldap/dn_spec.rb +++ b/spec/lib/gitlab/ldap/dn_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::LDAP::DN do using RSpec::Parameterized::TableSyntax - describe '#initialize' do + describe '#to_s_normalized' do subject { described_class.new(given).to_s_normalized } # Regarding the telephoneNumber test: @@ -93,7 +93,7 @@ describe Gitlab::LDAP::DN do let(:given) { '0.9.2342.19200300.100.1.25=#aaXaaa' } 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 @@ -101,7 +101,7 @@ describe Gitlab::LDAP::DN do let(:given) { '0.9.2342.19200300.100.1.25=#aaaYaa' } 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 @@ -109,7 +109,7 @@ describe Gitlab::LDAP::DN do let(:given) { 'uid="Sebasti\\cX\\a1n"' } 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 -- cgit v1.2.1