Cors: Accept array for ListOpts

The following four parameters of cors middleware are ListOpt, thus
accepting array for these options allows users to define parameters
in a similar format.

 - allowed_origin
 - expose_headers
 - allow_methods
 - allow_headers

Change-Id: I4478d209c23e7468e6f36fe417acc01d7b986938
This commit is contained in:
Takashi Kajinami 2021-05-12 00:00:25 +09:00
parent d9fe90e35c
commit 769ff6dec9
2 changed files with 43 additions and 4 deletions

View File

@ -49,12 +49,12 @@ define oslo::cors(
) {
$cors_options = {
'cors/allowed_origin' => { value => $allowed_origin },
'cors/allowed_origin' => { value => join(any2array($allowed_origin), ',') },
'cors/allow_credentials' => { value => $allow_credentials },
'cors/expose_headers' => { value => $expose_headers },
'cors/expose_headers' => { value => join(any2array($expose_headers), ',') },
'cors/max_age' => { value => $max_age },
'cors/allow_methods' => { value => $allow_methods },
'cors/allow_headers' => { value => $allow_headers }
'cors/allow_methods' => { value => join(any2array($allow_methods), ',') },
'cors/allow_headers' => { value => join(any2array($allow_headers), ',') }
}
create_resources($name, $cors_options)
}

View File

@ -15,7 +15,46 @@ describe 'oslo::cors' do
is_expected.to contain_keystone_config('cors/allow_methods').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/allow_headers').with_value('<SERVICE DEFAULT>')
end
end
context 'with parameters' do
let (:params) do
{
:allowed_origin => 'https://horizon.example.com,https://horizon.example2.com',
:allow_credentials => true,
:expose_headers => 'HeaderOne,HeaderTwo',
:max_age => 3600,
:allow_methods => 'GET,HEAD',
:allow_headers => 'HeaderThree,HeaderFour',
}
end
it 'configure cors params' do
is_expected.to contain_keystone_config('cors/allowed_origin').with_value('https://horizon.example.com,https://horizon.example2.com')
is_expected.to contain_keystone_config('cors/allow_credentials').with_value(true)
is_expected.to contain_keystone_config('cors/expose_headers').with_value('HeaderOne,HeaderTwo')
is_expected.to contain_keystone_config('cors/max_age').with_value(3600)
is_expected.to contain_keystone_config('cors/allow_methods').with_value('GET,HEAD')
is_expected.to contain_keystone_config('cors/allow_headers').with_value('HeaderThree,HeaderFour')
end
end
context 'with parameters in array' do
let (:params) do
{
:allowed_origin => ['https://horizon.example.com', 'https://horizon.example2.com'],
:expose_headers => ['HeaderOne', 'HeaderTwo'],
:allow_methods => ['GET', 'HEAD'],
:allow_headers => ['HeaderThree', 'HeaderFour'],
}
end
it 'configure cors params' do
is_expected.to contain_keystone_config('cors/allowed_origin').with_value('https://horizon.example.com,https://horizon.example2.com')
is_expected.to contain_keystone_config('cors/expose_headers').with_value('HeaderOne,HeaderTwo')
is_expected.to contain_keystone_config('cors/allow_methods').with_value('GET,HEAD')
is_expected.to contain_keystone_config('cors/allow_headers').with_value('HeaderThree,HeaderFour')
end
end
end