inline_encryption 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.pre-commit-config.yaml +21 -0
  3. data/.rubocop.yml +12 -0
  4. data/.rubocop_todo.yml +20 -0
  5. data/.tool-versions +2 -0
  6. data/.travis.yml +1 -1
  7. data/Gemfile +6 -4
  8. data/Guardfile +5 -4
  9. data/Rakefile +5 -3
  10. data/bin/inline_encryption +2 -0
  11. data/inline_encryption.gemspec +9 -10
  12. data/lib/inline_encryption/base.rb +16 -22
  13. data/lib/inline_encryption/cli.rb +6 -11
  14. data/lib/inline_encryption/config.rb +21 -15
  15. data/lib/inline_encryption/errors.rb +3 -3
  16. data/lib/inline_encryption/version.rb +3 -1
  17. data/lib/inline_encryption.rb +3 -2
  18. data/spec/inline_encryption/base_spec.rb +21 -33
  19. data/spec/inline_encryption/cli_spec.rb +5 -10
  20. data/spec/inline_encryption/config_spec.rb +11 -14
  21. data/spec/inline_encryption_spec.rb +3 -3
  22. data/spec/spec_helper.rb +4 -2
  23. metadata +9 -58
  24. data/test_app/.gitignore +0 -16
  25. data/test_app/Gemfile +0 -6
  26. data/test_app/README.rdoc +0 -28
  27. data/test_app/Rakefile +0 -6
  28. data/test_app/app/assets/images/.keep +0 -0
  29. data/test_app/app/assets/javascripts/application.js +0 -16
  30. data/test_app/app/assets/stylesheets/application.css +0 -13
  31. data/test_app/app/controllers/application_controller.rb +0 -5
  32. data/test_app/app/controllers/concerns/.keep +0 -0
  33. data/test_app/app/helpers/application_helper.rb +0 -2
  34. data/test_app/app/mailers/.keep +0 -0
  35. data/test_app/app/models/.keep +0 -0
  36. data/test_app/app/models/concerns/.keep +0 -0
  37. data/test_app/app/views/layouts/application.html.erb +0 -14
  38. data/test_app/bin/bundle +0 -3
  39. data/test_app/bin/rails +0 -4
  40. data/test_app/bin/rake +0 -4
  41. data/test_app/config/application.rb +0 -23
  42. data/test_app/config/boot.rb +0 -4
  43. data/test_app/config/database.yml +0 -25
  44. data/test_app/config/environment.rb +0 -5
  45. data/test_app/config/environments/development.rb +0 -29
  46. data/test_app/config/environments/production.rb +0 -80
  47. data/test_app/config/environments/test.rb +0 -36
  48. data/test_app/config/initializers/backtrace_silencers.rb +0 -7
  49. data/test_app/config/initializers/filter_parameter_logging.rb +0 -4
  50. data/test_app/config/initializers/inflections.rb +0 -16
  51. data/test_app/config/initializers/mime_types.rb +0 -5
  52. data/test_app/config/initializers/secret_token.rb +0 -12
  53. data/test_app/config/initializers/session_store.rb +0 -3
  54. data/test_app/config/initializers/wrap_parameters.rb +0 -14
  55. data/test_app/config/locales/en.yml +0 -23
  56. data/test_app/config/routes.rb +0 -56
  57. data/test_app/config.ru +0 -4
  58. data/test_app/db/seeds.rb +0 -7
  59. data/test_app/lib/assets/.keep +0 -0
  60. data/test_app/lib/tasks/.keep +0 -0
  61. data/test_app/log/.keep +0 -0
  62. data/test_app/public/404.html +0 -58
  63. data/test_app/public/422.html +0 -58
  64. data/test_app/public/500.html +0 -57
  65. data/test_app/public/favicon.ico +0 -0
  66. data/test_app/public/robots.txt +0 -5
  67. data/test_app/test/controllers/.keep +0 -0
  68. data/test_app/test/fixtures/.keep +0 -0
  69. data/test_app/test/helpers/.keep +0 -0
  70. data/test_app/test/integration/.keep +0 -0
  71. data/test_app/test/mailers/.keep +0 -0
  72. data/test_app/test/models/.keep +0 -0
  73. data/test_app/test/test_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 16d2dbac242627fd934085109d15186d5ce6467c
4
- data.tar.gz: ebb1094e6923741890f66e725f5dab491e4c9cda
2
+ SHA256:
3
+ metadata.gz: 8579ebc960ba6c9f084553a3f948c18aa15013c5ceda7d4ff9d84191b386defa
4
+ data.tar.gz: cbb00c55dadcfba3f757e90222aa04e5779037afd9fee2b0fddaf35937c06983
5
5
  SHA512:
6
- metadata.gz: a1534f625ef45b19cc5b188169c9fd76ba74005fef25ca9ef97f26a37e9156e7711a185aa66eb08c5fb50f380acbd78accc43ef178d904030be058665a45db76
7
- data.tar.gz: bc230d72d58413c72c528c6ce5245181dc60a088c0cb4386dd522162cb9ca1f07523e26623de9bd8176ce34c60fd55654ec57c4921006cda85ab41412283432f
6
+ metadata.gz: 9a4d667b844ce6bdd816022d4abd763a6488d89cec23e9e32680748e6f2a9eb6e5d489ae419c6a9eb5f1382ba7579e7997334aa8581fd144312293a23aea0f5f
7
+ data.tar.gz: 1adff188699044cf0e9facff5393e96a47f20393335b7ee45e5de761fa438ced3d8b3b5865d9b87755c8b5137f380b9771d08732d6ad28cac9201e54dcae6c95
@@ -0,0 +1,21 @@
1
+ repos:
2
+ - hooks:
3
+ - id: check-added-large-files
4
+ - id: check-merge-conflict
5
+ - id: check-yaml
6
+ - id: detect-aws-credentials
7
+ - id: detect-private-key
8
+ - id: end-of-file-fixer
9
+ - id: trailing-whitespace
10
+ repo: https://github.com/pre-commit/pre-commit-hooks
11
+ rev: v4.1.0
12
+ - hooks:
13
+ - id: commitizen
14
+ stages:
15
+ - commit-msg
16
+ repo: https://github.com/commitizen-tools/commitizen
17
+ rev: v2.20.3
18
+ - hooks:
19
+ - id: rubocop
20
+ repo: https://github.com/jumanjihouse/pre-commit-hooks
21
+ rev: 2.1.5
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
4
+ # configuration file. It makes it possible to enable/disable
5
+ # certain cops (checks) and to alter their behavior if they accept
6
+ # any parameters. The file can be placed either in your home
7
+ # directory or in some project directory.
8
+ #
9
+ # RuboCop will start looking for the configuration file in the directory
10
+ # where the inspected file is and continue its way up to the root directory.
11
+ #
12
+ # See https://docs.rubocop.org/rubocop/configuration
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-01-11 17:25:54 UTC using RuboCop version 1.24.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'inline_encryption.gemspec'
15
+
16
+ # Offense count: 4
17
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
18
+ # IgnoredMethods: refine
19
+ Metrics/BlockLength:
20
+ Max: 63
data/.tool-versions ADDED
@@ -0,0 +1,2 @@
1
+ ruby 2.7.4
2
+ pre-commit 2.15.0
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - '2.2.10'
4
3
  - '2.3.8'
5
4
  - '2.4.4'
6
5
  - '2.5.3'
6
+ - '2.7.4'
7
7
  script: bundle exec rspec spec
8
8
  bundler_args: --without development debugger
data/Gemfile CHANGED
@@ -1,20 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem 'bundler', '~> 1.7'
7
+ gem 'bundler', '>= 2.2.33'
6
8
  gem 'hashie'
7
9
  gem 'i18n'
8
10
  gem 'thor'
9
11
 
10
12
  group :debugger do
11
- gem 'byebug'
13
+ gem 'byebug', '~> 11'
12
14
  end
13
15
 
14
16
  group :development do
15
17
  gem 'guard'
16
18
  gem 'guard-rspec'
17
- end
19
+ gem 'rubocop'
20
+ end
18
21
 
19
22
  group :development, :test do
20
23
  gem 'rake'
@@ -23,4 +26,3 @@ group :development, :test do
23
26
  gem 'simplecov', require: false
24
27
  gem 'yard'
25
28
  end
26
-
data/Guardfile CHANGED
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
4
6
  guard 'rspec', all_after_pass: true, failed_mode: :focus, all_on_start: true, cmd: 'rspec' do
5
7
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}){ |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb'){ "spec" }
8
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
9
11
  end
10
-
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # -*- mode: ruby -*-
3
5
  require 'bundler'
4
6
  Bundler.setup
@@ -1,5 +1,7 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ lib = File.expand_path('lib', __dir__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'inline_encryption/version'
5
7
 
@@ -8,22 +10,19 @@ Gem::Specification.new do |spec|
8
10
  spec.version = InlineEncryption::VERSION
9
11
  spec.authors = ['rubyisbeautiful']
10
12
  spec.email = 'bcptaylor+github@gmail.com'
11
- spec.description = %q{ A simple encryption tool based on common convention }
12
- spec.summary = %q{ A simple encryption tool based on common convention and designed as a drop in for Stringish things }
13
- spec.homepage = 'http://github.com/rubyisbeautiful/inline_encryption'
13
+ spec.description = ' A simple encryption tool based on common convention '
14
+ spec.summary = ' A drop-in simple encryption tool for stringish things '
15
+ spec.homepage = 'https://github.com/rubyisbeautiful/inline_encryption'
14
16
  spec.license = 'MIT'
15
17
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ['lib']
20
21
  spec.required_ruby_version = '>= 2.1.5'
21
22
 
22
- spec.executables = ['inline_encryption']
23
+ spec.executables = ['inline_encryption']
23
24
 
24
25
  spec.add_runtime_dependency 'hashie'
25
26
  spec.add_runtime_dependency 'i18n'
26
27
  spec.add_runtime_dependency 'thor'
27
-
28
-
29
28
  end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
 
3
5
  module InlineEncryption
4
-
6
+ # Base module including core functionality
5
7
  module Base
6
-
7
-
8
8
  # @param [String] data encryption target
9
9
  # @return [String] encrypted target
10
10
  # @raise [EncryptionFailureError] couldn't encrypt the target
@@ -13,63 +13,57 @@ module InlineEncryption
13
13
 
14
14
  begin
15
15
  encrypted = config.real_key.public_encrypt(data)
16
- converted = Base64.encode64(encrypted)
17
- rescue => e
16
+ Base64.encode64(encrypted)
17
+ rescue StandardError
18
18
  err = EncryptionFailureError.exception I18n.t('target', data: data)
19
19
  raise err
20
20
  end
21
21
  end
22
22
 
23
-
24
23
  # @param [String] data encryption target
25
24
  # @return [String] encrypted target, or fail_text on error (default data)
26
- def encrypt(data, fail_text=nil)
25
+ def encrypt(data, fail_text = nil)
27
26
  config.check_required_variables
28
27
 
29
28
  begin
30
29
  encrypt!(data)
31
- rescue EncryptionFailureError => e
32
- return fail_text.nil? ? data : fail_text.to_s
30
+ rescue EncryptionFailureError
31
+ fail_text.nil? ? data : fail_text.to_s
33
32
  end
34
33
  end
35
34
 
36
-
37
35
  # @param [String] data decryption target
38
36
  # @return [String] decrypted target
39
37
  # @raise [DecryptionFailureError] couldn't decrypt the target
40
38
  def decrypt!(data)
41
39
  config.check_required_variables
42
- raise MisconfigurationError.new(I18n.t('error.pub_key_decrypt')) unless config.real_key.private?
40
+ raise MisconfigurationError, I18n.t('error.pub_key_decrypt') unless config.real_key.private?
43
41
 
44
42
  begin
45
43
  converted = Base64.decode64(data)
46
- decrypted = config.real_key.private_decrypt(converted)
47
- rescue => e
48
- err = DecryptionFailureError.exception I18n.t('encrypted', data)
44
+ config.real_key.private_decrypt(converted)
45
+ rescue StandardError
46
+ err = DecryptionFailureError.exception I18n.t('encrypted', data: data)
49
47
  raise err
50
48
  end
51
49
  end
52
50
 
53
-
54
51
  # @param [String] data decryption target
55
52
  # @param [String] fail_text text to be returned in the case of a decryption failure
56
53
  # @return [String] decrypted target
57
- def decrypt(data, fail_text=nil)
54
+ def decrypt(data, fail_text = nil)
58
55
  config.check_required_variables
59
56
 
60
57
  begin
61
58
  decrypt!(data)
62
- rescue DecryptionFailureError => e
63
- return fail_text.nil? ? data : fail_text.to_s
59
+ rescue DecryptionFailureError
60
+ fail_text.nil? ? data : fail_text.to_s
64
61
  end
65
62
  end
66
63
 
67
-
68
64
  # @return [InlineEncryption::Config] the configuration instance
69
65
  def config
70
66
  @config ||= Config.new
71
67
  end
72
-
73
68
  end
74
-
75
- end
69
+ end
@@ -1,31 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
 
3
5
  module InlineEncryption
4
-
6
+ # CLI class for using on commandline
5
7
  class CLI < Thor
6
-
7
- def initialize(args=[], opts=[], config={})
8
+ def initialize(args = [], opts = [], config = {})
8
9
  super(args, opts, config)
9
10
  end
10
11
 
11
-
12
12
  desc 'encrypt [DATA]', 'encrypt stuff'
13
- class_option :require, :aliases => ['-r'], :type => :string
13
+ class_option :require, aliases: ['-r'], type: :string
14
14
  def encrypt(data)
15
15
  load_environment(options[:require]) if options[:require]
16
16
 
17
17
  puts InlineEncryption.encrypt(data)
18
18
  end
19
19
 
20
-
21
-
22
20
  protected
23
21
 
24
-
25
22
  def load_environment(file)
26
23
  require File.expand_path(file)
27
24
  end
28
-
29
25
  end
30
-
31
- end
26
+ end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hashie/extensions/ruby_version_check'
1
4
  require 'hashie/extensions/indifferent_access'
2
5
  require 'hashie/extensions/method_access'
3
6
  require 'hashie/extensions/dash/indifferent_access'
@@ -5,7 +8,6 @@ require 'hashie/dash'
5
8
  require 'openssl'
6
9
 
7
10
  module InlineEncryption
8
-
9
11
  # known configuration variables
10
12
  # key - a String containing the private key, a filename pointing to the private key, or an OpenSSL::PKey::RSA
11
13
  class Config < Hash
@@ -15,26 +17,30 @@ module InlineEncryption
15
17
  # checks required, currently only the 'key'
16
18
  # @raises [InlineEncryption::MissingRequiredVariableError] raise on a missing variable
17
19
  def check_required_variables
18
- raise MissingRequiredVariableError.new(I18n.t('error.missing_key')) unless self.has_key?(:key)
20
+ raise MissingRequiredVariableError, I18n.t('error.missing_key') unless key?(:key)
19
21
  end
20
22
 
21
-
22
23
  # @return [OpenSSL::PKey::RSA] the OpenSSL key instance
23
24
  def real_key
24
25
  case self[:key]
25
- when NilClass
26
- nil
27
- when String
28
- if File.exists?(self[:key])
29
- OpenSSL::PKey::RSA.new(File.read(self[:key]))
30
- else
31
- OpenSSL::PKey::RSA.new(self[:key])
32
- end
33
- when OpenSSL::PKey::RSA
34
- self[:key]
26
+ when NilClass
27
+ nil
28
+ when String
29
+ load_or_use_key(self[:key])
30
+ when OpenSSL::PKey::RSA
31
+ self[:key]
35
32
  end
36
33
  end
37
- end
38
34
 
35
+ private
39
36
 
40
- end
37
+ # @return OpenSSL::PKey::RSA
38
+ def load_or_use_key(str)
39
+ if File.exist?(str)
40
+ OpenSSL::PKey::RSA.new(File.read(str))
41
+ else
42
+ OpenSSL::PKey::RSA.new(str)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,8 +1,8 @@
1
- module InlineEncryption
1
+ # frozen_string_literal: true
2
2
 
3
+ module InlineEncryption
3
4
  class MissingRequiredVariableError < StandardError; end
4
5
  class DecryptionFailureError < StandardError; end
5
6
  class EncryptionFailureError < StandardError; end
6
7
  class MisconfigurationError < StandardError; end
7
-
8
- end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InlineEncryption
2
- VERSION = '2.0.1'
4
+ VERSION = '2.1.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'i18n'
2
4
  require 'base64'
3
5
  require 'inline_encryption/version'
@@ -5,6 +7,7 @@ require 'inline_encryption/config'
5
7
  require 'inline_encryption/base'
6
8
  require 'inline_encryption/errors'
7
9
 
10
+ # top level module InlineEncryption
8
11
  module InlineEncryption
9
12
  extend InlineEncryption::Base
10
13
 
@@ -14,6 +17,4 @@ module InlineEncryption
14
17
  I18n.enforce_available_locales = false
15
18
  @_i18n_initialized_for_ie = true
16
19
  end
17
-
18
-
19
20
  end
@@ -1,15 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'base64'
3
5
 
4
6
  describe InlineEncryption::Base do
5
-
6
7
  before :all do
7
8
  @default_key = OpenSSL::PKey::RSA.generate(2048)
8
9
  end
9
10
 
10
11
  describe 'encrypt' do
11
-
12
- let(:str){ 'foo' }
12
+ let(:str) { 'foo' }
13
13
 
14
14
  before :each do
15
15
  InlineEncryption.config[:key] = @default_key
@@ -20,19 +20,18 @@ describe InlineEncryption::Base do
20
20
  end
21
21
 
22
22
  it 'should fail to encrpyt and return the target' do
23
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
24
- expect(InlineEncryption.encrypt(str*2)).to eq(str*2)
23
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
24
+ expect(InlineEncryption.encrypt(nil)).to eq(nil)
25
25
  end
26
26
 
27
27
  it 'should fail to encrypt and return the fail_text' do
28
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
29
- expect(InlineEncryption.encrypt(str*2, 'chunky')).to eq('chunky')
28
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
29
+ expect(InlineEncryption.encrypt(nil, 'chunky')).to eq('chunky')
30
30
  end
31
-
32
31
  end
33
32
 
34
33
  describe 'encrypt!' do
35
- let(:str){ 'foo' }
34
+ let(:str) { 'foo' }
36
35
 
37
36
  before :each do
38
37
  InlineEncryption.config[:key] = @default_key
@@ -43,57 +42,46 @@ describe InlineEncryption::Base do
43
42
  end
44
43
 
45
44
  it 'should fail to encrpyt and raise' do
46
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
47
- expect{ InlineEncryption.encrypt!(str*2) }.to raise_error(InlineEncryption::EncryptionFailureError)
45
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
46
+ expect { InlineEncryption.encrypt!(nil) }.to raise_error(InlineEncryption::EncryptionFailureError)
48
47
  end
49
-
50
48
  end
51
49
 
52
50
  describe 'decrypt' do
53
-
54
- before :all do
55
- @str = Base64.encode64(@default_key.public_encrypt('chunky'))
56
- end
51
+ let(:str) { Base64.encode64(@default_key.public_encrypt('chunky')) }
57
52
 
58
53
  it 'should decrypt' do
59
54
  InlineEncryption.config[:key] = @default_key
60
- expect(InlineEncryption.decrypt(@str)).to eq('chunky')
55
+ expect(InlineEncryption.decrypt(str)).to eq('chunky')
61
56
  end
62
57
 
63
58
  it 'should fail to decrypt and return the target' do
64
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
65
- expect(InlineEncryption.decrypt(@str)).to eq(@str)
59
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
60
+ expect(InlineEncryption.decrypt(str)).to eq(str)
66
61
  end
67
62
 
68
63
  it 'should fail to decrypt and return the fail_text' do
69
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
70
- expect(InlineEncryption.decrypt(@str, 'chunky')).to eq('chunky')
64
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
65
+ expect(InlineEncryption.decrypt(str, 'chunky')).to eq('chunky')
71
66
  end
72
67
 
73
68
  it 'should fail to decrpyt and raise if using a public key to decrypt' do
74
69
  InlineEncryption.config[:key] = @default_key.public_key
75
- expect{ InlineEncryption.decrypt('whatevs') }.to raise_error(InlineEncryption::MisconfigurationError)
70
+ expect { InlineEncryption.decrypt('whatevs') }.to raise_error(InlineEncryption::MisconfigurationError)
76
71
  end
77
-
78
72
  end
79
73
 
80
74
  describe 'decrypt!' do
81
-
82
- before :all do
83
- @str = Base64.encode64(@default_key.public_encrypt('chunky'))
84
- end
75
+ let(:str) { Base64.encode64(@default_key.public_encrypt('chunky')) }
85
76
 
86
77
  it 'should decrypt' do
87
78
  InlineEncryption.config[:key] = @default_key
88
- expect(InlineEncryption.decrypt!(@str)).to eq('chunky')
79
+ expect(InlineEncryption.decrypt!(str)).to eq('chunky')
89
80
  end
90
81
 
91
82
  it 'should fail to decrpyt and raise' do
92
- InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(32)
93
- expect{ InlineEncryption.decrypt!(@str) }.to raise_error(InlineEncryption::DecryptionFailureError)
83
+ InlineEncryption.config[:key] = OpenSSL::PKey::RSA.generate(2048)
84
+ expect { InlineEncryption.decrypt!(str) }.to raise_error(InlineEncryption::DecryptionFailureError)
94
85
  end
95
-
96
86
  end
97
-
98
87
  end
99
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'base64'
3
5
  require 'inline_encryption/cli'
@@ -7,10 +9,8 @@ def tmp_filename
7
9
  end
8
10
 
9
11
  describe InlineEncryption::CLI do
10
-
11
12
  describe 'initialize' do
12
-
13
- let(:subject){ InlineEncryption::CLI.new }
13
+ let(:subject) { InlineEncryption::CLI.new }
14
14
 
15
15
  before :all do
16
16
  @default_key = OpenSSL::PKey::RSA.generate(2048)
@@ -24,18 +24,15 @@ describe InlineEncryption::CLI do
24
24
  end
25
25
 
26
26
  it 'should require a file if passed' do
27
- subject = InlineEncryption::CLI.new(['foo'], [ '-r', 'foo.rb' ], {})
27
+ subject = InlineEncryption::CLI.new(['foo'], ['-r', 'foo.rb'], {})
28
28
 
29
29
  expect(subject).to receive(:load_environment).with('foo.rb')
30
30
 
31
31
  subject.encrypt('foo')
32
32
  end
33
-
34
33
  end
35
34
 
36
-
37
35
  describe 'load_environment' do
38
-
39
36
  before :each do
40
37
  FileUtils.mkdir_p File.dirname(tmp_filename)
41
38
  File.open(tmp_filename, 'w') do |file|
@@ -49,9 +46,7 @@ describe InlineEncryption::CLI do
49
46
 
50
47
  it 'should require the file' do
51
48
  subject.send(:load_environment, tmp_filename)
52
- expect{ FooForInlineEncryptionSpec }.not_to raise_error
49
+ expect { FooForInlineEncryptionSpec }.not_to raise_error
53
50
  end
54
-
55
51
  end
56
-
57
52
  end
@@ -1,24 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe InlineEncryption::Config do
4
-
5
6
  describe 'check_required_values' do
6
- let(:subject){ InlineEncryption::Config.new }
7
+ let(:subject) { InlineEncryption::Config.new }
7
8
 
8
9
  it "should raise if 'key' is not set" do
9
- expect{ subject.check_required_variables }.to raise_error(InlineEncryption::MissingRequiredVariableError)
10
+ expect { subject.check_required_variables }.to raise_error(InlineEncryption::MissingRequiredVariableError)
10
11
  end
11
12
 
12
13
  it "should not raise if 'key' is set" do
13
14
  subject[:key] = 'foo'
14
- expect{ subject.check_required_variables }.not_to raise_error
15
+ expect { subject.check_required_variables }.not_to raise_error
15
16
  end
16
-
17
17
  end
18
18
 
19
-
20
19
  describe 'real_key' do
21
- let(:subject){ InlineEncryption::Config.new }
20
+ let(:subject) { InlineEncryption::Config.new }
22
21
 
23
22
  it 'should return nil if key is NilClass' do
24
23
  subject[:key] = nil
@@ -27,14 +26,14 @@ describe InlineEncryption::Config do
27
26
  end
28
27
 
29
28
  it 'should return the key value if key is an OpenSSL::PKey::RSA key' do
30
- key = OpenSSL::PKey::RSA.new(128)
29
+ key = OpenSSL::PKey::RSA.new(512)
31
30
  subject[:key] = key
32
31
 
33
32
  expect(subject.real_key).to eq(key)
34
33
  end
35
34
 
36
35
  it 'should return an OpenSSL::PKey::RSA key from the given String' do
37
- temp_key = OpenSSL::PKey::RSA.generate(32)
36
+ temp_key = OpenSSL::PKey::RSA.generate(512)
38
37
  key = temp_key.to_s
39
38
  subject[:key] = key
40
39
 
@@ -43,16 +42,14 @@ describe InlineEncryption::Config do
43
42
  end
44
43
 
45
44
  it 'should load the contents of the given file if exists and use as key' do
46
- temp_key = OpenSSL::PKey::RSA.generate(32)
45
+ temp_key = OpenSSL::PKey::RSA.generate(512)
47
46
  key = 'foo'
48
47
  subject[:key] = key
49
- allow(File).to receive(:exists?).with('foo').and_return(true)
48
+ allow(File).to receive(:exist?).with('foo').and_return(true)
50
49
  allow(File).to receive(:read).with('foo').and_return(temp_key.to_s)
51
50
 
52
51
  expect(subject.real_key.to_s).to eq(temp_key.to_s)
53
52
  expect(subject.real_key).to be_an_instance_of OpenSSL::PKey::RSA
54
53
  end
55
54
  end
56
-
57
-
58
- end
55
+ end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe InlineEncryption do
4
-
5
6
  it 'should load Base' do
6
- expect{ InlineEncryption::Base }.not_to raise_error
7
+ expect { InlineEncryption::Base }.not_to raise_error
7
8
  end
8
9
 
9
10
  it 'should be extended by Base' do
10
11
  expect(InlineEncryption.respond_to?(:config)).to be_truthy
11
12
  end
12
-
13
13
  end