Set AsymmetricKey#account
This commit is contained in:
parent
230085b964
commit
4838fb91a6
5 changed files with 37 additions and 2 deletions
|
@ -33,7 +33,7 @@ class Staffs::X509CertificatesController < ApplicationController
|
|||
return render :new unless @x509_certificate_form.valid?
|
||||
|
||||
result = CreateRSAKeysAndX509SelfSignedCertificate.call \
|
||||
@x509_certificate_form.attributes
|
||||
@x509_certificate_form.attributes.merge(account: current_account)
|
||||
|
||||
redirect_to after_create_url result.certificate
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@ private
|
|||
pkey = OpenSSL::PKey::RSA.new BITS
|
||||
|
||||
{
|
||||
account: context.account,
|
||||
|
||||
bits: BITS,
|
||||
|
||||
sha1: Digest::SHA1.hexdigest(pkey.public_key.to_der),
|
||||
|
|
|
@ -5,12 +5,14 @@ require 'rails_helper'
|
|||
RSpec.describe CreateRSAKeysAndX509SelfSignedCertificate do
|
||||
subject do
|
||||
described_class.call(
|
||||
account: account,
|
||||
distinguished_name: distinguished_name,
|
||||
not_before: not_before,
|
||||
not_after: not_after,
|
||||
)
|
||||
end
|
||||
|
||||
let(:account) { create :initial_account }
|
||||
let(:distinguished_name) { "CN=#{Faker::Internet.domain_name}" }
|
||||
let(:not_before) { Faker::Time.backward.utc }
|
||||
let(:not_after) { Faker::Time.forward.utc }
|
||||
|
@ -51,4 +53,16 @@ RSpec.describe CreateRSAKeysAndX509SelfSignedCertificate do
|
|||
specify do
|
||||
expect(subject.asymmetric_key.private_key_pem_secret).not_to be_blank
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.asymmetric_key.account).to eq account
|
||||
end
|
||||
|
||||
context 'when owner is not specified' do
|
||||
let(:account) { nil }
|
||||
|
||||
specify do
|
||||
expect(subject.asymmetric_key.account).to equal nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateRSAKeys do
|
||||
subject { described_class.call }
|
||||
subject { described_class.call account: account }
|
||||
|
||||
let(:account) { create :initial_account }
|
||||
|
||||
specify do
|
||||
expect { subject }.to change(AsymmetricKey, :count).by(1)
|
||||
|
@ -42,6 +44,10 @@ RSpec.describe CreateRSAKeys do
|
|||
expect(subject.asymmetric_key.private_key_pem_secret).not_to be_blank
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.asymmetric_key.account).to eq account
|
||||
end
|
||||
|
||||
specify do
|
||||
expect do
|
||||
OpenSSL::PKey::RSA.new subject.asymmetric_key.private_key_pem
|
||||
|
@ -99,4 +105,12 @@ RSpec.describe CreateRSAKeys do
|
|||
|
||||
expect(cleartext).to eq subject.asymmetric_key.private_key_pem
|
||||
end
|
||||
|
||||
context 'when owner is not specified' do
|
||||
let(:account) { nil }
|
||||
|
||||
specify do
|
||||
expect(subject.asymmetric_key.account).to equal nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,6 +66,11 @@ RSpec.describe 'POST /staff/x509_certificates' do
|
|||
expect(X509Certificate.last).to \
|
||||
have_attributes x509_certificate_attributes
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(X509Certificate.last.asymmetric_key.account).to \
|
||||
eq current_account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Reference in a new issue