Uses the TagSanitizer in Debate
This commit is contained in:
@@ -13,6 +13,7 @@ class Debate < ActiveRecord::Base
|
|||||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||||
|
|
||||||
before_validation :sanitize_description
|
before_validation :sanitize_description
|
||||||
|
before_validation :sanitize_tag_list
|
||||||
|
|
||||||
def likes
|
def likes
|
||||||
get_likes.size
|
get_likes.size
|
||||||
@@ -40,4 +41,8 @@ class Debate < ActiveRecord::Base
|
|||||||
self.description = WYSIWYGSanitizer.new.sanitize(description)
|
self.description = WYSIWYGSanitizer.new.sanitize(description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize_tag_list
|
||||||
|
self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -62,6 +62,27 @@ feature 'Debates' do
|
|||||||
expect(page.html).to_not include '<script>alert("an attack");</script>'
|
expect(page.html).to_not include '<script>alert("an attack");</script>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'tagging using dangerous strings' do
|
||||||
|
|
||||||
|
author = create(:user)
|
||||||
|
login_as(author)
|
||||||
|
|
||||||
|
visit new_debate_path
|
||||||
|
|
||||||
|
fill_in 'debate_title', with: 'A test'
|
||||||
|
fill_in 'debate_description', with: 'A test'
|
||||||
|
fill_in 'debate_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
|
||||||
|
check 'debate_terms_of_service'
|
||||||
|
|
||||||
|
click_button 'Create Debate'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Debate was successfully created.'
|
||||||
|
expect(page).to have_content 'user_id1'
|
||||||
|
expect(page).to have_content 'a3'
|
||||||
|
expect(page).to have_content 'scriptalert("hey");script'
|
||||||
|
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Update should not be posible if logged user is not the author' do
|
scenario 'Update should not be posible if logged user is not the author' do
|
||||||
debate = create(:debate)
|
debate = create(:debate)
|
||||||
expect(debate).to be_editable
|
expect(debate).to be_editable
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ describe Debate do
|
|||||||
expect(@debate.description).to eq("alert('danger');")
|
expect(@debate.description).to eq("alert('danger');")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should sanitize the tag list" do
|
||||||
|
@debate.tag_list = "user_id=1"
|
||||||
|
@debate.valid?
|
||||||
|
expect(@debate.tag_list).to eq(['user_id1'])
|
||||||
|
end
|
||||||
|
|
||||||
it "should not be valid without accepting terms of service" do
|
it "should not be valid without accepting terms of service" do
|
||||||
@debate.terms_of_service = nil
|
@debate.terms_of_service = nil
|
||||||
expect(@debate).to_not be_valid
|
expect(@debate).to_not be_valid
|
||||||
|
|||||||
Reference in New Issue
Block a user