File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -144,9 +144,8 @@ def api_key(arguments)
144
144
if ( headers = arguments . dig ( :transport_options , :headers ) )
145
145
headers . merge! ( authorization )
146
146
else
147
- arguments [ :transport_options ] = {
148
- headers : authorization
149
- }
147
+ arguments [ :transport_options ] ||= { }
148
+ arguments [ :transport_options ] . merge! ( { headers : authorization } )
150
149
end
151
150
end
152
151
Original file line number Diff line number Diff line change 57
57
end
58
58
end
59
59
60
- context 'when other headers where specified' do
60
+ context 'when other headers were specified' do
61
61
let ( :client ) do
62
62
described_class . new (
63
63
api_key : 'elasticsearch_api_key' ,
72
72
end
73
73
end
74
74
75
+ context 'when sending transport_options but no headers were specified' do
76
+ let ( :client ) do
77
+ described_class . new (
78
+ api_key : 'elasticsearch_api_key' ,
79
+ transport_options : { ssl : { verify : false } }
80
+ )
81
+ end
82
+
83
+ it 'Adds the ApiKey header to the connection and keeps the options' do
84
+ header = client . transport . connections . first . connection . headers
85
+ expect ( header [ 'Authorization' ] ) . to eq ( 'ApiKey elasticsearch_api_key' )
86
+ expect ( client . transport . options [ :transport_options ] ) . to include ( { ssl : { verify : false } } )
87
+ expect ( client . transport . options [ :transport_options ] [ :headers ] ) . to include ( 'Authorization' => 'ApiKey elasticsearch_api_key' )
88
+ end
89
+ end
90
+
91
+ context 'when other headers and options were specified' do
92
+ let ( :client ) do
93
+ described_class . new (
94
+ api_key : 'elasticsearch_api_key' ,
95
+ transport_options : {
96
+ headers : { 'x-test-header' => 'test' } ,
97
+ ssl : { verify : false }
98
+ }
99
+ )
100
+ end
101
+
102
+ it 'Adds the ApiKey header to the connection and keeps the header' do
103
+ header = client . transport . connections . first . connection . headers
104
+ expect ( header [ 'X-Test-Header' ] ) . to eq ( 'test' )
105
+ expect ( header [ 'Authorization' ] ) . to eq ( 'ApiKey elasticsearch_api_key' )
106
+ expect ( client . transport . options [ :transport_options ] ) . to include ( { ssl : { verify : false } } )
107
+ expect ( client . transport . options [ :transport_options ] [ :headers ] ) . to include ( 'Authorization' => 'ApiKey elasticsearch_api_key' )
108
+ end
109
+ end
110
+
75
111
context 'Metaheader' do
76
112
let ( :adapter_code ) { "nh=#{ defined? ( Net ::HTTP ::VERSION ) ? Net ::HTTP ::VERSION : Net ::HTTP ::HTTPVersion } " }
77
113
let ( :meta_header ) do
You can’t perform that action at this time.
0 commit comments