1
0
Fork 0

Add columns X509Certificate#subject, #issuer

This commit is contained in:
Alex Kotov 2019-09-11 17:03:14 +05:00
parent 6c6dd0e56b
commit a099bd9d4e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 28 additions and 0 deletions

View file

@ -11,6 +11,8 @@ class CreateX509SelfSignedCertificate
def call def call
context.certificate = X509Certificate.create!( context.certificate = X509Certificate.create!(
pem: cert.to_pem.freeze, pem: cert.to_pem.freeze,
subject: cert.subject.to_s,
issuer: cert.issuer.to_s,
not_before: context.not_before, not_before: context.not_before,
not_after: context.not_after, not_after: context.not_after,
) )

View file

@ -13,6 +13,10 @@ class X509Certificate < ApplicationRecord
validates :pem, presence: true validates :pem, presence: true
validates :subject, presence: true
validates :issuer, presence: true
validates :not_before, presence: true validates :not_before, presence: true
validates :not_after, presence: true validates :not_after, presence: true

View file

@ -36,6 +36,8 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
t.references :x509_certificate_request, null: true, foreign_key: true t.references :x509_certificate_request, null: true, foreign_key: true
t.text :pem, null: false t.text :pem, null: false
t.string :subject, null: false
t.string :issuer, null: false
t.datetime :not_before, null: false t.datetime :not_before, null: false
t.datetime :not_after, null: false t.datetime :not_after, null: false
end end

View file

@ -925,6 +925,8 @@ CREATE TABLE public.x509_certificates (
updated_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL,
x509_certificate_request_id bigint, x509_certificate_request_id bigint,
pem text NOT NULL, pem text NOT NULL,
subject character varying NOT NULL,
issuer character varying NOT NULL,
not_before timestamp without time zone NOT NULL, not_before timestamp without time zone NOT NULL,
not_after timestamp without time zone NOT NULL not_after timestamp without time zone NOT NULL
); );

View file

@ -3,6 +3,8 @@
FactoryBot.define do FactoryBot.define do
factory :self_signed_x509_certificate, class: X509Certificate do factory :self_signed_x509_certificate, class: X509Certificate do
pem { File.read Rails.root.join 'fixtures', 'ca.crt' } pem { File.read Rails.root.join 'fixtures', 'ca.crt' }
subject { '/CN=example.com' }
issuer { subject }
not_before { Faker::Time.backward.utc } not_before { Faker::Time.backward.utc }
not_after { Faker::Time.forward.utc } not_after { Faker::Time.forward.utc }
end end

View file

@ -37,6 +37,14 @@ RSpec.describe CreateX509SelfSignedCertificate do
be_start_with "-----BEGIN CERTIFICATE-----\n" be_start_with "-----BEGIN CERTIFICATE-----\n"
end 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 specify do
expect(subject.certificate.not_before).to eq not_before expect(subject.certificate.not_before).to eq not_before
end end

View file

@ -25,6 +25,14 @@ RSpec.describe X509Certificate do
end end
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 describe '#not_before' do
it { is_expected.to validate_presence_of :not_before } it { is_expected.to validate_presence_of :not_before }
end end