The Wayback Machine - https://web.archive.org/web/20220309174922/https://github.com/jwt/ruby-jwt/pull/221
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reported codesmells #221

Merged
merged 12 commits into from Sep 2, 2017
Merged

Fix reported codesmells #221

merged 12 commits into from Sep 2, 2017

Conversation

excpt
Copy link
Member

@excpt excpt commented Aug 24, 2017

No description provided.

@excpt excpt added this to the Version 2.0.0 milestone Aug 24, 2017
@excpt excpt self-assigned this Aug 24, 2017
excpt added 4 commits Aug 24, 2017
ECDSA_ALGORITHMS = %w(ES256 ES384 ES512).freeze
HMAC_ALGORITHMS = %w[HS256 HS512256 HS384 HS512].freeze
RSA_ALGORITHMS = %w[RS256 RS384 RS512].freeze
ECDSA_ALGORITHMS = %w[ES256 ES384 ES512].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%w-literals should be delimited by ( and ).

RSA_ALGORITHMS = %w(RS256 RS384 RS512).freeze
ECDSA_ALGORITHMS = %w(ES256 ES384 ES512).freeze
HMAC_ALGORITHMS = %w[HS256 HS512256 HS384 HS512].freeze
RSA_ALGORITHMS = %w[RS256 RS384 RS512].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%w-literals should be delimited by ( and ).

HMAC_ALGORITHMS = %w(HS256 HS512256 HS384 HS512).freeze
RSA_ALGORITHMS = %w(RS256 RS384 RS512).freeze
ECDSA_ALGORITHMS = %w(ES256 ES384 ES512).freeze
HMAC_ALGORITHMS = %w[HS256 HS512256 HS384 HS512].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%w-literals should be delimited by ( and ).

require 'jwt/error'

module JWT
# JWT verify methods
class Verify
class << self
%w(verify_aud verify_expiration verify_iat verify_iss verify_jti verify_not_before verify_sub).each do |method_name|
%w[verify_aud verify_expiration verify_iat verify_iss verify_jti verify_not_before verify_sub].each do |method_name|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%w-literals should be delimited by ( and ).

@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = %w(lib)
spec.require_paths = %w[lib]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%w-literals should be delimited by ( and ).

else
raise JWT::VerificationError, 'Algorithm not supported'
end
verify_hmac(algo, key, signing_input, signature)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -9) spaces for indentation.

SecurityUtils.verify_rsa(algo, key, signing_input, signature)
elsif ECDSA_ALGORITHMS.include?(algo)
verify_ecdsa(algo, key, signing_input, signature)
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align else with if.

verify_hmac(algo, key, signing_input, signature)
elsif RSA_ALGORITHMS.include?(algo)
SecurityUtils.verify_rsa(algo, key, signing_input, signature)
elsif ECDSA_ALGORITHMS.include?(algo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align elsif with if.

raise JWT::VerificationError, 'Algorithm not supported'
end
verify_hmac(algo, key, signing_input, signature)
elsif RSA_ALGORITHMS.include?(algo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align elsif with if.

verify_ecdsa(algo, key, signing_input, signature)
else
raise JWT::VerificationError, 'Algorithm not supported'
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 48, 6 is not aligned with if at 40, 17.

#
# @see: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/security_utils.rb
module SecurityUtils

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

iss = @payload['iss']

return if Array(options_iss).map(&:to_s).include?(iss.to_s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

raise(JWT::InvalidIssuerError, "Invalid issuer. Expected #{options_iss}, received #{@payload['iss'] || '<none>'}")

iss = @payload['iss']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

else
yield(header)
end
yield(header, payload)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -4) spaces for indentation.

yield(header)
end
yield(header, payload)
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align else with if.

yield(header, payload)
else
yield(header)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 56, 6 is not aligned with if at 52, 12.

OpenSSL::ASN1.decode(signature).value.map { |value| value.value.to_s(2).rjust(byte_size, "\x00") }.join
end

def raw_to_asn1(signature, private_key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JWT::SecurityUtils#raw_to_asn1 has the name 'raw_to_asn1'

Read more about it here.

@sourcelevel-bot
Copy link

@sourcelevel-bot sourcelevel-bot bot commented Sep 2, 2017

Ebert has finished reviewing this Pull Request and has found:

  • 17 possible new issues (including those that may have been commented here).
  • 15 fixed issues! 🎉

But beware that this branch is 2 commits behind the jwt:master branch, and a review of an up to date branch would produce more accurate results.

You can see more details about this review at https://ebertapp.io/github/jwt/ruby-jwt/pulls/221.

Remove parameters as they are already instance vars.
@excpt excpt merged commit 59ff654 into jwt:master Sep 2, 2017
2 of 4 checks passed
@excpt excpt deleted the fix-reported-codesmells branch Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant