Sha256: b1ff07aba8acac0232485d3729e236a0182384f8200dacb11ae176f3fa1d4fad

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe Bugsnag::Middleware::Rails3Request do
  before(:each) do
    Bugsnag.configuration.middleware.use(described_class)
  end

  describe "#call" do
    it "sets request metadata" do
      Bugsnag.configuration.set_request_data(:rack_env, {
        "action_dispatch.remote_ip" => "10.2.2.224",
        "action_dispatch.request_id" => "5",
      })
      Bugsnag.notify(BugsnagTestException.new('Grimbles'))

      expect(Bugsnag).to have_sent_notification { |payload, headers|
        event = get_event_from_payload(payload)
        puts event["metaData"].inspect
        expect(event["metaData"]["request"]).to eq({
          "clientIp" => "10.2.2.224",
          "requestId" => "5"
        })
      }
    end

    context "the Remote IP will throw when serialized" do

      it "sets the client IP metdata to [SPOOF]" do
        class SpecialIP
          def to_s
            raise BugsnagTestException.new('oh no')
          end
        end
        Bugsnag.configuration.set_request_data(:rack_env, {
          "action_dispatch.remote_ip" => SpecialIP.new,
          "action_dispatch.request_id" => "5",
        })

        Bugsnag.notify(BugsnagTestException.new('Grimbles'))

        expect(Bugsnag).to have_sent_notification { |payload, headers|
          event = get_event_from_payload(payload)
          puts event["metaData"].inspect
          expect(event["metaData"]["request"]).to eq({
            "clientIp" => "[SPOOF]",
            "requestId" => "5"
          })
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bugsnag-6.6.1 spec/rails3_request_spec.rb
bugsnag-6.6.0 spec/rails3_request_spec.rb
bugsnag-6.5.0 spec/rails3_request_spec.rb
bugsnag-6.3.0.beta.0 spec/rails3_request_spec.rb