summaryrefslogtreecommitdiff
path: root/docs/chipy-presentation/simple-scripttranscluder-example.py
blob: ad827d5fca61a995de8d79b6a196b2eced4cd0db (plain)
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
from webtest import TestApp
from scripttranscluder.wsgiapp import make_app

app = TestApp(make_app({}, True, ['http://*.org/*']))

def test_denial():
    app.get('/?url=http://google.com', status=403)
    app.get('/?url=http://wikipedia.org', status=200)
    app.get('/?url=http://google.com', extra_environ=dict(HTTP_HOST='google.com'))

def test_js():
    res = app.get('/?url=http://wikipedia.org')
    assert res.body.startswith('document.write')
    assert res.body.strip().endswith(';')
    assert res.content_type == 'text/javascript'
    res2 = app.get('/?url=http://wikipedia.org/#globalWrapper')
    assert res2.body != res.body
    assert len(res2.body) < len(res.body)
    res3 = app.get('/?url=http://wikipedia.org&dest=LOC1')
    res3.mustcontain('LOC1')
    res3.mustcontain('innerHTML')
    assert len(res3.body) > len(res.body)