Remove model CertificateRequest
This commit is contained in:
parent
458c351e6b
commit
52303a736c
10 changed files with 1 additions and 236 deletions
|
@ -1,38 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateX509CertificateRequest
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
context.certificate_request = X509CertificateRequest.create!(
|
||||
rsa_public_key: context.public_key,
|
||||
distinguished_name: context.distinguished_name,
|
||||
pem: request.to_pem.freeze,
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def private_key_pkey
|
||||
@private_key_pkey ||=
|
||||
OpenSSL::PKey::RSA.new context.public_key.private_key_pem
|
||||
end
|
||||
|
||||
def public_key_pkey
|
||||
@public_key_pkey ||=
|
||||
OpenSSL::PKey::RSA.new context.public_key.public_key_pem
|
||||
end
|
||||
|
||||
def subject
|
||||
@subject ||= OpenSSL::X509::Name.parse context.distinguished_name
|
||||
end
|
||||
|
||||
def request
|
||||
@request ||= OpenSSL::X509::Request.new.tap do |request|
|
||||
request.version = 0
|
||||
request.public_key = public_key_pkey
|
||||
request.subject = subject
|
||||
request.sign private_key_pkey, OpenSSL::Digest::SHA256.new
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,8 +7,6 @@ class X509Certificate < ApplicationRecord
|
|||
|
||||
belongs_to :rsa_public_key
|
||||
|
||||
belongs_to :x509_certificate_request, optional: true
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class X509CertificateRequest < ApplicationRecord
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
||||
belongs_to :rsa_public_key
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
||||
validates :distinguished_name,
|
||||
presence: true,
|
||||
length: { maximum: 10_000 }
|
||||
|
||||
validates :pem, presence: true
|
||||
end
|
|
@ -27,24 +27,10 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
|
|||
bits in (2048, 4096)
|
||||
SQL
|
||||
|
||||
create_table :x509_certificate_requests do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.references :rsa_public_key, null: false, foreign_key: true
|
||||
|
||||
t.string :distinguished_name, null: false
|
||||
t.text :pem, null: false
|
||||
end
|
||||
|
||||
constraint :x509_certificate_requests, :distinguished_name, <<~SQL
|
||||
is_good_big_text(distinguished_name)
|
||||
SQL
|
||||
|
||||
create_table :x509_certificates do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.references :rsa_public_key, null: false, foreign_key: true
|
||||
t.references :x509_certificate_request, null: true, foreign_key: true
|
||||
t.references :rsa_public_key, null: false, foreign_key: true
|
||||
|
||||
t.text :pem, null: false
|
||||
t.string :subject, null: false
|
||||
|
|
|
@ -886,40 +886,6 @@ CREATE SEQUENCE public.users_id_seq
|
|||
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.x509_certificate_requests (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
rsa_public_key_id bigint NOT NULL,
|
||||
distinguished_name character varying NOT NULL,
|
||||
pem text NOT NULL,
|
||||
CONSTRAINT distinguished_name CHECK (public.is_good_big_text((distinguished_name)::text))
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.x509_certificate_requests_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.x509_certificate_requests_id_seq OWNED BY public.x509_certificate_requests.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificates; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -929,7 +895,6 @@ CREATE TABLE public.x509_certificates (
|
|||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
rsa_public_key_id bigint NOT NULL,
|
||||
x509_certificate_request_id bigint,
|
||||
pem text NOT NULL,
|
||||
subject character varying NOT NULL,
|
||||
issuer character varying NOT NULL,
|
||||
|
@ -1069,13 +1034,6 @@ ALTER TABLE ONLY public.user_omniauths ALTER COLUMN id SET DEFAULT nextval('publ
|
|||
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
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: -
|
||||
--
|
||||
|
@ -1227,14 +1185,6 @@ ALTER TABLE ONLY public.users
|
|||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests x509_certificate_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
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: -
|
||||
--
|
||||
|
@ -1544,13 +1494,6 @@ CREATE UNIQUE INDEX index_users_on_reset_password_token ON public.users USING bt
|
|||
CREATE UNIQUE INDEX index_users_on_unlock_token ON public.users USING btree (unlock_token);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_x509_certificate_requests_on_rsa_public_key_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
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_rsa_public_key_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1558,13 +1501,6 @@ CREATE INDEX index_x509_certificate_requests_on_rsa_public_key_id ON public.x509
|
|||
CREATE INDEX index_x509_certificates_on_rsa_public_key_id ON public.x509_certificates 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: -
|
||||
--
|
||||
|
@ -1602,14 +1538,6 @@ 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: -
|
||||
--
|
||||
|
@ -1730,14 +1658,6 @@ ALTER TABLE ONLY public.contacts
|
|||
ADD CONSTRAINT fk_rails_dd2a5400cf FOREIGN KEY (contact_list_id) REFERENCES public.contact_lists(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: x509_certificate_requests fk_rails_f0002b108f; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.x509_certificate_requests
|
||||
ADD CONSTRAINT fk_rails_f0002b108f FOREIGN KEY (rsa_public_key_id) REFERENCES public.rsa_public_keys(id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :x509_certificate_request do
|
||||
association :rsa_public_key
|
||||
|
||||
distinguished_name { "CN=#{Faker::Internet.domain_name}" }
|
||||
pem { OpenSSL::X509::Request.new.to_pem }
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateX509CertificateRequest do
|
||||
subject do
|
||||
described_class.call(
|
||||
public_key: public_key,
|
||||
distinguished_name: distinguished_name,
|
||||
)
|
||||
end
|
||||
|
||||
let(:rsa_keys) { CreateRSAKeys.call }
|
||||
let(:public_key) { rsa_keys.public_key }
|
||||
let(:distinguished_name) { "CN=#{Faker::Internet.domain_name}" }
|
||||
|
||||
specify do
|
||||
expect { subject }.to change(X509CertificateRequest, :count).by(1)
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate_request).to be_instance_of X509CertificateRequest
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate_request.rsa_public_key).to eq public_key
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate_request.distinguished_name).to \
|
||||
eq distinguished_name
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate_request.pem).to \
|
||||
be_start_with "-----BEGIN CERTIFICATE REQUEST-----\n"
|
||||
end
|
||||
end
|
|
@ -32,10 +32,6 @@ RSpec.describe CreateX509SelfSignedCertificate do
|
|||
expect(subject.certificate.rsa_public_key).to eq public_key
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate.x509_certificate_request).to equal nil
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate.pem).to \
|
||||
be_start_with "-----BEGIN CERTIFICATE-----\n"
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe X509CertificateRequest do
|
||||
subject { create :x509_certificate_request }
|
||||
|
||||
describe '#rsa_public_key' do
|
||||
it do
|
||||
is_expected.to \
|
||||
validate_presence_of(:rsa_public_key).with_message(:required)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#distinguished_name' do
|
||||
it { is_expected.to validate_presence_of :distinguished_name }
|
||||
|
||||
it do
|
||||
is_expected.to validate_length_of(:distinguished_name).is_at_most(10_000)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pem' do
|
||||
it { is_expected.to validate_presence_of :pem }
|
||||
end
|
||||
end
|
|
@ -16,10 +16,6 @@ RSpec.describe X509Certificate do
|
|||
it { is_expected.not_to validate_uniqueness_of :rsa_public_key }
|
||||
end
|
||||
|
||||
describe '#x509_certificate_request' do
|
||||
it { is_expected.not_to validate_presence_of :x509_certificate_request }
|
||||
end
|
||||
|
||||
describe '#pem' do
|
||||
def allow_value(*)
|
||||
super.for :pem
|
||||
|
|
Reference in a new issue