|
15 | 15 | expect(wrappers).to include(ScanSuppressingLogger::RollbarWrapper) |
16 | 16 | end |
17 | 17 | end |
| 18 | + |
| 19 | + describe 'Replacing Rails::Rack::Logger' do |
| 20 | + it 'replaces Rails::Rack::Logger with ScanSuppressingLogger::Middleware' do |
| 21 | + expect(Rails.application.middleware).to include(ScanSuppressingLogger::Middleware) |
| 22 | + expect(Rails.application.middleware).not_to include(Rails::Rack::Logger) |
| 23 | + end |
| 24 | + |
| 25 | + context 'from a suppressed address' do |
| 26 | + it 'does not log the request' do |
| 27 | + # Expect the middleware to be called |
| 28 | + expect_any_instance_of(ScanSuppressingLogger::Middleware).to receive(:call).and_call_original |
| 29 | + # Expect the logger to report it was suppressed |
| 30 | + expect(Rails.logger).to receive(:info).with('Suppressed for 127.0.0.1') |
| 31 | + # Do not expect the original Rails::Rack::Logger to be called |
| 32 | + expect_any_instance_of(Rails::Rack::Logger).not_to receive(:call) |
| 33 | + |
| 34 | + # Make a simulated request to the app |
| 35 | + env = Rack::MockRequest.env_for('http://example.org/', 'REMOTE_ADDR' => '127.0.0.1') |
| 36 | + status, headers, body = Rails.application.call(env) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'from a non-suppressed address' do |
| 41 | + it 'logs the request' do |
| 42 | + # Expect the original Rails::Rack::Logger to be called |
| 43 | + expect_any_instance_of(Rails::Rack::Logger).to receive(:call).and_call_original |
| 44 | + |
| 45 | + # Make a simulated request to the app |
| 46 | + env = Rack::MockRequest.env_for('/', 'REMOTE_ADDR' => '192.0.2.1') |
| 47 | + status, headers, body = Rails.application.call(env) |
| 48 | + end |
| 49 | + end |
| 50 | + end |
18 | 51 | end |
0 commit comments