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 #8035] Fix a false positive for Lint/DeprecatedOpenSSLConstant #8038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
* [#8012](https://github.com/rubocop-hq/rubocop/issues/8012): Fix an incorrect autocorrect for `Lint/DeprecatedOpenSSLConstant` when deprecated OpenSSL constant is used in a block. ([@koic][])
* [#8017](https://github.com/rubocop-hq/rubocop/pull/8017): Fix a false positive for `Lint/SuppressedException` when empty rescue with comment in `def`. ([@koic][])
* [#7990](https://github.com/rubocop-hq/rubocop/issues/7990): Fix resolving `inherit_gem` in remote configs. ([@CvX][])
* [#8035](https://github.com/rubocop-hq/rubocop/issues/8035): Fix the following false positive for `Lint/DeprecatedOpenSSLConstant` when using double quoted string argument. ([@koic][])

## 0.84.0 (2020-05-21)

Expand Down
6 changes: 5 additions & 1 deletion lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb
Expand Up @@ -106,7 +106,11 @@ def algorithm_name(node)
end

def sanitize_arguments(arguments)
arguments.flat_map { |arg| arg.source.tr(":'", '').split('-') }
arguments.flat_map do |arg|
argument = arg.str_type? ? arg.value : arg.source

argument.tr(":'", '').split('-')
end
end

def replacement_args(node)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/lint/deprecated_open_ssl_constant_spec.rb
Expand Up @@ -27,6 +27,17 @@
RUBY
end

it 'registers an offense with cipher constant and double quoted string argument and corrects' do
expect_offense(<<~RUBY)
OpenSSL::Cipher::AES128.new("GCM")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `OpenSSL::Cipher.new('AES-128-GCM')` instead of `OpenSSL::Cipher::AES128.new("GCM")`.
RUBY

expect_correction(<<~RUBY)
OpenSSL::Cipher.new('AES-128-GCM')
RUBY
end

it 'registers an offense with AES + blocksize constant and mode argument and corrects' do
expect_offense(<<~RUBY)
OpenSSL::Cipher::AES128.new(:GCM)
Expand Down