Skip to content

Commit

Permalink
use different directories for different tests (CTFd#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankli0324 authored Apr 12, 2021
1 parent 87711d7 commit 5976830
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ def test_theme_fallback_config():
app = create_ctfd()
# Make an empty theme
try:
os.mkdir(os.path.join(app.root_path, "themes", "foo"))
os.mkdir(os.path.join(app.root_path, "themes", "foo_fallback"))
except OSError:
pass

# Without theme fallback, missing themes should disappear
with app.app_context():
set_config("ctf_theme", "foo")
set_config("ctf_theme", "foo_fallback")
assert app.config["THEME_FALLBACK"] == False
with app.test_client() as client:
try:
r = client.get("/")
except TemplateNotFound:
pass
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:
pass
destroy_ctfd(app)
Expand All @@ -179,17 +179,17 @@ class ThemeFallbackConfig(TestingConfig):

app = create_ctfd(config=ThemeFallbackConfig)
with app.app_context():
set_config("ctf_theme", "foo")
set_config("ctf_theme", "foo_fallback")
assert app.config["THEME_FALLBACK"] == True
with app.test_client() as client:
r = client.get("/")
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
destroy_ctfd(app)

# 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():
Expand All @@ -208,9 +208,10 @@ def test_theme_template_disallow_loading_admin_templates():
try:
# Make an empty malicious theme
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)
set_config("ctf_theme", "foo_disallow")
with open(filename, "w") as f:
f.write("malicious")

Expand All @@ -219,5 +220,6 @@ def test_theme_template_disallow_loading_admin_templates():
finally:
# Remove empty theme
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,
)

0 comments on commit 5976830

Please sign in to comment.