|
6 | 6 | 'vault_name' => 'vault_name', |
7 | 7 | 'vault_api_version' => 'vault_api_version', |
8 | 8 | 'metadata_api_version' => 'metadata_api_version', |
| 9 | + 'confine_to_keys' => [%r{^.*sensitive_azure.*}], |
9 | 10 | } |
10 | 11 | end |
11 | 12 | let(:lookup_context) do |
|
28 | 29 | end |
29 | 30 | it 'validates the :options hash' do |
30 | 31 | is_expected.to run.with_params( |
31 | | - 'secret_name', { 'key1' => 'value1' }, lookup_context |
| 32 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', { 'key1' => 'value1' }, lookup_context |
32 | 33 | ).and_raise_error(ArgumentError) |
33 | 34 | end |
34 | 35 | it 'uses the cache' do |
35 | | - expect(lookup_context).to receive(:cache_has_key).with('secret-name').and_return(true) |
36 | | - expect(lookup_context).to receive(:cached_value).with('secret-name').and_return('value') |
| 36 | + expect(lookup_context).to receive(:cache_has_key).with('profile--windows--sqlserver--sensitive-azure-sql-user-password').and_return(true) |
| 37 | + expect(lookup_context).to receive(:cached_value).with('profile--windows--sqlserver--sensitive-azure-sql-user-password').and_return('value') |
37 | 38 | is_expected.to run.with_params( |
38 | | - 'secret_name', options, lookup_context |
| 39 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
39 | 40 | ).and_return('value') |
40 | 41 | end |
41 | 42 | it 'caches the access token after a cache miss' do |
|
48 | 49 | expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
49 | 50 | expect(lookup_context).to receive(:cache).and_return(secret_value).ordered |
50 | 51 | is_expected.to run.with_params( |
51 | | - 'secret_name', options, lookup_context |
| 52 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
52 | 53 | ).and_return(secret_value) |
53 | 54 | end |
54 | 55 |
|
|
60 | 61 | end |
61 | 62 |
|
62 | 63 | it 'uses - as the default key_replacement_token' do |
63 | | - secret_name = 'profile::windows::sqlserver::sensitive_sql_user_password' |
| 64 | + secret_name = 'profile::windows::sqlserver::sensitive_azure_sql_user_password' |
64 | 65 | access_token_value = 'access_value' |
65 | 66 | secret_value = 'secret_value' |
66 | 67 | expect(TragicCode::Azure).to receive(:normalize_object_name).with(secret_name, '-') |
67 | 68 | expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
68 | 69 | expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
69 | 70 | is_expected.to run.with_params( |
70 | | - 'profile::windows::sqlserver::sensitive_sql_user_password', options, lookup_context |
| 71 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
71 | 72 | ).and_return(secret_value) |
72 | 73 | end |
| 74 | + |
| 75 | + it 'errors when confine_to_keys is no array' do |
| 76 | + is_expected.to run.with_params( |
| 77 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => '^vault.*$' }), lookup_context |
| 78 | + ).and_raise_error(ArgumentError, %r{'confine_to_keys' expects an Array value}i) |
| 79 | + end |
| 80 | + |
| 81 | + it 'errors when passing invalid regexes' do |
| 82 | + is_expected.to run.with_params( |
| 83 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => ['['] }), lookup_context |
| 84 | + ).and_raise_error(ArgumentError, %r{'confine_to_keys' index 0 expects a Regexp value}i) |
| 85 | + end |
| 86 | + |
| 87 | + it 'returns the key if regex matches confine_to_keys' do |
| 88 | + access_token_value = 'access_value' |
| 89 | + secret_value = 'secret_value' |
| 90 | + expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
| 91 | + expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
| 92 | + is_expected.to run.with_params( |
| 93 | + 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => [%r{^.*sensitive_azure.*}] }), lookup_context |
| 94 | + ).and_return(secret_value) |
| 95 | + end |
| 96 | + |
| 97 | + it 'does not return the key if regex does not match confine_to_keys' do |
| 98 | + access_token_value = 'access_value' |
| 99 | + secret_value = 'secret_value' |
| 100 | + |
| 101 | + expect(lookup_context).to receive(:not_found) |
| 102 | + expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
| 103 | + expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
| 104 | + |
| 105 | + is_expected.to run.with_params( |
| 106 | + 'profile::windows::sqlserver::sensitive_sql_user_password', options.merge({ 'confine_to_keys' => [%r{^sensitive_azure.*$}] }), lookup_context |
| 107 | + ) |
| 108 | + end |
73 | 109 | end |
0 commit comments