Sha256: 315f004d8be96c9bedd846af61436351de4f8eaeb528ae897bc50d1be743b0d7

Contents?: true

Size: 1.55 KB

Versions: 19

Compression:

Stored size: 1.55 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# RUBY-981 Audit Log

require 'newrelic_rpm'

class AuditLogTest < Minitest::Test
  include MultiverseHelpers

  def setup
    @string_log = StringIO.new
    NewRelic::Agent::AuditLogger.any_instance.stubs(:ensure_log_path).returns(@string_log)
  end

  def audit_log_contents
    if @contents.nil?
      @string_log.rewind
      @contents = @string_log.read
    end
    @contents
  end

  def test_logs_nothing_by_default
    run_agent do
      perform_actions
      assert_equal('', audit_log_contents)
    end
  end

  def test_logs_nothing_when_disabled
    run_agent(:'audit_log.enabled' => false) do
      perform_actions
      assert_equal('', audit_log_contents)
    end
  end

  def test_logs_request_bodies_human_readably_ish
    run_agent(:'audit_log.enabled' => true) do
      perform_actions
      $collector.agent_data.each do |req|
        assert_audit_log_contains_object(audit_log_contents, req.body)
      end
    end
  end

  def perform_actions
    state = NewRelic::Agent::TransactionState.tl_get
    NewRelic::Agent.instance.sql_sampler.on_start_transaction(state, nil)
    NewRelic::Agent.instance.sql_sampler.notice_sql("select * from test",
                                 "Database/test/select",
                                 nil, 1.5, state)
    NewRelic::Agent.instance.sql_sampler.on_finishing_transaction(state, 'txn')
    NewRelic::Agent.instance.send(:harvest_and_send_slowest_sql)
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
newrelic_rpm-4.1.0.333 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-4.0.0.332 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.18.1.330 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.18.0.329 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.17.2.327 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.17.1.326 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.17.0.325 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.16.3.323 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.16.2.321 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.16.1.320 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.16.0.318 test/multiverse/suites/agent_only/audit_log_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.15.2.317 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.15.1.316 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.15.0.314 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.14.3.313 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.14.2.312 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.14.1.311 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.14.0.305 test/multiverse/suites/agent_only/audit_log_test.rb