1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/spec/interactors/create_rsa_keys_spec.rb
2019-09-12 07:14:17 +05:00

63 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CreateRSAKeys do
subject { described_class.call }
specify do
expect { subject }.to change(RSAPublicKey, :count).by(1)
end
specify do
expect(subject.public_key).to be_instance_of RSAPublicKey
end
specify do
expect(subject.public_key.private_key_pem).not_to be_blank
end
specify do
expect(subject.public_key.private_key_pem_secret).not_to be_blank
end
specify do
expect do
OpenSSL::PKey::RSA.new subject.public_key.private_key_pem
end.not_to raise_error
end
specify do
expect { OpenSSL::PKey::RSA.new subject.public_key.public_key_pem }.not_to \
raise_error
end
specify do
expect(subject.public_key.public_key_pem).to eq(
OpenSSL::PKey::RSA.new(subject.public_key.private_key_pem)
.public_key.to_pem,
)
end
specify do
expect(subject.public_key.private_key_pem_iv).not_to be_blank
end
specify do
expect(subject.public_key.private_key_pem_ciphertext).not_to be_blank
end
specify do
cipher = OpenSSL::Cipher::AES256.new
cipher.decrypt
cipher.iv = subject.public_key.private_key_pem_iv
cipher.key = subject.public_key.private_key_pem_secret
cleartext = [
cipher.update(subject.public_key.private_key_pem_ciphertext),
cipher.final,
].join.freeze
expect(cleartext).to eq subject.public_key.private_key_pem
end
end