ref: master
vendor/plugins/xss_terminate/test/xss_terminate_test.rb
1 2 3 4 5 6 7 8 9 10 11 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
require_relative 'setup_test' class XssTerminateTest < Test::Unit::TestCase XssTerminate.sanitize_by_default = true def test_sanitize_by_default_is_true assert XssTerminate.sanitize_by_default end def test_strip_tags_on_discovered_fields c = Comment.create!(:title => "<script>alert('xss in title')</script>", :body => "<script>alert('xss in body')</script>") assert_equal "alert('xss in title')", c.title assert_equal "alert('xss in body')", c.body end def test_rails_sanitization_on_specified_fields e = Entry.create!(:title => "<script>alert('xss in title')</script>", :body => "<script>alert('xss in body')</script>", :extended => "<script>alert('xss in extended')</script>", :person_id => 1) assert_equal [:body, :extended], e.xss_terminate_options[:only] assert_equal "alert('xss in title')", e.title assert_equal "", e.body assert_equal "", e.extended end def test_excepting_specified_fields p = Person.create!(:name => "<strong>Mallory</strong>") assert_equal [:name], p.xss_terminate_options[:except] assert_equal "<strong>Mallory</strong>", p.name end def test_html5lib_sanitization_on_specified_fields r = Review.create!(:title => "<script>alert('xss in title')</script>", :body => "<script>alert('xss in body')</script>", :extended => "<script>alert('xss in extended')</script>", :person_id => 1) assert_equal [:body, :extended], r.xss_terminate_options[:html5lib_sanitize] assert_equal "alert('xss in title')", r.title assert_equal "<script>alert('xss in body')</script>", r.body assert_equal "<script>alert('xss in extended')</script>", r.extended end ### Tests for new features (the API rewriten) def test_onlying_specified_fields p = Message.create!(:body => "<strong>Mallory</strong>") assert_equal [:body], p.xss_terminate_options[:only] assert_equal "Mallory", p.body end end |