mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
2.3.0 / 2020-02-17
==================
**General**
* During setup, admins can register their email address with the CTFd LLC newsletter for news and updates
* Fix editting hints from the admin panel
* Allow admins to insert HTML code directly into the header and footer (end of body tag) of pages. This replaces and supercedes the custom CSS feature.
* The `views.custom_css` route has been removed.
* Admins can now customize the content of outgoing emails and inject certain variables into email content.
* The `manage.py` script can now manipulate the CTFd Configs table via the `get_config` and `set_config` commands. (e.g. `python manage.py get_config ctf_theme` and `python manage.py set_config ctf_theme core`)
**Themes**
* Themes should now reference the `theme_header` and `theme_footer` configs instead of the `views.custom_css` endpoint to allow for user customizations. See the `base.html` file of the core theme.
**Plugins**
* Make `ezq` functions available to `CTFd.js` under `CTFd.ui.ezq`
**Miscellaneous**
* Python imports sorted with `isort` and import order enforced
* Black formatter running on a majority of Python code
94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from CTFd.models import Hints
|
|
from tests.helpers import (
|
|
create_ctfd,
|
|
destroy_ctfd,
|
|
gen_challenge,
|
|
gen_hint,
|
|
login_as_user,
|
|
register_user,
|
|
)
|
|
|
|
|
|
def test_api_hint_get_non_admin():
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
register_user(app)
|
|
with login_as_user(app) as client:
|
|
# test_api_hint_get_non_admin
|
|
"""Can the users get /api/v1/hints if not admin"""
|
|
r = client.get("/api/v1/hints", json="")
|
|
assert r.status_code == 403
|
|
assert Hints.query.count() == 0
|
|
|
|
# test_api_hint_post_non_admin
|
|
"""Can the users post /api/v1/hints if not admin"""
|
|
r = client.post("/api/v1/hints", json="")
|
|
assert r.status_code == 403
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_hint_get_admin():
|
|
"""Can the users get /api/v1/hints if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
with login_as_user(app, name="admin") as client:
|
|
r = client.get("/api/v1/hints", json="")
|
|
assert r.status_code == 200
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_hint_post_admin():
|
|
"""Can the users post /api/v1/hints if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
gen_challenge(app.db)
|
|
with login_as_user(app, name="admin") as client:
|
|
r = client.post(
|
|
"/api/v1/hints", json={"content": "hint", "cost": "1", "challenge": 1}
|
|
)
|
|
assert r.status_code == 200
|
|
assert Hints.query.count() == 1
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_admins_can_preview_hints():
|
|
"""Test that admins are able to bypass restrictions and preview hints with ?preview=true"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
gen_challenge(app.db)
|
|
gen_hint(app.db, challenge_id=1, cost=100)
|
|
client = login_as_user(app, name="admin", password="password")
|
|
r = client.get("/api/v1/hints/1")
|
|
assert r.status_code == 200
|
|
hint = r.get_json()
|
|
assert hint.get("content") is None
|
|
|
|
r = client.get("/api/v1/hints/1?preview=true")
|
|
assert r.status_code == 200
|
|
hint = r.get_json()
|
|
assert hint["data"]["content"] == "This is a hint"
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_users_cannot_preview_hints():
|
|
"""Test that users aren't able to preview hints"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
gen_challenge(app.db)
|
|
gen_hint(app.db, challenge_id=1, cost=100)
|
|
register_user(app)
|
|
client = login_as_user(app)
|
|
r = client.get("/api/v1/hints/1")
|
|
assert r.status_code == 200
|
|
hint = r.get_json()
|
|
assert hint.get("content") is None
|
|
|
|
r = client.get("/api/v1/hints/1?preview=true")
|
|
assert r.status_code == 200
|
|
hint = r.get_json()
|
|
assert hint["data"].get("content") is None
|
|
destroy_ctfd(app)
|