forked from CTFd/CTFd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_config.py
60 lines (47 loc) · 1.79 KB
/
test_config.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from CTFd.config import TestingConfig
from tests.helpers import create_ctfd, destroy_ctfd, login_as_user, register_user
def test_reverse_proxy_config():
"""Test that REVERSE_PROXY configuration behaves properly"""
class ReverseProxyConfig(TestingConfig):
REVERSE_PROXY = "1,2,3,4"
app = create_ctfd(config=ReverseProxyConfig)
with app.app_context():
assert app.wsgi_app.x_for == 1
assert app.wsgi_app.x_proto == 2
assert app.wsgi_app.x_host == 3
assert app.wsgi_app.x_port == 4
assert app.wsgi_app.x_prefix == 0
destroy_ctfd(app)
class ReverseProxyConfig(TestingConfig):
REVERSE_PROXY = "true"
app = create_ctfd(config=ReverseProxyConfig)
with app.app_context():
assert app.wsgi_app.x_for == 1
assert app.wsgi_app.x_proto == 1
assert app.wsgi_app.x_host == 1
assert app.wsgi_app.x_port == 1
assert app.wsgi_app.x_prefix == 1
destroy_ctfd(app)
class ReverseProxyConfig(TestingConfig):
REVERSE_PROXY = True
app = create_ctfd(config=ReverseProxyConfig)
with app.app_context():
assert app.wsgi_app.x_for == 1
assert app.wsgi_app.x_proto == 1
assert app.wsgi_app.x_host == 1
assert app.wsgi_app.x_port == 1
assert app.wsgi_app.x_prefix == 1
destroy_ctfd(app)
def test_server_sent_events_config():
"""Test that SERVER_SENT_EVENTS configuration behaves properly"""
class ServerSentEventsConfig(TestingConfig):
SERVER_SENT_EVENTS = False
app = create_ctfd(config=ServerSentEventsConfig)
with app.app_context():
register_user(app)
client = login_as_user(app)
r = client.get("/events")
assert r.status_code == 204
destroy_ctfd(app)