@@ -823,26 +823,28 @@ def synchronize_method!(object, method_name)
823
823
end
824
824
825
825
context "with ssl" do
826
- let ( :config ) { super ( ) . merge ( "ssl_enabled" => true ) }
827
- encoded_api_key = Base64 . strict_encode64 ( 'foo:bar' )
826
+ let ( :api_key_value ) { nil }
827
+ let ( :config ) { super ( ) . merge ( "ssl_enabled" => true , 'api_key' => LogStash ::Util ::Password . new ( api_key_value ) ) }
828
+ let ( :encoded_api_key ) { Base64 . strict_encode64 ( 'foo:bar' ) }
828
829
829
- scenarios = {
830
- 'with non-encoded api-key' => LogStash ::Util ::Password . new ( 'foo:bar' ) ,
831
- 'with encoded api-key' => LogStash ::Util ::Password . new ( encoded_api_key )
832
- }
830
+ shared_examples "a plugin that sets the ApiKey authorization header" do
831
+ it "correctly sets the Authorization header" do
832
+ plugin . register
833
+ client = plugin . send ( :client )
834
+ auth_header = extract_transport ( client ) . options [ :transport_options ] [ :headers ] [ 'Authorization' ]
833
835
834
- scenarios . each do | description , api_key_value |
835
- context description do
836
- let ( :config ) { super ( ) . merge ( 'api_key' => api_key_value ) }
836
+ expect ( auth_header ) . to eql ( "ApiKey #{ encoded_api_key } " )
837
+ end
838
+ end
837
839
838
- it "should set authorization " do
839
- plugin . register
840
- client = plugin . send ( :client )
841
- auth_header = extract_transport ( client ) . options [ :transport_options ] [ :headers ] [ 'Authorization' ]
840
+ context "with a non-encoded API key " do
841
+ let ( :api_key_value ) { "foo:bar" }
842
+ it_behaves_like "a plugin that sets the ApiKey authorization header"
843
+ end
842
844
843
- expect ( auth_header ) . to eql "ApiKey #{ encoded_api_key } "
844
- end
845
- end
845
+ context "with an encoded API key" do
846
+ let ( :api_key_value ) { encoded_api_key }
847
+ it_behaves_like "a plugin that sets the ApiKey authorization header"
846
848
end
847
849
848
850
context 'user also set' do
0 commit comments