aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-01 09:05:34 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-01 09:05:34 -0800
commitc60c1c0812d5eb55e7024db350f8bc5b6729f7fe (patch)
tree8665043df7d6705bc5cc41daf59fc2041126ff41 /activesupport/test
parentecff25cda6917a07c7bcb4ed0865c75d16164306 (diff)
parent55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07 (diff)
downloadrails-c60c1c0812d5eb55e7024db350f8bc5b6729f7fe.tar.gz
rails-c60c1c0812d5eb55e7024db350f8bc5b6729f7fe.tar.bz2
rails-c60c1c0812d5eb55e7024db350f8bc5b6729f7fe.zip
Merge branch '3-2-stable-security' into 3-2-2
* 3-2-stable-security: Ensure [] respects the status of the buffer. delete vulnerable AS::SafeBuffer#[] use AS::SafeBuffer#clone_empty for flushing the output_buffer add AS::SafeBuffer#clone_empty fix output safety issue with select options
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/safe_buffer_test.rb47
1 files changed, 38 insertions, 9 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index db9159b289..25c95f2a2f 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -89,31 +89,60 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_equal "hello&lt;&gt;", clean + @buffer
end
- test "Should concat as a normal string when dirty" do
+ test "Should concat as a normal string when safe" do
clean = "hello".html_safe
@buffer.gsub!('', '<>')
assert_equal "<>hello", @buffer + clean
end
- test "Should preserve dirty? status on copy" do
+ test "Should preserve html_safe? status on copy" do
@buffer.gsub!('', '<>')
assert !@buffer.dup.html_safe?
end
- test "Should raise an error when safe_concat is called on dirty buffers" do
+ test "Should return safe buffer when added with another safe buffer" do
+ clean = "<script>".html_safe
+ result_buffer = @buffer + clean
+ assert result_buffer.html_safe?
+ assert_equal "<script>", result_buffer
+ end
+
+ test "Should raise an error when safe_concat is called on unsafe buffers" do
@buffer.gsub!('', '<>')
assert_raise ActiveSupport::SafeBuffer::SafeConcatError do
@buffer.safe_concat "BUSTED"
end
end
-
- test "should not fail if the returned object is not a string" do
+
+ test "Should not fail if the returned object is not a string" do
assert_kind_of NilClass, @buffer.slice("chipchop")
end
- test "Should initialize @dirty to false for new instance when sliced" do
- dirty = @buffer[0,0].send(:dirty?)
- assert_not_nil dirty
- assert !dirty
+ test "clone_empty returns an empty buffer" do
+ assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty
+ end
+
+ test "clone_empty keeps the original dirtyness" do
+ assert @buffer.clone_empty.html_safe?
+ assert !@buffer.gsub!('', '').clone_empty.html_safe?
+ end
+
+ test "Should be safe when sliced if original value was safe" do
+ new_buffer = @buffer[0,0]
+ assert_not_nil new_buffer
+ assert new_buffer.html_safe?, "should be safe"
+ end
+
+ test "Should continue unsafe on slice" do
+ x = 'foo'.html_safe.gsub!('f', '<script>alert("lolpwnd");</script>')
+
+ # calling gsub! makes the dirty flag true
+ assert !x.html_safe?, "should not be safe"
+
+ # getting a slice of it
+ y = x[0..-1]
+
+ # should still be unsafe
+ assert !y.html_safe?, "should not be safe"
end
end