debian-mirror-gitlab/spec/config/smime_signature_settings_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe SmimeSignatureSettings, feature_category: :shared 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
2023-07-09 08:55:56 +05:30
custom_settings = GitlabSettings::Options.build({})
2019-12-04 20:38:33 +05:30
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
2023-07-09 08:55:56 +05:30
custom_settings = GitlabSettings::Options.build({
2019-12-04 20:38:33 +05:30
'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'
2023-07-09 08:55:56 +05:30
custom_settings = GitlabSettings::Options.build({
2019-12-04 20:38:33 +05:30
'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