2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe SmimeSignatureSettings, feature_category: :not_owned do
|
2019-12-04 20:38:33 +05:30
|
|
|
describe '.parse' do
|
|
|
|
let(:default_smime_key) { Rails.root.join('.gitlab_smime_key') }
|
|
|
|
let(:default_smime_cert) { Rails.root.join('.gitlab_smime_cert') }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:default_smime_ca_certs) { nil }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
it 'sets correct default values to disabled' do
|
|
|
|
parsed_settings = described_class.parse(nil)
|
|
|
|
|
|
|
|
expect(parsed_settings['enabled']).to be(false)
|
|
|
|
expect(parsed_settings['key_file']).to eq(default_smime_key)
|
|
|
|
expect(parsed_settings['cert_file']).to eq(default_smime_cert)
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(parsed_settings['ca_certs_file']).to eq(default_smime_ca_certs)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when providing custom values' do
|
|
|
|
it 'sets correct default values to disabled' do
|
|
|
|
custom_settings = Settingslogic.new({})
|
|
|
|
|
|
|
|
parsed_settings = described_class.parse(custom_settings)
|
|
|
|
|
|
|
|
expect(parsed_settings['enabled']).to be(false)
|
|
|
|
expect(parsed_settings['key_file']).to eq(default_smime_key)
|
|
|
|
expect(parsed_settings['cert_file']).to eq(default_smime_cert)
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(parsed_settings['ca_certs_file']).to eq(default_smime_ca_certs)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'enables smime with default key and cert' do
|
|
|
|
custom_settings = Settingslogic.new({
|
|
|
|
'enabled' => true
|
|
|
|
})
|
|
|
|
|
|
|
|
parsed_settings = described_class.parse(custom_settings)
|
|
|
|
|
|
|
|
expect(parsed_settings['enabled']).to be(true)
|
|
|
|
expect(parsed_settings['key_file']).to eq(default_smime_key)
|
|
|
|
expect(parsed_settings['cert_file']).to eq(default_smime_cert)
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(parsed_settings['ca_certs_file']).to eq(default_smime_ca_certs)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'enables smime with custom key and cert' do
|
|
|
|
custom_key = '/custom/key'
|
|
|
|
custom_cert = '/custom/cert'
|
2020-05-24 23:13:21 +05:30
|
|
|
custom_ca_certs = '/custom/ca_certs'
|
2019-12-04 20:38:33 +05:30
|
|
|
custom_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'key_file' => custom_key,
|
2020-05-24 23:13:21 +05:30
|
|
|
'cert_file' => custom_cert,
|
|
|
|
'ca_certs_file' => custom_ca_certs
|
2019-12-04 20:38:33 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
parsed_settings = described_class.parse(custom_settings)
|
|
|
|
|
|
|
|
expect(parsed_settings['enabled']).to be(true)
|
|
|
|
expect(parsed_settings['key_file']).to eq(custom_key)
|
|
|
|
expect(parsed_settings['cert_file']).to eq(custom_cert)
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(parsed_settings['ca_certs_file']).to eq(custom_ca_certs)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|