spec/system/system_spec.rb in rapid-vaults-1.0.0 vs spec/system/system_spec.rb in rapid-vaults-1.1.0
- old
+ new
@@ -2,11 +2,17 @@
require_relative '../../lib/rapid-vaults/cli'
require_relative '../../lib/rapid-vaults/api'
describe RapidVaults do
after(:all) do
+ require 'fileutils'
+
%w[key.txt nonce.txt tag.txt encrypted.txt decrypted.txt].each { |file| File.delete(file) }
+ unless File.directory?('/home/travis')
+ %w[S.gpg-agent random_seed pubring.kbx trustdb.gpg pubring.kbx~].each { |file| File.delete(file) }
+ %w[openpgp-revocs.d private-keys-v1.d].each { |dir| FileUtils.rm_r(dir) }
+ end
end
context 'executed as a system from the CLI with settings and a file to be processed' do
it 'generates key and nonce, encrypts a file, and then decrypts a file in order' do
# generate and utilize files inside suitable directory
@@ -38,17 +44,70 @@
RapidVaults::API.main(action: :generate)
expect(File.file?('key.txt')).to be true
expect(File.file?('nonce.txt')).to be true
# generate encrypted file
- encrypt, tag = RapidVaults::API.main(action: :encrypt, file: 'file.yaml', key: 'key.txt', nonce: 'nonce.txt', password: 'password')
+ encrypt, tag = RapidVaults::API.main(action: :encrypt, file: 'file.yaml', key: 'key.txt', nonce: 'nonce.txt', pw: 'foo')
expect(encrypt).to be_a(String)
expect(tag).to be_a(String)
# generate decrypted file
File.write('encrypted.txt', encrypt)
File.write('tag.txt', tag)
- decrypt = RapidVaults::API.main(action: :decrypt, file: 'encrypted.txt', key: 'key.txt', nonce: 'nonce.txt', tag: 'tag.txt', password: 'password')
+ decrypt = RapidVaults::API.main(action: :decrypt, file: 'encrypted.txt', key: 'key.txt', nonce: 'nonce.txt', tag: 'tag.txt', pw: 'foo')
+ expect(decrypt).to be_a(String)
expect(decrypt).to eq("foo: bar\n")
+ end
+ end
+
+ # travis ci cannot support non-interactive gpg encryption
+ unless File.directory?('/home/travis')
+ context 'executed wtih gpg as a system from the CLI with settings and a file to be processed' do
+ it 'encrypts a file and then decrypts a file in order' do
+ ENV['GNUPGHOME'] = fixtures_dir
+
+ # generate and utilize files inside suitable directory
+ Dir.chdir(fixtures_dir)
+
+ puts fixtures_dir
+
+ # generate keys
+ RapidVaults::CLI.main(%w[-g --gpg --gpgparams gpgparams.txt])
+ %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{fixtures_dir}/#{file}")).to be true }
+ %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{fixtures_dir}/#{dir}")).to be true }
+
+ # generate encrypted file
+ RapidVaults::CLI.main(%w[--gpg -e -p foo file.yaml])
+ expect(File.file?('encrypted.txt')).to be true
+
+ # generate decrypted file
+ RapidVaults::CLI.main(%w[--gpg -d -p foo encrypted.txt])
+ expect(File.file?('decrypted.txt')).to be true
+ expect(File.read('decrypted.txt')).to eq("foo: bar\n")
+ end
+ end
+
+ context 'executed with gpg as a system from the API with settings and a file to be processed' do
+ it 'encrypts a file and then decrypts a file in order' do
+ ENV['GNUPGHOME'] = fixtures_dir
+
+ # generate and utilize files inside suitable directory
+ Dir.chdir(fixtures_dir)
+
+ # generate keys
+ RapidVaults::API.main(action: :generate, algorithm: :gpgme, gpgparams: File.read('gpgparams.txt'), ui: :cli)
+ %w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{fixtures_dir}/#{file}")).to be true }
+ %w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{fixtures_dir}/#{dir}")).to be true }
+
+ # generate encrypted file
+ encrypt = RapidVaults::API.main(algorithm: :gpgme, action: :encrypt, file: 'file.yaml', pw: 'password')
+ expect(encrypt).to be_a(String)
+
+ # generate decrypted file
+ File.write('encrypted.txt', encrypt)
+ decrypt = RapidVaults::API.main(algorithm: :gpgme, action: :decrypt, file: 'encrypted.txt', pw: 'password')
+ expect(decrypt).to be_a(String)
+ expect(decrypt).to eq("foo: bar\n")
+ end
end
end
end