This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flask_nofloc.py
87 lines (58 loc) · 2.43 KB
/
test_flask_nofloc.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from flask import Flask
from flask_nofloc import NoFLoC, add_nofloc_header
def test_direct_instantiation():
app = Flask('DirectApp')
NoFLoC(app)
@app.route('/')
def index():
return ''
with app.test_client() as client:
response = client.get('/')
assert 'Permission-Policy' in response.headers, 'Permission-Policy is not in headers'
assert response.headers['Permission-Policy'] == 'interest-cohort=()', 'Permission-Policy is not interest-cohort=()'
def test_init_app_instantiation():
app = Flask('InitApp')
@app.route('/')
def index():
return ''
nofloc = NoFLoC()
nofloc.init_app(app)
with app.test_client() as client:
response = client.get('/')
assert 'Permission-Policy' in response.headers, 'Permission-Policy is not in headers'
assert response.headers['Permission-Policy'] == 'interest-cohort=()', 'Permission-Policy is not interest-cohort=()'
def test_two_apps():
app1 = Flask('App1')
@app1.route('/')
def index1():
return '1'
app2 = Flask('App2')
@app2.route('/')
def index2():
return '2'
nofloc = NoFLoC()
nofloc.init_app(app1)
nofloc.init_app(app2)
with app1.test_client() as client:
response = client.get('/')
assert 'Permission-Policy' in response.headers, 'Permission-Policy is not in headers for app1'
assert response.headers['Permission-Policy'] == 'interest-cohort=()', 'Permission-Policy is not interest-cohort=() for app1'
with app2.test_client() as client:
response = client.get('/')
assert 'Permission-Policy' in response.headers, 'Permission-Policy is not in headers for app2'
assert response.headers['Permission-Policy'] == 'interest-cohort=()', 'Permission-Policy is not interest-cohort=() for app2'
def test_individual_route():
app = Flask('TestApp')
@app.route('/floc')
def floc():
return 'floc'
@app.route('/nofloc')
@add_nofloc_header
def nofloc():
return 'nofloc'
with app.test_client() as client:
response = client.get('/floc')
assert 'Permission-Policy' not in response.headers, 'Permission-Policy is in headers but should not be'
response = client.get('/nofloc')
assert 'Permission-Policy' in response.headers, 'Permission-Policy is not in headers'
assert response.headers['Permission-Policy'] == 'interest-cohort=()', 'Permission-Policy is not interest-cohort=()'