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?
|
return render :new unless @x509_certificate_form.valid?
|
||||||
|
|
||||||
result = CreateRSAKeysAndX509SelfSignedCertificate.call \
|
result = CreateRSAKeysAndX509SelfSignedCertificate.call \
|
||||||
@x509_certificate_form.attributes
|
@x509_certificate_form.attributes.merge(account: current_account)
|
||||||
|
|
||||||
redirect_to after_create_url result.certificate
|
redirect_to after_create_url result.certificate
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,8 @@ private
|
||||||
pkey = OpenSSL::PKey::RSA.new BITS
|
pkey = OpenSSL::PKey::RSA.new BITS
|
||||||
|
|
||||||
{
|
{
|
||||||
|
account: context.account,
|
||||||
|
|
||||||
bits: BITS,
|
bits: BITS,
|
||||||
|
|
||||||
sha1: Digest::SHA1.hexdigest(pkey.public_key.to_der),
|
sha1: Digest::SHA1.hexdigest(pkey.public_key.to_der),
|
||||||
|
|
|
@ -5,12 +5,14 @@ require 'rails_helper'
|
||||||
RSpec.describe CreateRSAKeysAndX509SelfSignedCertificate do
|
RSpec.describe CreateRSAKeysAndX509SelfSignedCertificate do
|
||||||
subject do
|
subject do
|
||||||
described_class.call(
|
described_class.call(
|
||||||
|
account: account,
|
||||||
distinguished_name: distinguished_name,
|
distinguished_name: distinguished_name,
|
||||||
not_before: not_before,
|
not_before: not_before,
|
||||||
not_after: not_after,
|
not_after: not_after,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:account) { create :initial_account }
|
||||||
let(:distinguished_name) { "CN=#{Faker::Internet.domain_name}" }
|
let(:distinguished_name) { "CN=#{Faker::Internet.domain_name}" }
|
||||||
let(:not_before) { Faker::Time.backward.utc }
|
let(:not_before) { Faker::Time.backward.utc }
|
||||||
let(:not_after) { Faker::Time.forward.utc }
|
let(:not_after) { Faker::Time.forward.utc }
|
||||||
|
@ -51,4 +53,16 @@ RSpec.describe CreateRSAKeysAndX509SelfSignedCertificate do
|
||||||
specify do
|
specify do
|
||||||
expect(subject.asymmetric_key.private_key_pem_secret).not_to be_blank
|
expect(subject.asymmetric_key.private_key_pem_secret).not_to be_blank
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe CreateRSAKeys do
|
RSpec.describe CreateRSAKeys do
|
||||||
subject { described_class.call }
|
subject { described_class.call account: account }
|
||||||
|
|
||||||
|
let(:account) { create :initial_account }
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
expect { subject }.to change(AsymmetricKey, :count).by(1)
|
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
|
expect(subject.asymmetric_key.private_key_pem_secret).not_to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(subject.asymmetric_key.account).to eq account
|
||||||
|
end
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
expect do
|
expect do
|
||||||
OpenSSL::PKey::RSA.new subject.asymmetric_key.private_key_pem
|
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
|
expect(cleartext).to eq subject.asymmetric_key.private_key_pem
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when owner is not specified' do
|
||||||
|
let(:account) { nil }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(subject.asymmetric_key.account).to equal nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,6 +66,11 @@ RSpec.describe 'POST /staff/x509_certificates' do
|
||||||
expect(X509Certificate.last).to \
|
expect(X509Certificate.last).to \
|
||||||
have_attributes x509_certificate_attributes
|
have_attributes x509_certificate_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(X509Certificate.last.asymmetric_key.account).to \
|
||||||
|
eq current_account
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in a new issue