Skip to content
Myr

test_security.py

This file

Path

tests/test_security.py

67 lines · 1.6 KiB · Python

Last changed by

some more doc changes in jinja for the upcoming releaseArmin Ronacherbefore adoption825e522

History of this file

Take it

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 1–8why, one step back
1# -*- coding: utf-8 -*-
2"""3 unit test for security features4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~56 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""

some more doc changes in jinja for the upcoming releaseArmin Ronacherbefore adoption825e522

line 9why, one step back
9from jinja import Environment

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 10–11why, one step back
10
11

some more doc changes in jinja for the upcoming releaseArmin Ronacherbefore adoption825e522

lines 12–18why, one step back
12NONLOCALSET = '''\
13{% for item in range(10) %}14 {%- set outer = item! -%}15{% endfor -%}16{{ outer }}'''1718

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 19–53why, one step back
19class PrivateStuff(object):
20 bar = lambda self: 2321 foo = lambda self: 4222 foo.jinja_unsafe_call = True232425class PublicStuff(object):26 jinja_allowed_attributes = ['bar']27 bar = lambda self: 2328 foo = lambda self: 42293031test_unsafe = '''32>>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PrivateStuff())33u''34>>> env.from_string("{{ foo.bar() }}").render(foo=MODULE.PrivateStuff())35u'23'3637>>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PublicStuff())38u''39>>> env.from_string("{{ foo.bar() }}").render(foo=MODULE.PublicStuff())40u'23'4142>>> env.from_string("{{ foo.__class__ }}").render(foo=42)43u''4445>>> env.from_string("{{ foo.func_code }}").render(foo=lambda:None)46u''47'''484950test_restricted = '''51>>> env.from_string("{% for item.attribute in seq %}...{% endfor %}")52Traceback (most recent call last):53 ...

[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c

line 54why, one step back
54TemplateSyntaxError: cannot assign to expression (line 1)

[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b

lines 55–57why, one step back
55>>> env.from_string("{% for foo, bar.baz in seq %}...{% endfor %}")
56Traceback (most recent call last):57 ...

[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c

line 58why, one step back
58TemplateSyntaxError: cannot assign to expression (line 1)

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

line 59why, one step back
59'''

some more doc changes in jinja for the upcoming releaseArmin Ronacherbefore adoption825e522

lines 60–67why, one step back
60
6162def test_nonlocal_set():63 env = Environment()64 env.globals['outer'] = 4265 tmpl = env.from_string(NONLOCALSET)66 assert tmpl.render() == '9'67 assert env.globals['outer'] == 42