1
0
Fork 0

Add model X509Certificate

This commit is contained in:
Alex Kotov 2019-09-11 03:57:12 +05:00
parent bc35a2f63c
commit acfc202565
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 114 additions and 1 deletions

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class X509Certificate < ApplicationRecord
################
# Associations #
################
belongs_to :x509_certificate_request, optional: true
###############
# Validations #
###############
validates :pem, presence: true
end

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
class CreateX509Certificates < ActiveRecord::Migration[6.0]
def change
create_table :x509_certificates do |t|
t.timestamps null: false
t.references :x509_certificate_request, null: true, foreign_key: true
t.text :pem, null: false
end
end
end

View file

@ -915,6 +915,38 @@ CREATE SEQUENCE public.x509_certificate_requests_id_seq
ALTER SEQUENCE public.x509_certificate_requests_id_seq OWNED BY public.x509_certificate_requests.id;
--
-- Name: x509_certificates; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.x509_certificates (
id bigint NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
x509_certificate_request_id bigint,
pem text NOT NULL
);
--
-- Name: x509_certificates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.x509_certificates_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: x509_certificates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.x509_certificates_id_seq OWNED BY public.x509_certificates.id;
--
-- Name: accounts id; Type: DEFAULT; Schema: public; Owner: -
--
@ -1034,6 +1066,13 @@ ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_
ALTER TABLE ONLY public.x509_certificate_requests ALTER COLUMN id SET DEFAULT nextval('public.x509_certificate_requests_id_seq'::regclass);
--
-- Name: x509_certificates id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.x509_certificates ALTER COLUMN id SET DEFAULT nextval('public.x509_certificates_id_seq'::regclass);
--
-- Name: accounts accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -1186,6 +1225,14 @@ ALTER TABLE ONLY public.x509_certificate_requests
ADD CONSTRAINT x509_certificate_requests_pkey PRIMARY KEY (id);
--
-- Name: x509_certificates x509_certificates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.x509_certificates
ADD CONSTRAINT x509_certificates_pkey PRIMARY KEY (id);
--
-- Name: index_accounts_on_contact_list_id; Type: INDEX; Schema: public; Owner: -
--
@ -1473,6 +1520,13 @@ CREATE UNIQUE INDEX index_users_on_unlock_token ON public.users USING btree (unl
CREATE INDEX index_x509_certificate_requests_on_rsa_public_key_id ON public.x509_certificate_requests USING btree (rsa_public_key_id);
--
-- Name: index_x509_certificates_on_x509_certificate_request_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_x509_certificates_on_x509_certificate_request_id ON public.x509_certificates USING btree (x509_certificate_request_id);
--
-- Name: accounts ensure_contact_list_id_matches_related_person; Type: TRIGGER; Schema: public; Owner: -
--
@ -1510,6 +1564,14 @@ ALTER TABLE ONLY public.relationships
ADD CONSTRAINT fk_rails_124c042ac0 FOREIGN KEY (initiator_account_id) REFERENCES public.accounts(id);
--
-- Name: x509_certificates fk_rails_4958020bc7; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.x509_certificates
ADD CONSTRAINT fk_rails_4958020bc7 FOREIGN KEY (x509_certificate_request_id) REFERENCES public.x509_certificate_requests(id);
--
-- Name: people fk_rails_4f02f930eb; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1641,6 +1703,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20181130024918'),
('20190910040709'),
('20190910115511'),
('20190910133430');
('20190910133430'),
('20190910225118');

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
FactoryBot.define do
factory :self_signed_x509_certificate, class: X509Certificate do
pem { OpenSSL::X509::Certificate.new.to_pem }
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe X509Certificate do
subject { create :self_signed_x509_certificate }
describe '#x509_certificate_request' do
it { is_expected.not_to validate_presence_of :x509_certificate_request }
end
describe '#pem' do
it { is_expected.to validate_presence_of :pem }
end
end