diff options
| author | mo khan <mo.khan@gmail.com> | 2021-01-30 21:37:05 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2021-01-30 21:37:05 -0700 |
| commit | 9d46474008bcf7945a8c4a479852ccfd3d6fa811 (patch) | |
| tree | cfeeb0065e0bc25897f117d78af80f8ced148742 | |
| parent | 2bdb4a1b341160c52a39cc0d339f6f6b4514ad08 (diff) | |
style: fix linter errorsv0.5.0
| -rw-r--r-- | .rubocop.yml | 17 | ||||
| -rw-r--r-- | lib/xml/kit/certificate.rb | 2 | ||||
| -rw-r--r-- | lib/xml/kit/decryption.rb | 10 | ||||
| -rw-r--r-- | lib/xml/kit/templatable.rb | 4 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 2 | ||||
| -rw-r--r-- | spec/xml/kit/crypto/symmetric_cipher_spec.rb | 10 | ||||
| -rw-r--r-- | spec/xml/kit/signatures_spec.rb | 1 | ||||
| -rw-r--r-- | spec/xml/kit/soap_spec.rb | 1 |
8 files changed, 27 insertions, 20 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 2580860..3d38cdb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,7 +9,7 @@ AllCops: - 'spec/fixtures/**/*' - 'tmp/**/*' - 'vendor/**/*' - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Layout/ClassStructure: Enabled: true @@ -30,10 +30,10 @@ Layout/ClassStructure: Layout/EndOfLine: EnforcedStyle: lf -Layout/IndentFirstArrayElement: +Layout/FirstArrayElementIndentation: EnforcedStyle: consistent -Layout/IndentHeredoc: +Layout/HeredocIndentation: EnforcedStyle: active_support Layout/MultilineOperationIndentation: @@ -47,6 +47,10 @@ Lint/InterpolationCheck: Exclude: - 'spec/**/*.rb' +Metrics/AbcSize: + Exclude: + - 'lib/xml/kit/self_signed_certificate.rb' + Metrics/BlockLength: Exclude: - '**/**/*.builder' @@ -87,9 +91,16 @@ Style/TrailingCommaInHashLiteral: RSpec/ExampleLength: Max: 80 +RSpec/LeakyConstantDeclaration: + Exclude: + - 'spec/xml/kit/templatable_spec.rb' + RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false + RSpec/NamedSubject: Enabled: false diff --git a/lib/xml/kit/certificate.rb b/lib/xml/kit/certificate.rb index 46df7d6..559979f 100644 --- a/lib/xml/kit/certificate.rb +++ b/lib/xml/kit/certificate.rb @@ -7,9 +7,7 @@ module Xml # {include:file:spec/xml/kit/certificate_spec.rb} class Certificate include Templatable - # rubocop:disable Metrics/LineLength BASE64_FORMAT = %r(\A([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z).freeze - # rubocop:enable Metrics/LineLength BEGIN_CERT = /-----BEGIN CERTIFICATE-----/.freeze END_CERT = /-----END CERTIFICATE-----/.freeze # The use can be `:signing` or `:encryption`. Use `nil` for both. diff --git a/lib/xml/kit/decryption.rb b/lib/xml/kit/decryption.rb index 98535bc..0a9aa29 100644 --- a/lib/xml/kit/decryption.rb +++ b/lib/xml/kit/decryption.rb @@ -56,12 +56,10 @@ module Xml def symmetric_key_from(encrypted_key, attempts = private_keys.count) cipher, algorithm = cipher_and_algorithm_from(encrypted_key) private_keys.each do |private_key| - begin - attempts -= 1 - return to_plaintext(cipher, private_key, algorithm) - rescue OpenSSL::PKey::RSAError - raise if attempts.zero? - end + attempts -= 1 + return to_plaintext(cipher, private_key, algorithm) + rescue OpenSSL::PKey::RSAError + raise if attempts.zero? end raise DecryptionError, private_keys end diff --git a/lib/xml/kit/templatable.rb b/lib/xml/kit/templatable.rb index 0f53325..3fd2daa 100644 --- a/lib/xml/kit/templatable.rb +++ b/lib/xml/kit/templatable.rb @@ -76,9 +76,7 @@ module Xml # @abstract # @since 0.3.0 def asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM) - unless encryption_certificate - raise Xml::Kit::Error, 'encryption_certificate is not specified.' - end + raise Xml::Kit::Error, 'encryption_certificate is not specified.' unless encryption_certificate @asymmetric_cipher ||= Crypto.cipher_for( algorithm, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b0023c4..aeba20b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,7 @@ require 'tempfile' Xml::Kit.logger.level = Logger::FATAL -Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].each { |f| require f } +Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].sort.each { |f| require f } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' diff --git a/spec/xml/kit/crypto/symmetric_cipher_spec.rb b/spec/xml/kit/crypto/symmetric_cipher_spec.rb index 0bf72be..534bec8 100644 --- a/spec/xml/kit/crypto/symmetric_cipher_spec.rb +++ b/spec/xml/kit/crypto/symmetric_cipher_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do - [ - 'aes128-cbc', - 'aes192-cbc', - 'aes256-cbc', - 'tripledes-cbc', + %w[ + aes128-cbc + aes192-cbc + aes256-cbc + tripledes-cbc ].each do |algorithm| describe algorithm do let(:xml_algorithm) { "#{::Xml::Kit::Namespaces::XMLENC}#{algorithm}" } diff --git a/spec/xml/kit/signatures_spec.rb b/spec/xml/kit/signatures_spec.rb index ee170b0..efcfb06 100644 --- a/spec/xml/kit/signatures_spec.rb +++ b/spec/xml/kit/signatures_spec.rb @@ -27,6 +27,7 @@ RSpec.describe ::Xml::Kit::Signatures do specify { expect(signature['SignedInfo']['Reference']['DigestValue']).to be_present } specify { expect(signature['SignatureValue']).to be_present } specify { expect(OpenSSL::X509::Certificate.new(Base64.decode64(signature['KeyInfo']['X509Data']['X509Certificate']))).to be_present } + specify do expect(signature['SignedInfo']['Reference']['Transforms']['Transform']).to match_array([ { 'Algorithm' => 'http://www.w3.org/2000/09/xmldsig#enveloped-signature' }, diff --git a/spec/xml/kit/soap_spec.rb b/spec/xml/kit/soap_spec.rb index ebc2d01..a38e90f 100644 --- a/spec/xml/kit/soap_spec.rb +++ b/spec/xml/kit/soap_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Soap do specify { expect(result['Envelope']).to be_present } specify { expect(result['Envelope']['Header']).to be_present } + specify do cipher_value = result['Envelope']['Header']['Security']['EncryptedKey']['CipherData']['CipherValue'] symmetric_key = key_pair.private_key.private_decrypt(Base64.decode64(cipher_value)) |
