mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
Add tainting tests
This commit is contained in:
@@ -48,6 +48,10 @@ class ProductDrop < Liquid::Drop
|
|||||||
ContextDrop.new
|
ContextDrop.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_input
|
||||||
|
"foo".taint
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def callmenot
|
def callmenot
|
||||||
"protected"
|
"protected"
|
||||||
@@ -108,6 +112,30 @@ class DropsTest < Minitest::Test
|
|||||||
assert_equal ' ', tpl.render!('product' => ProductDrop.new)
|
assert_equal ' ', tpl.render!('product' => ProductDrop.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rendering_raises_on_tainted_attr
|
||||||
|
Liquid::Template.taint_mode = :error
|
||||||
|
tpl = Liquid::Template.parse('{{ product.user_input }}')
|
||||||
|
assert_raises TaintedError do
|
||||||
|
tpl.render!('product' => ProductDrop.new)
|
||||||
|
end
|
||||||
|
Liquid::Template.taint_mode = :lax
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_warns_on_tainted_attr
|
||||||
|
Liquid::Template.taint_mode = :warn
|
||||||
|
tpl = Liquid::Template.parse('{{ product.user_input }}')
|
||||||
|
tpl.render!('product' => ProductDrop.new)
|
||||||
|
assert_match /tainted/, tpl.warnings.first
|
||||||
|
Liquid::Template.taint_mode = :lax
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_doesnt_raise_on_escaped_tainted_attr
|
||||||
|
Liquid::Template.taint_mode = :error
|
||||||
|
tpl = Liquid::Template.parse('{{ product.user_input | escape }}')
|
||||||
|
tpl.render!('product' => ProductDrop.new)
|
||||||
|
Liquid::Template.taint_mode = :lax
|
||||||
|
end
|
||||||
|
|
||||||
def test_drop_does_only_respond_to_whitelisted_methods
|
def test_drop_does_only_respond_to_whitelisted_methods
|
||||||
assert_equal "", Liquid::Template.parse("{{ product.inspect }}").render!('product' => ProductDrop.new)
|
assert_equal "", Liquid::Template.parse("{{ product.inspect }}").render!('product' => ProductDrop.new)
|
||||||
assert_equal "", Liquid::Template.parse("{{ product.pretty_inspect }}").render!('product' => ProductDrop.new)
|
assert_equal "", Liquid::Template.parse("{{ product.pretty_inspect }}").render!('product' => ProductDrop.new)
|
||||||
|
|||||||
Reference in New Issue
Block a user