|
211 | 211 | let(:config) { DatadogAPIClient::Configuration.new } |
212 | 212 | let(:api_client) { DatadogAPIClient::APIClient.new(config) } |
213 | 213 |
|
214 | | - context 'when bearer token (PAT) is configured' do |
| 214 | + context 'when all auth credentials are configured' do |
215 | 215 | before do |
216 | 216 | config.api_key = 'test_api_key' |
217 | 217 | config.application_key = 'test_app_key' |
218 | 218 | config.access_token = 'ddpat_test_pat' |
219 | 219 | end |
220 | 220 |
|
221 | | - it 'sends only Bearer Authorization header, no API key or app key' do |
| 221 | + it 'sends all configured auth headers simultaneously' do |
222 | 222 | header_params = {} |
223 | 223 | query_params = {} |
224 | | - api_client.update_params_for_auth!(header_params, query_params, [:apiKeyAuth, :appKeyAuth]) |
| 224 | + api_client.update_params_for_auth!(header_params, query_params, [:apiKeyAuth, :appKeyAuth, :bearerAuth]) |
225 | 225 | expect(header_params['Authorization']).to eq('Bearer ddpat_test_pat') |
226 | | - expect(header_params).not_to have_key('DD-API-KEY') |
227 | | - expect(header_params).not_to have_key('DD-APPLICATION-KEY') |
| 226 | + expect(header_params['DD-API-KEY']).to eq('test_api_key') |
| 227 | + expect(header_params['DD-APPLICATION-KEY']).to eq('test_app_key') |
228 | 228 | end |
| 229 | + end |
229 | 230 |
|
230 | | - it 'sends only Bearer even when bearerAuth is already in auth_names' do |
| 231 | + context 'when only bearer token is configured' do |
| 232 | + before do |
| 233 | + config.access_token = 'ddpat_test_pat' |
| 234 | + end |
| 235 | + |
| 236 | + it 'sends only Bearer header, skips empty API key and app key' do |
231 | 237 | header_params = {} |
232 | 238 | query_params = {} |
233 | 239 | api_client.update_params_for_auth!(header_params, query_params, [:apiKeyAuth, :appKeyAuth, :bearerAuth]) |
|
237 | 243 | end |
238 | 244 | end |
239 | 245 |
|
240 | | - context 'when bearer token is not configured' do |
| 246 | + context 'when only API key and app key are configured' do |
241 | 247 | before do |
242 | 248 | config.api_key = 'test_api_key' |
243 | 249 | config.application_key = 'test_app_key' |
244 | 250 | end |
245 | 251 |
|
246 | | - it 'uses API key and app key, no Bearer header' do |
| 252 | + it 'sends API key and app key, no Bearer header' do |
247 | 253 | header_params = {} |
248 | 254 | query_params = {} |
249 | | - api_client.update_params_for_auth!(header_params, query_params, [:apiKeyAuth, :appKeyAuth]) |
| 255 | + api_client.update_params_for_auth!(header_params, query_params, [:apiKeyAuth, :appKeyAuth, :bearerAuth]) |
250 | 256 | expect(header_params['DD-API-KEY']).to eq('test_api_key') |
251 | 257 | expect(header_params['DD-APPLICATION-KEY']).to eq('test_app_key') |
252 | 258 | expect(header_params).not_to have_key('Authorization') |
|
0 commit comments