summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2018-02-11 12:59:16 -0700
committermo <mo.khan@gmail.com>2018-02-11 12:59:16 -0700
commitdbe80b3a01db80e1f8b25bd0049318305ffa99f6 (patch)
tree4076263f8c7f5df35975866e8bacec465d4c2622
parent6d0636f3833454f5764b3bfe54759f01f43cb920 (diff)
add spec for encryption.
-rw-r--r--spec/lib/secure_proxy_spec.rb30
-rw-r--r--spec/spec_helper.rb1
2 files changed, 31 insertions, 0 deletions
diff --git a/spec/lib/secure_proxy_spec.rb b/spec/lib/secure_proxy_spec.rb
new file mode 100644
index 0000000..4a8c60c
--- /dev/null
+++ b/spec/lib/secure_proxy_spec.rb
@@ -0,0 +1,30 @@
+module TFA
+ describe SecureProxy do
+ subject { described_class.new(original, passphrase) }
+ let(:original) { Tempfile.new('tfa') }
+ let(:passphrase) { SecureRandom.uuid }
+
+ after { original.unlink }
+
+ describe "decrypt!" do
+ let(:message) { JSON.generate(secret: SecureRandom.uuid) }
+
+ it 'decrypts an encrypted file' do
+ IO.write(original.path, message)
+ subject.encrypt!
+ subject.decrypt!
+ expect(IO.read(original.path)).to eql(message)
+ end
+ end
+
+ describe "encrypt!" do
+ let(:message) { JSON.generate(secret: SecureRandom.uuid) }
+
+ it 'encrypts a file' do
+ IO.write(original.path, message)
+ subject.encrypt!
+ expect(IO.read(original.path)).to_not eql(message)
+ end
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 72a74a5..0521f72 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -18,6 +18,7 @@ require 'tfa'
require 'securerandom'
require 'tempfile'
require 'tmpdir'
+require 'json'
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.