1
0
Fork 0

Add shared example "asymmetric_key"

This commit is contained in:
Alex Kotov 2019-09-14 02:45:49 +05:00
parent 2172d55317
commit 8ffe943e5a
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 53 additions and 45 deletions

View file

@ -5,56 +5,12 @@ require 'rails_helper'
RSpec.describe RSAKey do RSpec.describe RSAKey do
subject { create :rsa_key } subject { create :rsa_key }
describe '#account' do it_behaves_like 'asymmetric_key'
it { is_expected.to belong_to(:account).optional }
it { is_expected.not_to validate_presence_of :account }
it { is_expected.not_to validate_uniqueness_of :account }
end
describe '#public_key_pem' do
it { is_expected.to validate_presence_of :public_key_pem }
it { is_expected.to validate_uniqueness_of :public_key_pem }
end
describe '#public_key_der' do
it { is_expected.to validate_presence_of :public_key_der }
it { is_expected.to validate_uniqueness_of :public_key_der }
end
describe '#has_password' do
it { is_expected.to validate_exclusion_of(:has_password).in_array([nil]) }
end
describe '#bits' do describe '#bits' do
it do
is_expected.to \
validate_numericality_of(:bits)
.only_integer
.is_greater_than(0)
end
it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) } it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) }
end end
describe '#sha1' do
it { is_expected.to validate_presence_of :sha1 }
it { is_expected.to validate_uniqueness_of(:sha1).case_insensitive }
end
describe '#sha256' do
it { is_expected.to validate_presence_of :sha256 }
it { is_expected.to validate_uniqueness_of(:sha256).case_insensitive }
end
describe '#private_key_pem_iv' do
it { is_expected.not_to validate_presence_of :private_key_pem_iv }
end
describe '#private_key_pem_ciphertext' do
it { is_expected.not_to validate_presence_of :private_key_pem_ciphertext }
end
describe '#encrypt_private_key_pem' do describe '#encrypt_private_key_pem' do
subject { create :rsa_key, private_key_pem: cleartext } subject { create :rsa_key, private_key_pem: cleartext }

View file

@ -0,0 +1,51 @@
# frozen_string_literal: true
RSpec.shared_examples 'asymmetric_key' do
describe '#account' do
it { is_expected.to belong_to(:account).optional }
it { is_expected.not_to validate_presence_of :account }
it { is_expected.not_to validate_uniqueness_of :account }
end
describe '#public_key_pem' do
it { is_expected.to validate_presence_of :public_key_pem }
it { is_expected.to validate_uniqueness_of :public_key_pem }
end
describe '#public_key_der' do
it { is_expected.to validate_presence_of :public_key_der }
it { is_expected.to validate_uniqueness_of :public_key_der }
end
describe '#has_password' do
it { is_expected.to validate_exclusion_of(:has_password).in_array([nil]) }
end
describe '#bits' do
it do
is_expected.to \
validate_numericality_of(:bits)
.only_integer
.is_greater_than(0)
end
end
describe '#sha1' do
it { is_expected.to validate_presence_of :sha1 }
it { is_expected.to validate_uniqueness_of(:sha1).case_insensitive }
end
describe '#sha256' do
it { is_expected.to validate_presence_of :sha256 }
it { is_expected.to validate_uniqueness_of(:sha256).case_insensitive }
end
describe '#private_key_pem_iv' do
it { is_expected.not_to validate_presence_of :private_key_pem_iv }
end
describe '#private_key_pem_ciphertext' do
it { is_expected.not_to validate_presence_of :private_key_pem_ciphertext }
end
end

View file

@ -37,6 +37,7 @@ require_relative 'support/database_cleaner'
require_relative 'support/devise' require_relative 'support/devise'
require_relative 'support/pundit' require_relative 'support/pundit'
require_relative 'models/shared_examples/asymmetric_key'
require_relative 'models/shared_examples/nameable' require_relative 'models/shared_examples/nameable'
require_relative 'models/shared_examples/required_nameable' require_relative 'models/shared_examples/required_nameable'