spec/logstash/outputs/scalyr_integration_spec.rb in logstash-output-scalyr-0.2.6 vs spec/logstash/outputs/scalyr_integration_spec.rb in logstash-output-scalyr-0.2.7.beta

- old
+ new

@@ -8,10 +8,12 @@ # Require the specific version of `json` used in logstash gem 'json', '1.8.6' require 'json' +EXAMPLE_COME_CA_CERTS_PATH = File.expand_path(File.join(File.dirname(__FILE__), + "/fixtures/example_com.pem")) + WebMock.allow_net_connect! RSpec.configure do |rspec| rspec.expect_with :rspec do |c| c.max_formatted_output_length = nil @@ -62,54 +64,39 @@ } ) end end - context "when pointing at a location without any valid certs and not using builtin" do - it "throws an SSLError" do + context "when pointing at an invalid location (doesnt exist) without any valid certs" do + it "throws an Errno::ENOENT error" do plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, 'max_retries' => 2, 'retry_max_interval' => 2, 'retry_initial_interval' => 0.2, }) - plugin.register - plugin.instance_variable_set(:@running, false) - allow(plugin.instance_variable_get(:@logger)).to receive(:warn) - plugin.multi_receive(sample_events) - expect(plugin.instance_variable_get(:@logger)).to have_received(:warn).with("Error uploading to Scalyr (will backoff-retry)", - { - :error_class=>"Manticore::UnknownException", - :batch_num=>1, - :message=>"Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty", - #:message=>"java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty", - :payload_size=>737, - :record_count=>3, - :total_batches=>1, - :url=>"https://agent.scalyr.com/addEvents", - :will_retry_in_seconds=>0.4 - } - ) + + expect { + plugin.register + }.to raise_error(Errno::ENOENT, /Invalid path for ssl_ca_bundle_path config option - file doesn't exist or is not readable/) end end - context "when system certs are missing and not using builtin" do + context "when pointing to an empty certs file" do it "throws an SSLError" do - `sudo mv #{OpenSSL::X509::DEFAULT_CERT_FILE} /tmp/system_cert.pem` - `sudo mv #{OpenSSL::X509::DEFAULT_CERT_DIR} /tmp/system_certs` + temp_file = file = Tempfile.new('emot_certs_file') begin plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, - 'append_builtin_cert' => false, 'max_retries' => 2, 'retry_max_interval' => 2, 'retry_initial_interval' => 0.2, + 'ssl_ca_bundle_path' => temp_file.path }) plugin.register plugin.instance_variable_set(:@running, false) allow(plugin.instance_variable_get(:@logger)).to receive(:warn) plugin.multi_receive(sample_events) @@ -125,13 +112,12 @@ :url=>"https://agent.scalyr.com/addEvents", :will_retry_in_seconds=>0.4 } ) end - ensure - `sudo mv /tmp/system_certs #{OpenSSL::X509::DEFAULT_CERT_DIR}` - `sudo mv /tmp/system_cert.pem #{OpenSSL::X509::DEFAULT_CERT_FILE}` + ensure + temp_file.unlink end end context "when server hostname doesn't match the cert" do it "throws an SSLError" do @@ -178,28 +164,27 @@ `echo "#{hosts_bkp}" | sudo tee -a /etc/hosts` end end end - context "when an error occurs with retries at 15" do - it "exits after 5 retries and emits a log" do - plugin = LogStash::Outputs::Scalyr.new({ - 'api_write_token' => '1234', - 'perform_connectivity_check' => false, - 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, - 'max_retries' => 15, - 'retry_max_interval' => 0.5, - 'retry_initial_interval' => 0.2, - }) - plugin.register - allow(plugin.instance_variable_get(:@logger)).to receive(:error) - plugin.multi_receive(sample_events) - expect(plugin.instance_variable_get(:@logger)).to have_received(:error).with("Failed to send 3 events after 15 tries.", anything - ) - end + context "when an error occurs with retries at 15 and invalid example_com cert" do + it "exits after 15 retries and emits a log" do + plugin = LogStash::Outputs::Scalyr.new({ + 'api_write_token' => '1234', + 'perform_connectivity_check' => false, + 'ssl_ca_bundle_path' => EXAMPLE_COME_CA_CERTS_PATH, + 'max_retries' => 15, + 'retry_max_interval' => 0.2, + 'retry_initial_interval' => 0.1, + }) + plugin.register + allow(plugin.instance_variable_get(:@logger)).to receive(:error) + plugin.multi_receive(sample_events) + expect(plugin.instance_variable_get(:@logger)).to have_received(:error).with("Failed to send 3 events after 15 tries.", anything + ) end + end end describe "response_handling_tests" do context "when receiving a 503 response" do it "don't throw an error but do log one to debug" do @@ -207,15 +192,14 @@ to_return(status: 503, body: "stubbed response", headers: {}) plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, - 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, + 'ssl_ca_bundle_path' => EXAMPLE_COME_CA_CERTS_PATH, 'max_retries' => 2, - 'retry_max_interval' => 2, - 'retry_initial_interval' => 0.2, + 'retry_max_interval' => 0.2, + 'retry_initial_interval' => 0.1, }) plugin.register plugin.instance_variable_set(:@running, false) allow(plugin.instance_variable_get(:@logger)).to receive(:debug) @@ -228,11 +212,11 @@ :message=>"Invalid JSON response from server", :payload_size=>737, :record_count=>3, :total_batches=>1, :url=>"https://agent.scalyr.com/addEvents", - :will_retry_in_seconds=>0.4, + :will_retry_in_seconds=>0.2, :body=>"stubbed response" } ) end end @@ -243,15 +227,14 @@ to_return(status: 500, body: "stubbed response", headers: {}) plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, - 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, + 'ssl_ca_bundle_path' => EXAMPLE_COME_CA_CERTS_PATH, 'max_retries' => 2, - 'retry_max_interval' => 2, - 'retry_initial_interval' => 0.2, + 'retry_max_interval' => 0.2, + 'retry_initial_interval' => 0.1, }) plugin.register plugin.instance_variable_set(:@running, false) allow(plugin.instance_variable_get(:@logger)).to receive(:warn) @@ -264,11 +247,11 @@ :message=>"Invalid JSON response from server", :payload_size=>737, :record_count=>3, :total_batches=>1, :url=>"https://agent.scalyr.com/addEvents", - :will_retry_in_seconds=>0.4, + :will_retry_in_seconds=>0.2, :body=>"stubbed response" } ) end end @@ -279,15 +262,14 @@ to_return(status: 500, body: "0123456789" * 52, headers: {}) plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, - 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, + 'ssl_ca_bundle_path' => EXAMPLE_COME_CA_CERTS_PATH, 'max_retries' => 2, - 'retry_max_interval' => 2, - 'retry_initial_interval' => 0.2, + 'retry_max_interval' => 0.2, + 'retry_initial_interval' => 0.1, }) plugin.register plugin.instance_variable_set(:@running, false) allow(plugin.instance_variable_get(:@logger)).to receive(:warn) @@ -300,11 +282,11 @@ :message=>"Invalid JSON response from server", :payload_size=>737, :record_count=>3, :total_batches=>1, :url=>"https://agent.scalyr.com/addEvents", - :will_retry_in_seconds=>0.4, + :will_retry_in_seconds=>0.2, :body=>("0123456789" * 50) + "012345678..." } ) end end @@ -316,14 +298,13 @@ to_return(status: 500, body: "stubbed response", headers: {}) plugin = LogStash::Outputs::Scalyr.new({ 'api_write_token' => '1234', 'perform_connectivity_check' => false, - 'ssl_ca_bundle_path' => '/fakepath/nocerts', - 'append_builtin_cert' => false, + 'ssl_ca_bundle_path' => EXAMPLE_COME_CA_CERTS_PATH, 'max_retries' => 2, - 'retry_max_interval' => 2, - 'retry_initial_interval' => 0.2, + 'retry_max_interval' => 0.2, + 'retry_initial_interval' => 0.1, }) plugin.register plugin.instance_variable_set(:@running, false) plugin.instance_variable_set('@dlq_writer', dlq_writer)