|
32 | 32 | 'profile::windows::sqlserver::sensitive_azure_sql_user_password', { 'key1' => 'value1' }, lookup_context |
33 | 33 | ).and_raise_error(ArgumentError) |
34 | 34 | end |
| 35 | + |
| 36 | + # rubocop:disable RSpec/NamedSubject |
35 | 37 | it 'uses the cache' do |
36 | 38 | expect(lookup_context).to receive(:cache_has_key).with('profile--windows--sqlserver--sensitive-azure-sql-user-password').and_return(true) |
37 | 39 | expect(lookup_context).to receive(:cached_value).with('profile--windows--sqlserver--sensitive-azure-sql-user-password').and_return('value') |
38 | | - is_expected.to run.with_params( |
39 | | - 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
40 | | - ).and_return('value') |
| 40 | + |
| 41 | + expect(subject.execute('profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context).unwrap).to eq 'value' |
41 | 42 | end |
| 43 | + # rubocop:enable RSpec/NamedSubject |
| 44 | + |
| 45 | + # rubocop:disable RSpec/NamedSubject |
42 | 46 | it 'caches the access token after a cache miss' do |
43 | 47 | access_token_value = 'access_value' |
44 | 48 | secret_value = 'secret_value' |
|
48 | 52 | expect(lookup_context).to receive(:cache).with('access_token', access_token_value).ordered |
49 | 53 | expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
50 | 54 | expect(lookup_context).to receive(:cache).and_return(secret_value).ordered |
51 | | - is_expected.to run.with_params( |
52 | | - 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
53 | | - ).and_return(secret_value) |
| 55 | + |
| 56 | + expect(subject.execute('profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context).unwrap).to eq secret_value |
54 | 57 | end |
| 58 | + # rubocop:enable RSpec/NamedSubject |
55 | 59 |
|
56 | 60 | it 'call context.not_found for the lookup_options key' do |
57 | 61 | expect(lookup_context).to receive(:not_found) |
|
60 | 64 | ) |
61 | 65 | end |
62 | 66 |
|
| 67 | + # rubocop:disable RSpec/NamedSubject |
63 | 68 | it 'uses - as the default key_replacement_token' do |
64 | 69 | secret_name = 'profile::windows::sqlserver::sensitive_azure_sql_user_password' |
65 | 70 | access_token_value = 'access_value' |
66 | 71 | secret_value = 'secret_value' |
67 | 72 | expect(TragicCode::Azure).to receive(:normalize_object_name).with(secret_name, '-') |
68 | 73 | expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
69 | 74 | expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
70 | | - is_expected.to run.with_params( |
71 | | - 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context |
72 | | - ).and_return(secret_value) |
| 75 | + |
| 76 | + expect(subject.execute('profile::windows::sqlserver::sensitive_azure_sql_user_password', options, lookup_context).unwrap).to eq secret_value |
73 | 77 | end |
| 78 | + # rubocop:enable RSpec/NamedSubject |
74 | 79 |
|
75 | 80 | it 'errors when confine_to_keys is no array' do |
76 | 81 | is_expected.to run.with_params( |
|
84 | 89 | ).and_raise_error(ArgumentError, %r{creating regexp failed with}i) |
85 | 90 | end |
86 | 91 |
|
| 92 | + # rubocop:disable RSpec/NamedSubject |
87 | 93 | it 'returns the key if regex matches confine_to_keys' do |
88 | 94 | access_token_value = 'access_value' |
89 | 95 | secret_value = 'secret_value' |
90 | 96 | expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
91 | 97 | 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' => ['^.*sensitive_azure.*'] }), lookup_context |
94 | | - ).and_return(secret_value) |
| 98 | + |
| 99 | + expect(subject.execute('profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => ['^.*sensitive_azure.*'] }), lookup_context).unwrap) |
| 100 | + .to eq secret_value |
95 | 101 | end |
| 102 | + # rubocop:enable RSpec/NamedSubject |
96 | 103 |
|
97 | 104 | it 'does not return the key if regex does not match confine_to_keys' do |
98 | 105 | access_token_value = 'access_value' |
|
118 | 125 | 'profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => ['^.*sensitive_azure.*'] }), lookup_context |
119 | 126 | ) |
120 | 127 | end |
| 128 | + |
| 129 | + # rubocop:disable RSpec/NamedSubject |
| 130 | + it 'returns the secret wrapped in the sensitive data type' do |
| 131 | + access_token_value = 'access_value' |
| 132 | + secret_value = 'secret_value' |
| 133 | + expect(TragicCode::Azure).to receive(:get_access_token).and_return(access_token_value) |
| 134 | + expect(TragicCode::Azure).to receive(:get_secret).and_return(secret_value) |
| 135 | + |
| 136 | + expect(subject.execute('profile::windows::sqlserver::sensitive_azure_sql_user_password', options.merge({ 'confine_to_keys' => ['^.*sensitive_azure.*'] }), lookup_context)) |
| 137 | + .to be_an_instance_of(Puppet::Pops::Types::PSensitiveType::Sensitive) |
| 138 | + end |
| 139 | + # rubocop:enable RSpec/NamedSubject |
121 | 140 | end |
0 commit comments