Add columns X509Certificate#subject, #issuer
This commit is contained in:
parent
6c6dd0e56b
commit
a099bd9d4e
7 changed files with 28 additions and 0 deletions
|
@ -11,6 +11,8 @@ class CreateX509SelfSignedCertificate
|
|||
def call
|
||||
context.certificate = X509Certificate.create!(
|
||||
pem: cert.to_pem.freeze,
|
||||
subject: cert.subject.to_s,
|
||||
issuer: cert.issuer.to_s,
|
||||
not_before: context.not_before,
|
||||
not_after: context.not_after,
|
||||
)
|
||||
|
|
|
@ -13,6 +13,10 @@ class X509Certificate < ApplicationRecord
|
|||
|
||||
validates :pem, presence: true
|
||||
|
||||
validates :subject, presence: true
|
||||
|
||||
validates :issuer, presence: true
|
||||
|
||||
validates :not_before, presence: true
|
||||
|
||||
validates :not_after, presence: true
|
||||
|
|
|
@ -36,6 +36,8 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
|
|||
t.references :x509_certificate_request, null: true, foreign_key: true
|
||||
|
||||
t.text :pem, null: false
|
||||
t.string :subject, null: false
|
||||
t.string :issuer, null: false
|
||||
t.datetime :not_before, null: false
|
||||
t.datetime :not_after, null: false
|
||||
end
|
||||
|
|
|
@ -925,6 +925,8 @@ CREATE TABLE public.x509_certificates (
|
|||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
x509_certificate_request_id bigint,
|
||||
pem text NOT NULL,
|
||||
subject character varying NOT NULL,
|
||||
issuer character varying NOT NULL,
|
||||
not_before timestamp without time zone NOT NULL,
|
||||
not_after timestamp without time zone NOT NULL
|
||||
);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
FactoryBot.define do
|
||||
factory :self_signed_x509_certificate, class: X509Certificate do
|
||||
pem { File.read Rails.root.join 'fixtures', 'ca.crt' }
|
||||
subject { '/CN=example.com' }
|
||||
issuer { subject }
|
||||
not_before { Faker::Time.backward.utc }
|
||||
not_after { Faker::Time.forward.utc }
|
||||
end
|
||||
|
|
|
@ -37,6 +37,14 @@ RSpec.describe CreateX509SelfSignedCertificate do
|
|||
be_start_with "-----BEGIN CERTIFICATE-----\n"
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate.subject).to eq "/#{distinguished_name}"
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate.issuer).to eq "/#{distinguished_name}"
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.certificate.not_before).to eq not_before
|
||||
end
|
||||
|
|
|
@ -25,6 +25,14 @@ RSpec.describe X509Certificate do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#subject' do
|
||||
it { is_expected.to validate_presence_of :subject }
|
||||
end
|
||||
|
||||
describe '#issuer' do
|
||||
it { is_expected.to validate_presence_of :issuer }
|
||||
end
|
||||
|
||||
describe '#not_before' do
|
||||
it { is_expected.to validate_presence_of :not_before }
|
||||
end
|
||||
|
|
Reference in a new issue