Rename column RSAPublicKey#pem to #public_key_pem
This commit is contained in:
parent
2ab04a014b
commit
3958ddd336
9 changed files with 20 additions and 16 deletions
|
@ -14,7 +14,7 @@ class CreateRSAKeys
|
|||
|
||||
context.public_key = RSAPublicKey.create!(
|
||||
bits: BITS,
|
||||
pem: @pkey.public_key.to_pem.freeze,
|
||||
public_key_pem: @pkey.public_key.to_pem.freeze,
|
||||
private_key_pem_iv: @iv,
|
||||
private_key_pem_ciphertext: @ciphertext,
|
||||
)
|
||||
|
|
|
@ -18,7 +18,8 @@ private
|
|||
end
|
||||
|
||||
def public_key_pkey
|
||||
@public_key_pkey ||= OpenSSL::PKey::RSA.new context.public_key.pem
|
||||
@public_key_pkey ||=
|
||||
OpenSSL::PKey::RSA.new context.public_key.public_key_pem
|
||||
end
|
||||
|
||||
def subject
|
||||
|
|
|
@ -26,7 +26,8 @@ private
|
|||
end
|
||||
|
||||
def public_key_pkey
|
||||
@public_key_pkey ||= OpenSSL::PKey::RSA.new context.public_key.pem
|
||||
@public_key_pkey ||=
|
||||
OpenSSL::PKey::RSA.new context.public_key.public_key_pem
|
||||
end
|
||||
|
||||
def subject
|
||||
|
|
|
@ -5,7 +5,7 @@ class RSAPublicKey < ApplicationRecord
|
|||
# Validations #
|
||||
###############
|
||||
|
||||
validates :pem, presence: true
|
||||
validates :public_key_pem, presence: true
|
||||
|
||||
validates :bits, inclusion: { in: [2048, 4096] }
|
||||
end
|
||||
|
|
|
@ -7,13 +7,14 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
|
|||
create_table :rsa_public_keys do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.text :pem, null: false
|
||||
t.integer :bits, null: false
|
||||
t.text :public_key_pem, null: false
|
||||
|
||||
t.binary :private_key_pem_iv
|
||||
t.binary :private_key_pem_ciphertext
|
||||
|
||||
t.index :pem, unique: true
|
||||
t.integer :bits, null: false
|
||||
|
||||
t.index :public_key_pem, unique: true
|
||||
end
|
||||
|
||||
constraint :rsa_public_keys, :bits, <<~SQL
|
||||
|
|
|
@ -729,10 +729,10 @@ CREATE TABLE public.rsa_public_keys (
|
|||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
pem text NOT NULL,
|
||||
bits integer NOT NULL,
|
||||
public_key_pem text NOT NULL,
|
||||
private_key_pem_iv bytea,
|
||||
private_key_pem_ciphertext bytea,
|
||||
bits integer NOT NULL,
|
||||
CONSTRAINT bits CHECK ((bits = ANY (ARRAY[2048, 4096])))
|
||||
);
|
||||
|
||||
|
@ -1458,10 +1458,10 @@ CREATE INDEX index_relationships_on_status ON public.relationships USING btree (
|
|||
|
||||
|
||||
--
|
||||
-- Name: index_rsa_public_keys_on_pem; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_rsa_public_keys_on_public_key_pem; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_rsa_public_keys_on_pem ON public.rsa_public_keys USING btree (pem);
|
||||
CREATE UNIQUE INDEX index_rsa_public_keys_on_public_key_pem ON public.rsa_public_keys USING btree (public_key_pem);
|
||||
|
||||
|
||||
--
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
FactoryBot.define do
|
||||
factory :rsa_public_key do
|
||||
pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
|
||||
public_key_pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
|
||||
bits { [2048, 4096].sample }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,11 +42,12 @@ RSpec.describe CreateRSAKeys do
|
|||
end
|
||||
|
||||
specify do
|
||||
expect { OpenSSL::PKey::RSA.new subject.public_key.pem }.not_to raise_error
|
||||
expect { OpenSSL::PKey::RSA.new subject.public_key.public_key_pem }.not_to \
|
||||
raise_error
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.public_key.pem).to \
|
||||
expect(subject.public_key.public_key_pem).to \
|
||||
eq OpenSSL::PKey::RSA.new(subject.private_key_pem).public_key.to_pem
|
||||
end
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ require 'rails_helper'
|
|||
RSpec.describe RSAPublicKey do
|
||||
subject { create :rsa_public_key }
|
||||
|
||||
describe '#pem' do
|
||||
it { is_expected.to validate_presence_of :pem }
|
||||
describe '#public_key_pem' do
|
||||
it { is_expected.to validate_presence_of :public_key_pem }
|
||||
end
|
||||
|
||||
describe '#bits' do
|
||||
|
|
Reference in a new issue