|
86 | 86 | ).and_raise_error(ArgumentError, %r{'confine_to_keys' expects an Array value}i) |
87 | 87 | end |
88 | 88 |
|
| 89 | + it 'errors when strip_from_keys is no array' do |
| 90 | + is_expected.to run.with_params( |
| 91 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'strip_from_keys' => '^vault.*$' }), lookup_context |
| 92 | + ).and_raise_error(ArgumentError, %r{'strip_from_keys' expects an Array value}i) |
| 93 | + end |
| 94 | + |
89 | 95 | it "errors when using both 'metadata_api_version' and 'service_principal_credentials'" do |
90 | 96 | is_expected.to run.with_params( |
91 | 97 | 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'service_principal_credentials' => 'path' }), lookup_context |
|
131 | 137 | ) |
132 | 138 | end |
133 | 139 |
|
| 140 | + describe 'strip_from_keys' do |
| 141 | + [ |
| 142 | + { |
| 143 | + input_secret_name: 'profile::windows::sqlserver::azure_sql_user_password', |
| 144 | + expected_secret_name: 'profile--windows--sqlserver--sql-user-password', |
| 145 | + secret_value: 'secret_value', |
| 146 | + strip_from_keys: ['azure_'], |
| 147 | + confine_to_keys: ['^.*azure_.*'] |
| 148 | + }, |
| 149 | + { |
| 150 | + input_secret_name: 'profile::windows::sqlserver::azure_sql_user_password', |
| 151 | + expected_secret_name: 'azure-sql-user-password', |
| 152 | + secret_value: 'secret_value', |
| 153 | + strip_from_keys: ['^profile::.*::'], |
| 154 | + confine_to_keys: ['^.*azure_.*'] |
| 155 | + }, |
| 156 | + ].each do |test_case| |
| 157 | + it "strips the patterns #{test_case[:strip_from_keys]} from the secret_name changing it from #{test_case[:input_secret_name]} to #{test_case[:expected_secret_name]}" do |
| 158 | + access_token_value = 'access_value' |
| 159 | + |
| 160 | + expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
| 161 | + |
| 162 | + expect(TragicCode::Azure).to receive(:get_secret).with( |
| 163 | + options['vault_name'], |
| 164 | + test_case[:expected_secret_name], |
| 165 | + options['vault_api_version'], |
| 166 | + access_token_value, |
| 167 | + '', |
| 168 | + ).and_return(test_case[:secret_value]) |
| 169 | + |
| 170 | + # rubocop:disable RSpec/NamedSubject |
| 171 | + expect(subject.execute( |
| 172 | + test_case[:input_secret_name], |
| 173 | + options.merge({ |
| 174 | + 'confine_to_keys' => test_case[:confine_to_keys], |
| 175 | + 'strip_from_keys' => test_case[:strip_from_keys] |
| 176 | + }), |
| 177 | + lookup_context, |
| 178 | + ).unwrap).to eq test_case[:secret_value] |
| 179 | + # rubocop:enable RSpec/NamedSubject |
| 180 | + end |
| 181 | + end |
| 182 | + end |
| 183 | + |
134 | 184 | it 'calls context.not_found when secret is not found in vault' do |
135 | 185 | access_token_value = 'access_value' |
136 | 186 |
|
|
0 commit comments