Fixes #3528 - Allow to add S/MIME certificate chains from single file.

This commit is contained in:
Rolf Schmidt 2021-04-28 06:57:52 +00:00 committed by Thorsten Eckel
parent 3b7909ed5c
commit 9bc1d212ce
3 changed files with 28 additions and 5 deletions

View file

@ -42,11 +42,13 @@ class Integration::SMIMEController < ApplicationController
string = params[:file].read.force_encoding('utf-8')
end
item = SMIMECertificate.create!(public_key: string)
items = string.scan(/.+?-+END(?: TRUSTED)? CERTIFICATE-+/mi).each_with_object([]) do |cert, result|
result << SMIMECertificate.create!(public_key: cert)
end
render json: {
result: 'ok',
response: item,
response: items,
}
rescue => e
unprocessable_entity(e)

View file

@ -30,7 +30,7 @@ RSpec.describe 'Integration SMIME', type: :request do
end.to change(SMIMECertificate, :count).by(1)
expect(response).to have_http_status(:ok)
expect(DateTime.parse(json_response['response']['not_after_at'])).to eq(parsed_certificate.not_after)
expect(DateTime.parse(json_response['response'][0]['not_after_at'])).to eq(parsed_certificate.not_after)
end
it 'adds certificate by file' do
@ -39,7 +39,7 @@ RSpec.describe 'Integration SMIME', type: :request do
end.to change(SMIMECertificate, :count).by(1)
expect(response).to have_http_status(:ok)
expect(DateTime.parse(json_response['response']['not_after_at'])).to eq(parsed_certificate.not_after)
expect(DateTime.parse(json_response['response'][0]['not_after_at'])).to eq(parsed_certificate.not_after)
end
end

View file

@ -14,11 +14,14 @@ RSpec.describe 'Manage > Integration > S/MIME', type: :system do
File.read(Rails.root.join("spec/fixtures/smime/#{fixture}.secret")).strip
end
it 'enabling and adding of public and private key' do
before do
visit 'system/integration/smime'
# enable S/MIME
click 'label[for=setting-switch]'
end
it 'enabling and adding of public and private key' do
# add cert
click '.js-addCertificate'
@ -40,4 +43,22 @@ RSpec.describe 'Manage > Integration > S/MIME', type: :system do
expect( SMIMECertificate.last.raw ).to be_present
expect( SMIMECertificate.last.private_key ).to be_present
end
it 'adding of multiple certificates at once' do
multiple_certificates = [
File.read(Rails.root.join('spec/fixtures/smime/ChainCA.crt')),
File.read(Rails.root.join('spec/fixtures/smime/IntermediateCA.crt')),
File.read(Rails.root.join('spec/fixtures/smime/RootCA.crt')),
].join
# add cert
click '.js-addCertificate'
fill_in 'Paste Certificate', with: multiple_certificates
click '.js-submit'
# wait for ajax
expect(page).to have_text('ChainCA')
expect(page).to have_text('IntermediateCA')
expect(page).to have_text('RootCA')
end
end