rapid-vaults 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff3321864a63230a5cb7c5c3b57dfbfc403e2cc06f4c903e78c3bcbf4f52a4c3
4
- data.tar.gz: 302469d5ba1c2306c16a438552a47dcf895423f3b661f76088ac1c8eaab21770
3
+ metadata.gz: 3b0cdeb7f71f3f2a7ded9f820beb5ca0783be43de7601b513dfc678d78cc838d
4
+ data.tar.gz: b5b89f9d9842f9e52272e146635dcb173b3cbe6213b20b057e8d431f175fe318
5
5
  SHA512:
6
- metadata.gz: 6668ff3eb490e4b68335f602693ba84ffa9b2079bf614c9f730d006a26d8ac66caa324bdf8b29dd4a15141c3ae8bb230192d97255c124930c31f296038c5f3d1
7
- data.tar.gz: d79506278d8708890866ee20a742a60cb9d36d4c75f552ff0e5d051ae32f1923cbf2094bb5b0ab580677be2c36e49d458b9e90a7f9cf4091cbad689693576392
6
+ metadata.gz: 2499dc4629ed310eda5a6dc925576b7eba089ea541864ae43adbcb925162e77c97d6cc0a81c52d0b5052a9f809aa1a1e44e9173ae463b32213b0fab00ca87c56
7
+ data.tar.gz: dce32b3c164c16779bbaee284987d3884f8304f197d215d51c5a7ce9c68966afe114225ca1c0e8c66be5dc3bf8cb04a50d0fea461d5e8d32a2c71cac13aa99f1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 1.3.2
2
+ - Add `--force` CLI flag, and do not overwrite files by default.
3
+ - Improve output file pathing.
4
+ - Fix password file setting in Puppet bindings.
5
+ - Fix longform output directory CLI argument.
6
+
7
+ ### 1.3.1
8
+ - Fix GPG keys output path message.
9
+ - Fix encrypted data validation.
10
+ - Enforce non-empty password when input.
11
+ - Validate API settings analogous to CLI.
12
+
1
13
  ### 1.3.0
2
14
  - Bump minimum Ruby version to 2.6.
3
15
  - Code optimization and validation improvements.
@@ -10,6 +10,13 @@ class RapidVaults::API
10
10
 
11
11
  # parse api options; this is mostly here for unit testing
12
12
  def self.parse(settings)
13
+ # validate args
14
+ if %i[encrypt decrypt].include?(settings[:action])
15
+ raise 'no file specified for encryption or decryption' if !settings.key?(:file)
16
+ end
17
+
18
+ raise 'input password cannot be empty' if settings.key?(:pw) && settings[:pw].empty?
19
+
13
20
  # establish settings for api and denote using api
14
21
  settings.merge({ ui: :api })
15
22
  end
@@ -10,7 +10,7 @@ class Binding
10
10
  CRYPT.each do |algo|
11
11
  ACTION.each do |action|
12
12
  content = File.read("#{__dir__}/bindings/puppet_#{algo}_#{action}.rb")
13
- File.write("#{settings[:outdir]}puppet_#{algo}_#{action}.rb", content)
13
+ File.write(File.join(settings[:outdir], "puppet_#{algo}_#{action}.rb"), content)
14
14
  end
15
15
  end
16
16
  end
@@ -19,6 +19,6 @@ class Binding
19
19
  def self.chef(settings)
20
20
  # output chef bindings to output directory
21
21
  content = File.read("#{__dir__}/bindings/chef.rb")
22
- File.write("#{settings[:outdir]}chef.rb", content)
22
+ File.write(File.join(settings[:outdir], 'chef.rb'), content)
23
23
  end
24
24
  end
@@ -28,7 +28,7 @@ Puppet::Functions.create_function(:ssl_decrypt) do
28
28
  # initialize settings
29
29
  settings = { action: :decrypt, file: file, key: key, nonce: nonce, tag: tag }
30
30
  # update settings with password if input
31
- settings[pw: File.read(password_file)] unless password_file.nil?
31
+ settings[:pw] = File.read(password_file) unless password_file.nil?
32
32
 
33
33
  RapidVaults::API.main(settings)
34
34
  end
@@ -27,7 +27,7 @@ Puppet::Functions.create_function(:ssl_encrypt) do
27
27
  settings = { action: :encrypt, file: file, key: key, nonce: nonce }
28
28
  return_hash = {}
29
29
  # update settings with password if input
30
- settings[pw: File.read(password_file)] unless password_file.nil?
30
+ settings[:pw] = File.read(password_file) unless password_file.nil?
31
31
 
32
32
  return_hash[:encrypted_contents], return_hash[:tag] = RapidVaults::API.main(settings)
33
33
 
@@ -6,10 +6,14 @@ class RapidVaults::CLI
6
6
  def self.main(args)
7
7
  # parse args in cli and denote using cli
8
8
  settings = parse(args)
9
+
10
+ # validate args
9
11
  if %i[encrypt decrypt].include?(settings[:action])
10
12
  args.empty? ? (raise 'rapid-vaults: no file specified; try using --help') : settings[:file] = args.first
11
13
  end
12
14
 
15
+ raise 'input password cannot be empty' if settings.key?(:pw) && settings[:pw].empty?
16
+
13
17
  # run RapidVaults with specified file
14
18
  RapidVaults.new.main(settings)
15
19
  0
@@ -66,10 +70,11 @@ class RapidVaults::CLI
66
70
  raise "GPG Parameters file #{arg} is not an existing readable file!" unless File.readable?(arg)
67
71
  settings[:gpgparams] = File.read(arg)
68
72
  end
69
- opts.on('-o --outdir', String, 'Optional output directory for generated files (default: pwd). (GPG: optional)') do |arg|
73
+ opts.on('-o', '--outdir output_directory', String, 'Optional output directory for generated files (default: pwd). (GPG: optional)') do |arg|
70
74
  raise "The output directory #{arg} does not exist or is not a directory!" unless File.directory?(arg)
71
75
  settings[:outdir] = arg
72
76
  end
77
+ opts.on('--force', 'Force overwrite of existing files during generation, encryption, and decryption.') { settings[:force] = true }
73
78
  end
74
79
 
75
80
  # parse args and return settings
@@ -14,9 +14,18 @@ class Decrypt
14
14
  # output the decryption
15
15
  case settings[:ui]
16
16
  when :cli
17
+ # efficiency assignment
18
+ outdir = settings[:outdir]
19
+ decryptfile = File.join(outdir, 'decrypted.txt')
20
+
21
+ # check if already exists and no force flag
22
+ if File.exist?(decryptfile)
23
+ raise "decrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
24
+ end
25
+
17
26
  # output to file
18
- File.write("#{settings[:outdir]}decrypted.txt", decipher.update(settings[:file]) + decipher.final)
19
- puts "Your decrypted.txt has been written out to #{settings[:outdir]}."
27
+ File.write(decryptfile, decipher.update(settings[:file]) + decipher.final)
28
+ puts "Your decrypted.txt has been written out to #{outdir}."
20
29
  when :api
21
30
  # output to string
22
31
  decipher.update(settings[:file]) + decipher.final
@@ -37,9 +46,18 @@ class Decrypt
37
46
  # output the decryption
38
47
  case settings[:ui]
39
48
  when :cli
49
+ # efficiency assignment
50
+ outdir = settings[:outdir]
51
+ decryptfile = File.join(outdir, 'decrypted.txt')
52
+
53
+ # check if already exists and no force flag
54
+ if File.exist?(decryptfile)
55
+ raise "decrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
56
+ end
57
+
40
58
  # output to file
41
- File.write("#{settings[:outdir]}decrypted.txt", crypto.decrypt(encrypted, password: settings[:pw]).read)
42
- puts "Your decrypted.txt has been written out to #{settings[:outdir]}."
59
+ File.write(decryptfile, crypto.decrypt(encrypted, password: settings[:pw]).read)
60
+ puts "Your decrypted.txt has been written out to #{outdir}."
43
61
  when :api
44
62
  # output to string
45
63
  crypto.decrypt(encrypted, password: settings[:pw]).read
@@ -13,10 +13,20 @@ class Encrypt
13
13
  # output the encryption and associated tag
14
14
  case settings[:ui]
15
15
  when :cli
16
+ # efficiency assignment
17
+ outdir = settings[:outdir]
18
+ encryptfile = File.join(outdir, 'encrypted.txt')
19
+ tagfile = File.join(outdir, 'tag.txt')
20
+
21
+ # check if already exists and no force flag
22
+ if File.exist?(encryptfile) || File.exist?(tagfile)
23
+ raise "encrypted.txt or tag.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
24
+ end
25
+
16
26
  # output to file
17
- File.write("#{settings[:outdir]}encrypted.txt", cipher.update(settings[:file]) + cipher.final)
18
- File.write("#{settings[:outdir]}tag.txt", cipher.auth_tag)
19
- puts "Your encrypted.txt and associated tag.txt for this encryption have been generated in #{settings[:outdir]}."
27
+ File.write(encryptfile, cipher.update(settings[:file]) + cipher.final)
28
+ File.write(tagfile, cipher.auth_tag)
29
+ puts "Your encrypted.txt and associated tag.txt for this encryption have been generated in #{outdir}."
20
30
  when :api
21
31
  # return as array
22
32
  [cipher.update(settings[:file]) + cipher.final, cipher.auth_tag]
@@ -36,9 +46,18 @@ class Encrypt
36
46
  # output the encryption and associated tag
37
47
  case settings[:ui]
38
48
  when :cli
49
+ # efficiency assignment
50
+ outdir = settings[:outdir]
51
+ encryptfile = File.join(outdir, 'encrypted.txt')
52
+
53
+ # check if already exists and no force flag
54
+ if File.exist?(encryptfile)
55
+ raise "encrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
56
+ end
57
+
39
58
  # output to file
40
- File.write("#{settings[:outdir]}encrypted.txt", crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read)
41
- puts "Your encrypted.txt for this encryption has been generated in #{settings[:outdir]}."
59
+ File.write(encryptfile, crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read)
60
+ puts "Your encrypted.txt for this encryption has been generated in #{outdir}."
42
61
  when :api
43
62
  # return as string
44
63
  crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read
@@ -9,10 +9,20 @@ class Generate
9
9
 
10
10
  case settings[:ui]
11
11
  when :cli
12
+ # efficiency assignment
13
+ outdir = settings[:outdir]
14
+ keyfile = File.join(outdir, 'key.txt')
15
+ noncefile = File.join(outdir, 'nonce.txt')
16
+
17
+ # check if already exists and no force flag
18
+ if File.exist?(keyfile) || File.exist?(noncefile)
19
+ raise "key.txt or nonce.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
20
+ end
21
+
12
22
  # output to file
13
- File.write("#{settings[:outdir]}key.txt", cipher.random_key)
14
- File.write("#{settings[:outdir]}nonce.txt", cipher.random_iv)
15
- puts "Your key.txt and nonce.txt have been generated in #{settings[:outdir]}."
23
+ File.write(keyfile, cipher.random_key)
24
+ File.write(noncefile, cipher.random_iv)
25
+ puts "Your key.txt and nonce.txt have been generated in #{outdir}."
16
26
  when :api
17
27
  # return as array
18
28
  [cipher.random_key, cipher.random_iv]
@@ -26,8 +36,13 @@ class Generate
26
36
  # ensure we have a place to store these output files
27
37
  raise 'Environment variable "GNUPGHOME" was not set.' unless ENV.fetch('GNUPGHOME', false)
28
38
 
39
+ # check if already exists and no force flag
40
+ if Dir.exist?(ENV['GNUPGHOME']) && !Dir.empty?(ENV['GNUPGHOME'])
41
+ raise "GPG keyring in #{ENV['GNUPGHOME']} already exists and is not empty. Use the --force flag to overwrite existing files." unless settings[:force]
42
+ end
43
+
29
44
  # create gpg keys
30
45
  GPGME::Ctx.new.generate_key(settings[:gpgparams], nil, nil)
31
- puts "Your GPG keys have been generated in #{ENV.fetch['GNUPGHOME']}." if settings[:ui] == :cli
46
+ puts "Your GPG keys have been generated in #{ENV.fetch('GNUPGHOME')}." if settings[:ui] == :cli
32
47
  end
33
48
  end
data/lib/rapid_vaults.rb CHANGED
@@ -25,7 +25,6 @@ class RapidVaults
25
25
  if settings[:ui] == :cli
26
26
  # :outdir only relevant for :cli
27
27
  settings[:outdir] ||= Dir.pwd
28
- settings[:outdir] += '/' unless settings[:outdir][-1] == '/'
29
28
  end
30
29
 
31
30
  return if settings[:action] == :binding
@@ -35,9 +34,10 @@ class RapidVaults
35
34
  public_send(:"process_#{settings[:algorithm]}", settings)
36
35
  end
37
36
 
37
+ private
38
+
38
39
  # processing openssl
39
40
  def self.process_openssl(settings)
40
- private_class_method :method
41
41
  # check arguments
42
42
  case settings[:action]
43
43
  when :generate then return
@@ -49,7 +49,7 @@ class RapidVaults
49
49
  end
50
50
 
51
51
  # lambda for input processing
52
- process_input = ->(input) { File.readable?(settings[input]) ? settings[input] = File.read(settings[input]) : (raise "Input file '#{settings[input]}' for argument '#{input}' is not an existing readable file.") }
52
+ process_input = ->(input) { File.readable?(settings[input]) ? settings[input] = File.binread(settings[input]) : (raise "Input file '#{settings[input]}' for argument '#{input}' is not an existing readable file.") }
53
53
 
54
54
  # check inputs and read in files
55
55
  raise 'Password must be a string.' if settings.key?(:pw) && !settings[:pw].is_a?(String)
@@ -63,13 +63,12 @@ class RapidVaults
63
63
  return unless settings[:action] == :decrypt
64
64
  process_input.call(:tag) if settings[:action] == :decrypt
65
65
 
66
- raise 'The encrypted data is not a valid multiple of 9 bytes.' unless (settings[:file].bytesize % 9).zero?
66
+ raise 'The encrypted data is empty.' if settings[:file].empty?
67
67
  raise 'Tag is not 16 bytes.' unless settings[:tag].bytesize == 16
68
68
  end
69
69
 
70
70
  # processing gpgme
71
71
  def self.process_gpgme(settings)
72
- private_class_method :method
73
72
  # check arguments
74
73
  case settings[:action]
75
74
  when :generate
data/rapid-vaults.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'rapid-vaults'
3
- spec.version = '1.3.0'
3
+ spec.version = '1.3.2'
4
4
  spec.authors = ['Matt Schuchard']
5
5
  spec.description = 'Ad-hoc encrypt and decrypt data behind multiple layers of protection via OpenSSL or GPG.'
6
6
  spec.summary = 'Ad-hoc encrypt and decrypt data.'
@@ -15,5 +15,11 @@ describe RapidVaults::API do
15
15
  it 'correctly overrides the algorithm setting' do
16
16
  expect(RapidVaults::API.parse(algorithm: :gpgme)).to eq(algorithm: :gpgme, ui: :api)
17
17
  end
18
+ it 'raises an error for encrypt action with no file' do
19
+ expect { RapidVaults::API.parse(action: :encrypt) }.to raise_error('no file specified for encryption or decryption')
20
+ end
21
+ it 'raises an error for an empty password' do
22
+ expect { RapidVaults::API.parse(action: :encrypt, file: 'file.txt', pw: '') }.to raise_error('input password cannot be empty')
23
+ end
18
24
  end
19
25
  end
@@ -8,7 +8,7 @@ describe Binding do
8
8
  end
9
9
 
10
10
  it 'outputs the puppet bindings to the specified directory' do
11
- Binding.puppet({})
11
+ Binding.puppet({outdir: Dir.pwd})
12
12
  %w[puppet_gpg_decrypt.rb puppet_gpg_encrypt.rb puppet_ssl_decrypt.rb puppet_ssl_encrypt.rb].each do |file|
13
13
  expect(File.file?(file)).to be true
14
14
  end
@@ -21,7 +21,7 @@ describe Binding do
21
21
  end
22
22
 
23
23
  it 'outputs the chef bindings to the specified directory' do
24
- Binding.chef({})
24
+ Binding.chef({outdir: Dir.pwd})
25
25
  expect(File.file?('chef.rb')).to be true
26
26
  end
27
27
  end
@@ -16,11 +16,14 @@ describe RapidVaults::CLI do
16
16
  expect(RapidVaults::CLI.parse(%w[-g -o .])).to eq(ui: :cli, action: :generate, outdir: '.')
17
17
  end
18
18
  it 'correctly parses the arguments for gpg generate' do
19
- expect(RapidVaults::CLI.parse(%W[--gpg -g --gpgparams #{fixtures_dir}/file.yaml])).to eq(algorithm: :gpgme, ui: :cli, action: :generate, gpgparams: "foo: bar\n")
19
+ expect(RapidVaults::CLI.parse(%W[--gpg -g --gpgparams #{FIXTURES_DIR}/file.yaml])).to eq(algorithm: :gpgme, ui: :cli, action: :generate, gpgparams: "foo: bar\n")
20
20
  end
21
21
  it 'correctly parses the arguments for puppet bindings' do
22
22
  expect(RapidVaults::CLI.parse(%w[-b puppet -o .])).to eq(ui: :cli, action: :binding, binding: :puppet, outdir: '.')
23
23
  end
24
+ it 'correctly parses the arguments with force option' do
25
+ expect(RapidVaults::CLI.parse(%w[--force])).to eq(ui: :cli, force: true)
26
+ end
24
27
  it 'raises an error for a nonexistent password file' do
25
28
  expect { RapidVaults::CLI.parse(%w[-f /nopasswordhere]) }.to raise_error('Password file /nopasswordhere is not an existing readable file!')
26
29
  end
@@ -3,6 +3,10 @@ require_relative '../../lib/rapid-vaults/encrypt'
3
3
  require_relative '../../lib/rapid-vaults/decrypt'
4
4
 
5
5
  describe Decrypt do
6
+ after(:all) do
7
+ %w[tag.txt encrypted.txt decrypted.txt].each { |file| File.delete(file) }
8
+ end
9
+
6
10
  context '.openssl' do
7
11
  require 'openssl'
8
12
  cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
@@ -10,20 +14,16 @@ describe Decrypt do
10
14
  nonce = cipher.random_iv
11
15
 
12
16
  before(:all) do
13
- Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce)
14
- end
15
-
16
- after(:all) do
17
- %w[tag.txt encrypted.txt decrypted.txt].each { |file| File.delete(file) }
17
+ Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
18
18
  end
19
19
 
20
20
  it 'outputs a decrypted file with the key, nonce, and tag from the cli' do
21
- Decrypt.openssl(ui: :cli, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'))
21
+ Decrypt.openssl(ui: :cli, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'), outdir: Dir.pwd)
22
22
  expect(File.file?('decrypted.txt')).to be true
23
23
  expect(File.read('decrypted.txt')).to eq("foo: bar\n")
24
24
  end
25
25
  it 'outputs decrypted content with the key, nonce, and tag from the api' do
26
- decrypt = Decrypt.openssl(ui: :api, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'))
26
+ decrypt = Decrypt.openssl(ui: :api, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'), outdir: Dir.pwd)
27
27
  expect(decrypt).to be_a(String)
28
28
  expect(decrypt).to eq("foo: bar\n")
29
29
  end
@@ -31,20 +31,16 @@ describe Decrypt do
31
31
 
32
32
  context '.gpgme' do
33
33
  before(:all) do
34
- Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo')
35
- end
36
-
37
- after(:all) do
38
- %w[encrypted.txt decrypted.txt].each { |file| File.delete(file) }
34
+ Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd, force: true)
39
35
  end
40
36
 
41
37
  it 'outputs a decrypted file with the key from the cli' do
42
- Decrypt.gpgme(ui: :cli, file: File.read('encrypted.txt'), key: '', pw: 'foo')
38
+ Decrypt.gpgme(ui: :cli, file: File.read('encrypted.txt'), key: '', pw: 'foo', outdir: Dir.pwd, force: true)
43
39
  expect(File.file?('decrypted.txt')).to be true
44
40
  expect(File.read('decrypted.txt')).to eq("foo: bar\n")
45
41
  end
46
42
  it 'outputs decrypted content with the key from the api' do
47
- decrypt = Decrypt.gpgme(ui: :api, file: File.read('encrypted.txt'), key: '', pw: 'foo')
43
+ decrypt = Decrypt.gpgme(ui: :api, file: File.read('encrypted.txt'), key: '', pw: 'foo', outdir: Dir.pwd)
48
44
  expect(decrypt).to be_a(String)
49
45
  expect(decrypt).to eq("foo: bar\n")
50
46
  end
@@ -2,28 +2,28 @@ require_relative '../spec_helper'
2
2
  require_relative '../../lib/rapid-vaults/encrypt'
3
3
 
4
4
  describe Encrypt do
5
+ after(:all) do
6
+ %w[tag.txt encrypted.txt].each { |file| File.delete(file) }
7
+ end
8
+
5
9
  context '.openssl' do
6
10
  require 'openssl'
7
11
  cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
8
12
  key = cipher.random_key
9
13
  nonce = cipher.random_iv
10
14
 
11
- after(:all) do
12
- %w[tag.txt encrypted.txt].each { |file| File.delete(file) }
13
- end
14
-
15
15
  it 'outputs an encrypted file with the key and nonce from the cli' do
16
- Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce)
16
+ Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
17
17
  expect(File.file?('tag.txt')).to be true
18
18
  expect(File.file?('encrypted.txt')).to be true
19
19
  end
20
20
  it 'outputs an encrypted file with the key, nonce, and password from the cli' do
21
- Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, pw: 'password')
21
+ Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, pw: 'password', outdir: Dir.pwd, force: true)
22
22
  expect(File.file?('tag.txt')).to be true
23
23
  expect(File.file?('encrypted.txt')).to be true
24
24
  end
25
25
  it 'outputs an array of encrypted content and tag with the key and nonce from the api' do
26
- encrypt = Encrypt.openssl(ui: :api, file: "foo: bar\n", key: key, nonce: nonce)
26
+ encrypt = Encrypt.openssl(ui: :api, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
27
27
  expect(encrypt).to be_a(Array)
28
28
  expect(encrypt.length).to eq(2)
29
29
  expect(encrypt[0]).to be_a(String)
@@ -33,11 +33,11 @@ describe Encrypt do
33
33
 
34
34
  context '.gpgme' do
35
35
  it 'outputs an encrypted file with the key from the cli' do
36
- Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo')
36
+ Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd, force: true)
37
37
  expect(File.file?('encrypted.txt')).to be true
38
38
  end
39
39
  it 'outputs a string of encrypted content with the key from the api' do
40
- encrypt = Encrypt.gpgme(ui: :api, file: "foo: bar\n", key: '', pw: 'foo')
40
+ encrypt = Encrypt.gpgme(ui: :api, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd)
41
41
  expect(encrypt).to be_a(String)
42
42
  end
43
43
  end
@@ -8,7 +8,7 @@ describe Generate do
8
8
  end
9
9
 
10
10
  it 'generates the key and nonce files from the cli' do
11
- Generate.openssl(ui: :cli)
11
+ Generate.openssl(ui: :cli, outdir: Dir.pwd)
12
12
  expect(File.file?('key.txt')).to be true
13
13
  expect(File.file?('nonce.txt')).to be true
14
14
  expect(File.read('key.txt')).to be_a(String)
@@ -25,23 +25,23 @@ describe Generate do
25
25
 
26
26
  context '.gpgme' do
27
27
  it 'raises an error for a missing GNUPGHOME variable' do
28
- expect { Generate.gpgme(gpgparams: File.read("#{fixtures_dir}/gpgparams.txt")) }.to raise_error('Environment variable "GNUPGHOME" was not set.')
28
+ expect { Generate.gpgme(gpgparams: File.read("#{FIXTURES_DIR}/gpgparams.txt")) }.to raise_error('Environment variable "GNUPGHOME" was not set.')
29
29
  end
30
30
  it 'generates the key files' do
31
31
  require 'fileutils'
32
32
 
33
- ENV['GNUPGHOME'] = fixtures_dir
33
+ ENV['GNUPGHOME'] = FIXTURES_DIR
34
34
 
35
- Generate.gpgme(gpgparams: File.read("#{fixtures_dir}/gpgparams.txt"))
35
+ Generate.gpgme(gpgparams: File.read("#{FIXTURES_DIR}/gpgparams.txt"), force: true)
36
36
  %w[trustdb.gpg pubring.kbx pubring.kbx~].each do |file|
37
- expect(File.file?("#{fixtures_dir}/#{file}")).to be true
38
- File.delete("#{fixtures_dir}/#{file}")
37
+ expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true
38
+ File.delete("#{FIXTURES_DIR}/#{file}")
39
39
  end
40
40
  %w[openpgp-revocs.d private-keys-v1.d].each do |dir|
41
- expect(File.directory?("#{fixtures_dir}/#{dir}")).to be true
42
- FileUtils.rm_r("#{fixtures_dir}/#{dir}")
41
+ expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true
42
+ FileUtils.rm_r("#{FIXTURES_DIR}/#{dir}")
43
43
  end
44
- %w[S.gpg-agent random_seed].each { |file| File.delete("#{fixtures_dir}/#{file}") if File.file?(file) }
44
+ %w[S.gpg-agent random_seed].each { |file| File.delete("#{FIXTURES_DIR}/#{file}") if File.file?(file) }
45
45
  end
46
46
  end
47
47
  end
@@ -12,8 +12,8 @@ describe RapidVaults do
12
12
  File.write('nonce_good.txt', SecureRandom.random_bytes(12).strip)
13
13
  File.write('tag_bad.txt', SecureRandom.random_bytes(24).strip)
14
14
  File.write('tag_good.txt', SecureRandom.random_bytes(16).strip)
15
- File.write('encrypted_bad.txt', SecureRandom.random_bytes(16).strip)
16
- File.write('encrypted_good.txt', '')
15
+ File.write('encrypted_bad.txt', '')
16
+ File.write('encrypted_good.txt', SecureRandom.random_bytes(16).strip)
17
17
  end
18
18
 
19
19
  after(:all) do
@@ -51,22 +51,22 @@ describe RapidVaults do
51
51
  expect { RapidVaults.process(algorithm: :gpgme, action: :encrypt, file: 'a', pw: 'password') }.to raise_error('Input file \'a\' for argument \'file\' is not an existing readable file.')
52
52
  end
53
53
  it 'raises an error for an invalid key size' do
54
- expect { RapidVaults.process(action: :encrypt, file: "#{fixtures_dir}file.yaml", key: 'key_bad.txt', nonce: 'nonce_good.txt') }.to raise_error('The key is not a valid 32 byte key.')
54
+ expect { RapidVaults.process(action: :encrypt, file: "#{FIXTURES_DIR}file.yaml", key: 'key_bad.txt', nonce: 'nonce_good.txt') }.to raise_error('The key is not a valid 32 byte key.')
55
55
  end
56
56
  it 'raises an error for an invalid nonce size' do
57
- expect { RapidVaults.process(action: :encrypt, file: "#{fixtures_dir}file.yaml", key: 'key_good.txt', nonce: 'nonce_bad.txt') }.to raise_error('The nonce is not a valid 12 byte nonce.')
57
+ expect { RapidVaults.process(action: :encrypt, file: "#{FIXTURES_DIR}file.yaml", key: 'key_good.txt', nonce: 'nonce_bad.txt') }.to raise_error('The nonce is not a valid 12 byte nonce.')
58
58
  end
59
59
  it 'raises an error for an invalid tag size' do
60
60
  expect { RapidVaults.process(action: :decrypt, file: 'encrypted_good.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_bad.txt') }.to raise_error('Tag is not 16 bytes.')
61
61
  end
62
62
  it 'raises an error for corrupted encrypted file content' do
63
- expect { RapidVaults.process(action: :decrypt, file: 'encrypted_bad.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_good.txt') }.to raise_error('The encrypted data is not a valid multiple of 9 bytes.')
63
+ expect { RapidVaults.process(action: :decrypt, file: 'encrypted_bad.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_good.txt') }.to raise_error('The encrypted data is empty.')
64
64
  end
65
65
  it 'reads in all input files correctly for openssl encryption' do
66
66
  expect { RapidVaults.process(action: :decrypt, file: 'encrypted_good.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_good.txt', pw: 'password') }.not_to raise_exception
67
67
  end
68
68
  it 'reads in all input files correctly for gpgme decryption' do
69
- dummy = "#{fixtures_dir}file.yaml"
69
+ dummy = "#{FIXTURES_DIR}file.yaml"
70
70
  expect { RapidVaults.process(algorithm: :gpgme, action: :decrypt, file: dummy, pw: 'password') }.not_to raise_exception
71
71
  end
72
72
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,8 @@
1
1
  require 'rspec'
2
2
 
3
3
  # for path to fixtures
4
- module Variables
5
- extend RSpec::SharedContext
6
-
7
- let(:fixtures_dir) { "#{File.dirname(__FILE__)}/fixtures/" }
8
- end
4
+ FIXTURES_DIR = "#{File.dirname(__FILE__)}/fixtures/".freeze
9
5
 
10
6
  RSpec.configure do |config|
11
- config.include Variables
12
7
  config.color = true
13
8
  end
@@ -16,7 +16,7 @@ describe RapidVaults do
16
16
  context 'executed with openssl algorithm as a system from the CLI with settings and a file to be processed' do
17
17
  it 'generates key and nonce, encrypts a file, and then decrypts a file in order' do
18
18
  # generate and utilize files inside suitable directory
19
- Dir.chdir(fixtures_dir)
19
+ Dir.chdir(FIXTURES_DIR)
20
20
 
21
21
  # generate key and nonce
22
22
  RapidVaults::CLI.main(%w[-g])
@@ -38,7 +38,7 @@ describe RapidVaults do
38
38
  context 'executed with openssl algorithm as a system from the API with settings and a file to be processed' do
39
39
  it 'generates key and nonce, encrypts a file, and then decrypts a file in order' do
40
40
  # generate and utilize files inside suitable directory
41
- Dir.chdir(fixtures_dir)
41
+ Dir.chdir(FIXTURES_DIR)
42
42
 
43
43
  # generate key and nonce
44
44
  RapidVaults::API.main(action: :generate)
@@ -63,18 +63,18 @@ describe RapidVaults do
63
63
  unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
64
64
  context 'executed wtih gpg algorithm as a system from the CLI with settings and a file to be processed' do
65
65
  it 'encrypts a file and then decrypts a file in order' do
66
- ENV['GNUPGHOME'] = fixtures_dir
66
+ ENV['GNUPGHOME'] = FIXTURES_DIR
67
67
 
68
68
  # generate and utilize files inside suitable directory
69
- Dir.chdir(fixtures_dir)
69
+ Dir.chdir(FIXTURES_DIR)
70
70
 
71
71
  # generate keys
72
- RapidVaults::CLI.main(%w[-g --gpg --gpgparams gpgparams.txt])
73
- %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{fixtures_dir}/#{file}")).to be true }
74
- %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{fixtures_dir}/#{dir}")).to be true }
72
+ RapidVaults::CLI.main(%w[-g --gpg --force --gpgparams gpgparams.txt])
73
+ %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true }
74
+ %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true }
75
75
 
76
76
  # generate encrypted file
77
- RapidVaults::CLI.main(%w[--gpg -e -p foo file.yaml])
77
+ RapidVaults::CLI.main(%w[--gpg -e --force -p foo file.yaml])
78
78
  expect(File.file?('encrypted.txt')).to be true
79
79
 
80
80
  # generate decrypted file
@@ -86,15 +86,15 @@ describe RapidVaults do
86
86
 
87
87
  context 'executed with gpg algorithm as a system from the API with settings and a file to be processed' do
88
88
  it 'encrypts a file and then decrypts a file in order' do
89
- ENV['GNUPGHOME'] = fixtures_dir
89
+ ENV['GNUPGHOME'] = FIXTURES_DIR
90
90
 
91
91
  # generate and utilize files inside suitable directory
92
- Dir.chdir(fixtures_dir)
92
+ Dir.chdir(FIXTURES_DIR)
93
93
 
94
94
  # generate keys
95
- RapidVaults::API.main(action: :generate, algorithm: :gpgme, gpgparams: File.read('gpgparams.txt'))
96
- %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{fixtures_dir}/#{file}")).to be true }
97
- %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{fixtures_dir}/#{dir}")).to be true }
95
+ RapidVaults::API.main(action: :generate, algorithm: :gpgme, force: true, gpgparams: File.read('gpgparams.txt'))
96
+ %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true }
97
+ %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true }
98
98
 
99
99
  # generate encrypted file
100
100
  encrypt = RapidVaults::API.main(algorithm: :gpgme, action: :encrypt, file: 'file.yaml', pw: 'password')
@@ -112,7 +112,7 @@ describe RapidVaults do
112
112
  context 'executed as a system to output bindings from the CLI' do
113
113
  it 'outputs the puppet and chef bindings' do
114
114
  # generate and utilize files inside suitable directory
115
- Dir.chdir(fixtures_dir)
115
+ Dir.chdir(FIXTURES_DIR)
116
116
 
117
117
  # generate bindings
118
118
  RapidVaults::CLI.main(%w[-b puppet])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapid-vaults
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-14 00:00:00.000000000 Z
11
+ date: 2026-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gpgme