mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
use different directories for different tests (#1864)
This commit is contained in:
@@ -155,13 +155,13 @@ def test_theme_fallback_config():
|
|||||||
app = create_ctfd()
|
app = create_ctfd()
|
||||||
# Make an empty theme
|
# Make an empty theme
|
||||||
try:
|
try:
|
||||||
os.mkdir(os.path.join(app.root_path, "themes", "foo"))
|
os.mkdir(os.path.join(app.root_path, "themes", "foo_fallback"))
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Without theme fallback, missing themes should disappear
|
# Without theme fallback, missing themes should disappear
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
set_config("ctf_theme", "foo")
|
set_config("ctf_theme", "foo_fallback")
|
||||||
assert app.config["THEME_FALLBACK"] == False
|
assert app.config["THEME_FALLBACK"] == False
|
||||||
with app.test_client() as client:
|
with app.test_client() as client:
|
||||||
try:
|
try:
|
||||||
@@ -169,7 +169,7 @@ def test_theme_fallback_config():
|
|||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
r = client.get("/themes/foo/static/js/pages/main.dev.js")
|
r = client.get("/themes/foo_fallback/static/js/pages/main.dev.js")
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
pass
|
pass
|
||||||
destroy_ctfd(app)
|
destroy_ctfd(app)
|
||||||
@@ -179,17 +179,17 @@ def test_theme_fallback_config():
|
|||||||
|
|
||||||
app = create_ctfd(config=ThemeFallbackConfig)
|
app = create_ctfd(config=ThemeFallbackConfig)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
set_config("ctf_theme", "foo")
|
set_config("ctf_theme", "foo_fallback")
|
||||||
assert app.config["THEME_FALLBACK"] == True
|
assert app.config["THEME_FALLBACK"] == True
|
||||||
with app.test_client() as client:
|
with app.test_client() as client:
|
||||||
r = client.get("/")
|
r = client.get("/")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
r = client.get("/themes/foo/static/js/pages/main.dev.js")
|
r = client.get("/themes/foo_fallback/static/js/pages/main.dev.js")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
destroy_ctfd(app)
|
destroy_ctfd(app)
|
||||||
|
|
||||||
# Remove empty theme
|
# Remove empty theme
|
||||||
os.rmdir(os.path.join(app.root_path, "themes", "foo"))
|
os.rmdir(os.path.join(app.root_path, "themes", "foo_fallback"))
|
||||||
|
|
||||||
|
|
||||||
def test_theme_template_loading_by_prefix():
|
def test_theme_template_loading_by_prefix():
|
||||||
@@ -208,9 +208,10 @@ def test_theme_template_disallow_loading_admin_templates():
|
|||||||
try:
|
try:
|
||||||
# Make an empty malicious theme
|
# Make an empty malicious theme
|
||||||
filename = os.path.join(
|
filename = os.path.join(
|
||||||
app.root_path, "themes", "foo", "admin", "malicious.html"
|
app.root_path, "themes", "foo_disallow", "admin", "malicious.html"
|
||||||
)
|
)
|
||||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||||
|
set_config("ctf_theme", "foo_disallow")
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w") as f:
|
||||||
f.write("malicious")
|
f.write("malicious")
|
||||||
|
|
||||||
@@ -219,5 +220,6 @@ def test_theme_template_disallow_loading_admin_templates():
|
|||||||
finally:
|
finally:
|
||||||
# Remove empty theme
|
# Remove empty theme
|
||||||
shutil.rmtree(
|
shutil.rmtree(
|
||||||
os.path.join(app.root_path, "themes", "foo"), ignore_errors=True
|
os.path.join(app.root_path, "themes", "foo_disallow"),
|
||||||
|
ignore_errors=True,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user