report_generation.rb 1.1 KB
Newer Older
1 2 3 4 5 6 7 8
class TestReportGeneration < Test::Unit::TestCase
  Report = Brakeman.run("#{TEST_PATH}/apps/rails3.2").report

  def test_html_sanity
    report = Report.to_html

    assert report.is_a? String
    assert report.match(/\A<!DOCTYPE HTML SYSTEM>.*<\/html>\z/m)
9 10 11
    report.scan(/<a[^>]+>/).each do |a|
      assert a.include?("no-referrer"), "#{a} does not include 'no-referrer'"
    end
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  end

  def test_json_sanity
    report = Report.to_json
    expected_keys = ["scan_info", "warnings", "errors"]

    assert report.is_a? String

    report_hash = MultiJson.load report

    assert (expected_keys - report_hash.keys).empty?, "Expected #{expected_keys - report_hash.keys} to be empty"
  end

  def test_csv_sanity
    report = Report.to_csv

    assert report.is_a? String
  end

  def test_tabs_sanity
    report = Report.to_tabs

    assert report.is_a? String
  end

  def test_text_sanity
J
Justin Collins 已提交
38
    report = Report.to_s
39

J
Justin Collins 已提交
40
    assert report.is_a? String
41
  end
42 43 44 45 46 47

  def test_bad_format_type
    assert_raises RuntimeError do
      Report.format(:to_something_else)
    end
  end
48
end