diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-09-21 09:42:16 -0700 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-10-07 10:28:13 -0700 |
commit | 14ed20d68af935da1a236d010978939a8085aa59 (patch) | |
tree | 8d69e91db7274777c82509cd78055106ce10ea2b /lib | |
parent | 45ab20dca91024602e7c73814e8ff89df2000189 (diff) | |
download | gitlab-ce-14ed20d68af935da1a236d010978939a8085aa59.tar.gz |
Resolve Rubocop offenses
Disabling some for now since this is based on `Net::LDAP::DN`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ldap/dn.rb | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/gitlab/ldap/dn.rb b/lib/gitlab/ldap/dn.rb index 557b5af118e..05252c75624 100644 --- a/lib/gitlab/ldap/dn.rb +++ b/lib/gitlab/ldap/dn.rb @@ -37,16 +37,16 @@ module Gitlab buffer = StringIO.new args.each_index do |index| - buffer << "=" if index % 2 == 1 - buffer << "," if index % 2 == 0 && index != 0 + buffer << "=" if index.odd? + buffer << "," if index.even? && index != 0 arg = args[index].downcase - if index < args.length - 1 || index % 2 == 1 - buffer << self.class.escape(arg) - else - buffer << arg - end + buffer << if index < args.length - 1 || index.odd? + self.class.escape(arg) + else + arg + end end @dn = buffer.string @@ -55,6 +55,9 @@ module Gitlab ## # Parse a DN into key value pairs using ASN from # http://tools.ietf.org/html/rfc2253 section 3. + # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/PerceivedComplexity def each_pair state = :key key = StringIO.new @@ -98,7 +101,7 @@ module Gitlab state = :key yield key.string.strip, value.string.rstrip key = StringIO.new - value = StringIO.new; + value = StringIO.new else state = :value_normal value << char @@ -110,7 +113,7 @@ module Gitlab state = :key yield key.string.strip, value.string.rstrip key = StringIO.new - value = StringIO.new; + value = StringIO.new when '+' then raise(UnsupportedDnFormatError, "Multivalued RDNs are not supported") else value << char end @@ -119,8 +122,12 @@ module Gitlab when '0'..'9', 'a'..'f' then state = :value_normal_escape_hex hex_buffer = char - when /\s/ then state = :value_normal_escape_whitespace; value << char - else state = :value_normal; value << char + when /\s/ then + state = :value_normal_escape_whitespace + value << char + else + state = :value_normal + value << char end when :value_normal_escape_hex then case char @@ -136,7 +143,7 @@ module Gitlab state = :key yield key.string.strip, value.string # Don't strip trailing escaped space! key = StringIO.new - value = StringIO.new; + value = StringIO.new when '+' then raise(UnsupportedDnFormatError, "Multivalued RDNs are not supported") else value << char end @@ -152,7 +159,7 @@ module Gitlab state = :value_quoted_escape_hex hex_buffer = char else - state = :value_quoted; + state = :value_quoted value << char end when :value_quoted_escape_hex then @@ -172,7 +179,7 @@ module Gitlab state = :key yield key.string.strip, value.string.rstrip key = StringIO.new - value = StringIO.new; + value = StringIO.new else raise(MalformedDnError, "Expected the first character of a hex pair, but got \"#{char}\"") end when :value_hexstring_hex then @@ -189,7 +196,7 @@ module Gitlab state = :key yield key.string.strip, value.string.rstrip key = StringIO.new - value = StringIO.new; + value = StringIO.new else raise(MalformedDnError, "Expected the end of an attribute value, but got \"#{char}\"") end else raise "Fell out of state machine" @@ -228,13 +235,13 @@ module Gitlab # using a single backslash ('\') as escape. The space character is left # out here because in a "normalized" string, spaces should only be escaped # if necessary (i.e. leading or trailing space). - NORMAL_ESCAPES = [',', '+', '"', '\\', '<', '>', ';', '='] + NORMAL_ESCAPES = [',', '+', '"', '\\', '<', '>', ';', '='].freeze # The following must be represented as escaped hex HEX_ESCAPES = { "\n" => '\0a', "\r" => '\0d' - } + }.freeze # Compiled character class regexp using the keys from the above hash, and # checking for a space or # at the start, or space at the end, of the @@ -257,6 +264,7 @@ module Gitlab ## # Proxy all other requests to the string object, because a DN is mainly # used within the library as a string + # rubocop:disable GitlabSecurity/PublicSend def method_missing(method, *args, &block) @dn.send(method, *args, &block) end |