appbot/kms_rails

View on GitHub
lib/kms_rails/kms_client_mock.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

KmsRails::KmsClientMock#generate_data_key is controlled by argument 'key_spec'
Open

      raise RuntimeError, 'Unsupported key_spec in test mode' unless key_spec == 'AES_256'
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

KmsRails::KmsClientMock#decrypt is controlled by argument 'encryption_context'
Open

      raise ::Aws::KMS::Errors::InvalidCiphertextException.new(nil, nil) unless decoded_context == encryption_context
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

KmsRails::KmsClientMock has no descriptive comment
Open

  class KmsClientMock
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

KmsRails::KmsClientMock#decrypt calls 'raise ::Aws::KMS::Errors::InvalidCiphertextException.new(nil, nil)' 2 times
Open

      raise ::Aws::KMS::Errors::InvalidCiphertextException.new(nil, nil) unless decoded_context == encryption_context

      ::Aws::KMS::Types::DecryptResponse.new(
        key_id: key_id,
        plaintext: plaintext,
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

Surrounding space missing for operator /.
Open

      plaintext = SecureRandom.random_bytes(256/8)
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

Checks that operators have space around them, except for ** which should not have surrounding space.

Example:

# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b

# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b

Line is too long. [117/80]
Open

      raise ::Aws::KMS::Errors::InvalidCiphertextException.new(nil, nil) unless decoded_context == encryption_context
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      "#<Aws::KMS::Client (mocked)>"
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Line is too long. [84/80]
Open

        ciphertext_blob: [key_id, encryption_context, plaintext].to_msgpack.reverse,
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

Redundant RuntimeError argument can be removed.
Open

      raise RuntimeError, 'Unsupported key_spec in test mode' unless key_spec == 'AES_256'
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

This cop checks for RuntimeError as the argument of raise/fail.

It checks for code like this:

Example:

# Bad
raise RuntimeError, 'message'

# Bad
raise RuntimeError.new('message')

# Good
raise 'message'

Line is too long. [90/80]
Open

      raise RuntimeError, 'Unsupported key_spec in test mode' unless key_spec == 'AES_256'
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

Missing top-level class documentation comment.
Open

  class KmsClientMock
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Avoid comma after the last parameter of a method call.
Open

        ciphertext_blob: [key_id, encryption_context, plaintext].to_msgpack.reverse,
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

This cop checks for trailing comma in argument lists.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
method(1, 2,)

# good
method(
  1, 2,
  3,
)

# good
method(
  1,
  2,
)

Example: EnforcedStyleForMultiline: comma

# bad
method(1, 2,)

# good
method(
  1,
  2,
)

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
method(1, 2,)

# good
method(
  1,
  2
)

Avoid comma after the last parameter of a method call.
Open

        plaintext: plaintext,
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

This cop checks for trailing comma in argument lists.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
method(1, 2,)

# good
method(
  1, 2,
  3,
)

# good
method(
  1,
  2,
)

Example: EnforcedStyleForMultiline: comma

# bad
method(1, 2,)

# good
method(
  1,
  2,
)

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
method(1, 2,)

# good
method(
  1,
  2
)

Line is too long. [86/80]
Open

      key_id, decoded_context, plaintext = MessagePack.unpack(ciphertext_blob.reverse)
Severity: Minor
Found in lib/kms_rails/kms_client_mock.rb by rubocop

There are no issues that match your filters.

Category
Status