Sha256: 2113e5388cc516adfcc4763e35919a4afde22ee4a04420555767a31b56add8cd

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 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
      format = NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported? ? :json : :pruby
      $collector.agent_data.each do |req|
        assert_audit_log_contains_object(audit_log_contents, req.body, format)
      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

8 entries across 8 versions & 1 rubygems

Version Path
newrelic_rpm-3.13.2.302 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.13.1.300 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.13.0.299 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.12.1.298 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.12.0.288 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.11.2.286 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.11.1.284 test/multiverse/suites/agent_only/audit_log_test.rb
newrelic_rpm-3.11.0.283 test/multiverse/suites/agent_only/audit_log_test.rb