Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Add test to prevent regression regarding excessive logging #2131

Merged
merged 1 commit into from Jun 10, 2016
Merged

Add test to prevent regression regarding excessive logging #2131

merged 1 commit into from Jun 10, 2016

Conversation

bdewater
Copy link
Contributor

This is the test from #2126 for the master branch.

end

it "logs info about the detected spoof" do
Paperclip.expects(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [232/80]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think capture will read better. Also, by matching what we want to match we'll make the spec less brittle to log string changes. Do you think this would improve the spec?

output = capture(:stdout) do
  run_arbitrary_code
end
assert output =~ /pattern/

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that capturing std_out is better, testing behaviour instead of implementation. The brittleness might not be so bad in this case. A pattern could match against those very long lines of mime-types data which is the regression I am trying to prevent with this test. I'll try and figure something out in the weekend.

@tute
Copy link
Contributor

tute commented May 9, 2016

@bdewater do you have availability to rebase and get this PR ready? Thank you! :)

…our to prevent regressions.

Excessive logging can fill up disk space and become a denial of service attack, see https://cwe.mitre.org/data/definitions/779.html
@bdewater
Copy link
Contributor Author

@tute I've rebased my original PR. I've tried your suggestion and the following to capture log output:

it "logs info about the detected spoof" do
  aggregate_failures do
    expect { spoofed? }.to output(/image\/jpg from Headers/).to_stdout
    expect { spoofed? }.to output(/\["text\/html"\] from Extension/).to_stdout
    expect { spoofed? }.to output(/file command: text\/html/).to_stdout
  end
end

but the output is always an empty string. I don't have time to work on this for at least the next two weeks unfortunately.

@tute tute merged commit 6819fac into thoughtbot:master Jun 10, 2016
@tute
Copy link
Contributor

tute commented Jun 10, 2016

Thank you! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants