|
23 | 23 | context 'when getting the latest version of a secret' do |
24 | 24 | it 'defaults to using an empty string as the latest version' do |
25 | 25 | expect(TragicCode::Azure).to receive(:get_access_token).with(api_versions_hash['metadata_api_version']).and_return(access_token) |
26 | | - expect(TragicCode::Azure).to receive(:get_secret).with(vault_name, secret_name, api_versions_hash['vault_api_version'], access_token, '') |
| 26 | + expect(TragicCode::Azure).to receive(:get_secret).with(vault_name, secret_name, api_versions_hash['vault_api_version'], access_token, '').and_return(secret_value) |
27 | 27 |
|
28 | 28 | is_expected.to run.with_params(vault_name, secret_name, api_versions_hash) |
29 | 29 | end |
|
32 | 32 | context 'when getting a specific version of a secret' do |
33 | 33 | it 'uses the secret version when retreiving the secret' do |
34 | 34 | expect(TragicCode::Azure).to receive(:get_access_token).with(api_versions_hash['metadata_api_version']).and_return(access_token) |
35 | | - expect(TragicCode::Azure).to receive(:get_secret).with(vault_name, secret_name, api_versions_hash['vault_api_version'], access_token, secret_version) |
| 35 | + expect(TragicCode::Azure).to receive(:get_secret).with(vault_name, secret_name, api_versions_hash['vault_api_version'], access_token, secret_version).and_return(secret_value) |
36 | 36 |
|
37 | 37 | is_expected.to run.with_params(vault_name, secret_name, api_versions_hash, secret_version) |
38 | 38 | end |
39 | 39 | end |
40 | 40 |
|
| 41 | + context 'when getting a secret that does not exist in the vault' do |
| 42 | + it 'throws an error' do |
| 43 | + expect(TragicCode::Azure).to receive(:get_access_token).with(api_versions_hash['metadata_api_version']).and_return(access_token) |
| 44 | + expect(TragicCode::Azure).to receive(:get_secret).with(vault_name, secret_name, api_versions_hash['vault_api_version'], access_token, secret_version).and_return(nil) |
| 45 | + |
| 46 | + is_expected.to run.with_params( |
| 47 | + vault_name, secret_name, api_versions_hash, secret_version |
| 48 | + ).and_raise_error(Puppet::Error, %r{The secret named #{secret_name} could not be found in a vault named #{vault_name}}i) |
| 49 | + end |
| 50 | + end |
| 51 | + |
41 | 52 | # rubocop:disable RSpec/NamedSubject |
42 | 53 | it 'returns the secret' do |
43 | 54 | expect(TragicCode::Azure).to receive(:get_access_token).with(api_versions_hash['metadata_api_version']).and_return(access_token) |
|
0 commit comments