Add model RSAPublicKey
This commit is contained in:
parent
54fcae0631
commit
be251fc110
6 changed files with 114 additions and 5 deletions
11
app/models/rsa_public_key.rb
Normal file
11
app/models/rsa_public_key.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RSAPublicKey < ApplicationRecord
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
||||
validates :pem, presence: true
|
||||
|
||||
validates :bits, inclusion: { in: [2048, 4096] }
|
||||
end
|
|
@ -12,7 +12,6 @@
|
|||
# inflect.uncountable %w( fish sheep )
|
||||
# end
|
||||
|
||||
# These inflection rules are supported but not enabled by default:
|
||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
# inflect.acronym 'RESTful'
|
||||
# end
|
||||
ActiveSupport::Inflector.inflections :en do |inflect|
|
||||
inflect.acronym 'RSA'
|
||||
end
|
||||
|
|
20
db/migrate/20190910115511_create_rsa_public_keys.rb
Normal file
20
db/migrate/20190910115511_create_rsa_public_keys.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateRSAPublicKeys < ActiveRecord::Migration[6.0]
|
||||
include Partynest::Migration
|
||||
|
||||
def change
|
||||
create_table :rsa_public_keys do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.text :pem, null: false
|
||||
t.integer :bits, null: false
|
||||
|
||||
t.index :pem, unique: true
|
||||
end
|
||||
|
||||
constraint :rsa_public_keys, :bits, <<~SQL
|
||||
bits in (2048, 4096)
|
||||
SQL
|
||||
end
|
||||
end
|
|
@ -721,6 +721,39 @@ CREATE SEQUENCE public.relationships_id_seq
|
|||
ALTER SEQUENCE public.relationships_id_seq OWNED BY public.relationships.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: rsa_public_keys; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
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,
|
||||
CONSTRAINT bits CHECK ((bits = ANY (ARRAY[2048, 4096])))
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rsa_public_keys_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.rsa_public_keys_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: rsa_public_keys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.rsa_public_keys_id_seq OWNED BY public.rsa_public_keys.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -932,6 +965,13 @@ ALTER TABLE ONLY public.regional_offices ALTER COLUMN id SET DEFAULT nextval('pu
|
|||
ALTER TABLE ONLY public.relationships ALTER COLUMN id SET DEFAULT nextval('public.relationships_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rsa_public_keys id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.rsa_public_keys ALTER COLUMN id SET DEFAULT nextval('public.rsa_public_keys_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1057,6 +1097,14 @@ ALTER TABLE ONLY public.relationships
|
|||
ADD CONSTRAINT relationships_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rsa_public_keys rsa_public_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.rsa_public_keys
|
||||
ADD CONSTRAINT rsa_public_keys_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1306,6 +1354,13 @@ CREATE INDEX index_relationships_on_role ON public.relationships USING btree (ro
|
|||
CREATE INDEX index_relationships_on_status ON public.relationships USING btree (status);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_rsa_public_keys_on_pem; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_rsa_public_keys_on_pem ON public.rsa_public_keys USING btree (pem);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_sessions_on_account_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1520,6 +1575,7 @@ SET search_path TO "$user", public;
|
|||
INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20181129203927'),
|
||||
('20181130024918'),
|
||||
('20190910040709');
|
||||
('20190910040709'),
|
||||
('20190910115511');
|
||||
|
||||
|
||||
|
|
8
factories/rsa_public_keys.rb
Normal file
8
factories/rsa_public_keys.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :rsa_public_key do
|
||||
pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
|
||||
bits { [2048, 4096].sample }
|
||||
end
|
||||
end
|
15
spec/models/rsa_public_key_spec.rb
Normal file
15
spec/models/rsa_public_key_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RSAPublicKey do
|
||||
subject { create :rsa_public_key }
|
||||
|
||||
describe '#pem' do
|
||||
it { is_expected.to validate_presence_of :pem }
|
||||
end
|
||||
|
||||
describe '#bits' do
|
||||
it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) }
|
||||
end
|
||||
end
|
Reference in a new issue