mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
# 3.3.0 / UNRELEASED
**General**
- Don't require a team for viewing challenges if Challenge visibility is set to public
- Add a `THEME_FALLBACK` config to help develop themes. See **Themes** section for details.
**API**
- Implement a faster `/api/v1/scoreboard` endpoint in Teams Mode
- Add the `solves` item to both `/api/v1/challenges` and `/api/v1/challenges/[challenge_id]` to more easily determine how many solves a challenge has
- Add the `solved_by_me` item to both `/api/v1/challenges` and `/api/v1/challenges/[challenge_id]` to more easily determine if the current account has solved the challenge
- Prevent admins from deleting themselves through `DELETE /api/v1/users/[user_id]`
- Add length checking to some sensitive fields in the Pages and Challenges schemas
- Fix issue where `PATCH /api/v1/users[user_id]` returned a list instead of a dict
- Fix exception that occured on demoting admins through `PATCH /api/v1/users[user_id]`
- Add `team_id` to `GET /api/v1/users` to determine if a user is already in a team
**Themes**
- Add a `THEME_FALLBACK` config to help develop themes.
- `THEME_FALLBACK` will configure CTFd to try to find missing theme files in the default built-in `core` theme.
- This makes it easier to develop themes or use incomplete themes.
- Allow for one theme to reference and inherit from another theme through approaches like `{% extends "core/page.html" %}`
- Allow for the automatic date rendering format to be overridden by specifying a `data-time-format` attribute.
- Add styling for the `<blockquote>` element.
- Fix scoreboard table identifier to switch between User/Team depending on configured user mode
- Switch to using Bootstrap's scss in `core/main.scss` to allow using Bootstrap variables
- Consolidate Jinja error handlers into a single function and better handle issues where error templates can't be found
**Plugins**
- Set plugin migration version after successful migrations
- Fix issue where Page URLs injected into the navbar were relative instead of absolute
**Admin Panel**
- Add User standings as well as Teams standings to the admin scoreboard when in Teams Mode
- Add a UI for adding members to a team from the team's admin page
- Add ability for admins to disable public team creation
- Link directly to users who submitted something in the submissions page if the CTF is in Teams Mode
- Fix Challenge Requirements interface in Admin Panel to not allow empty/null requirements to be added
- Fixed an issue where config times (start, end, freeze times) could not be removed
- Fix an exception that occurred when demoting an Admin user
- Adds a temporary hack for re-enabling Javascript snippets in Flag editor templates. (See #1779)
**Deployment**
- Install `python3-dev` instead of `python-dev` in apt
- Bump lxml to 4.6.2
- Bump pip-compile to 5.4.0
**Miscellaneous**
- Cache Docker builds more by copying and installing Python dependencies before copying CTFd
- Change the default emails slightly and rework confirmation email page to make some recommendations clearer
- Use `examplectf.com` as testing/development domain instead of `ctfd.io`
- Fixes issue where user's name and email would not appear in logs properly
- Add more linting by also linting with `flake8-comprehensions` and `flake8-bugbear`
140 lines
4.5 KiB
Python
140 lines
4.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import shutil
|
|
from io import BytesIO
|
|
|
|
from CTFd.models import ChallengeFiles, Challenges, Files
|
|
from tests.helpers import (
|
|
create_ctfd,
|
|
destroy_ctfd,
|
|
gen_challenge,
|
|
gen_file,
|
|
login_as_user,
|
|
)
|
|
|
|
|
|
def test_api_files_get_non_admin():
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
chal = gen_challenge(app.db)
|
|
gen_file(
|
|
app.db,
|
|
location="0bf1a55a5cd327c07af15df260979668/bird.swf",
|
|
challenge_id=chal.id,
|
|
)
|
|
|
|
with app.test_client() as client:
|
|
# test_api_files_get_non_admin
|
|
"""Can a user get /api/v1/files if not admin"""
|
|
r = client.get("/api/v1/files", json="")
|
|
assert r.status_code == 403
|
|
|
|
# test_api_files_post_non_admin
|
|
"""Can a user post /api/v1/files if not admin"""
|
|
r = client.post("/api/v1/files")
|
|
assert r.status_code == 403
|
|
|
|
# test_api_file_get_non_admin
|
|
"""Can a user get /api/v1/files/<file_id> if not admin"""
|
|
r = client.get("/api/v1/files/1", json="")
|
|
assert r.status_code == 403
|
|
|
|
# test_api_file_delete_non_admin
|
|
"""Can a user delete /api/v1/files/<file_id> if not admin"""
|
|
r = client.delete("/api/v1/files/1", json="")
|
|
assert r.status_code == 403
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_files_get_admin():
|
|
"""Can a user get /api/v1/files if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
with login_as_user(app, "admin") as client:
|
|
r = client.get("/api/v1/files", json="")
|
|
assert r.status_code == 200
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_files_post_admin():
|
|
"""Can a user post /api/v1/files if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
with login_as_user(app, name="admin") as client:
|
|
with client.session_transaction() as sess:
|
|
nonce = sess.get("nonce")
|
|
r = client.post(
|
|
"/api/v1/files",
|
|
content_type="multipart/form-data",
|
|
data={
|
|
"file": (BytesIO(b"test file content"), "test.txt"),
|
|
"nonce": nonce,
|
|
},
|
|
)
|
|
assert r.status_code == 200
|
|
f = Files.query.filter_by(id=1).first()
|
|
os.remove(os.path.join(app.config["UPLOAD_FOLDER"] + "/" + f.location))
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_file_get_admin():
|
|
"""Can a user get /api/v1/files/<file_id> if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
chal = gen_challenge(app.db)
|
|
f = gen_file(
|
|
app.db,
|
|
location="0bf1a55a5cd327c07af15df260979668/bird.swf",
|
|
challenge_id=chal.id,
|
|
)
|
|
assert Files.query.count() == 1
|
|
assert ChallengeFiles.query.count() == 1
|
|
assert f in chal.files
|
|
with login_as_user(app, "admin") as client:
|
|
r = client.get("/api/v1/files/1", json="")
|
|
assert r.status_code == 200
|
|
destroy_ctfd(app)
|
|
|
|
|
|
def test_api_file_delete_admin():
|
|
"""Can a user delete /api/v1/files/<file_id> if admin"""
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
chal = gen_challenge(app.db)
|
|
path = os.path.join(
|
|
app.config["UPLOAD_FOLDER"], "0bf1a55a5cd327c07af15df260979668", "bird.swf"
|
|
)
|
|
try:
|
|
# Create a fake file
|
|
os.makedirs(os.path.dirname(path))
|
|
open(path, "a").close()
|
|
f = gen_file(
|
|
app.db,
|
|
location="0bf1a55a5cd327c07af15df260979668/bird.swf",
|
|
challenge_id=chal.id,
|
|
)
|
|
assert Files.query.count() == 1
|
|
assert ChallengeFiles.query.count() == 1
|
|
assert f in chal.files
|
|
|
|
# Make sure the file was created
|
|
assert os.path.exists(path)
|
|
|
|
with login_as_user(app, "admin") as client:
|
|
r = client.delete("/api/v1/files/1", json="")
|
|
assert r.status_code == 200
|
|
assert Files.query.count() == 0
|
|
assert ChallengeFiles.query.count() == 0
|
|
chal = Challenges.query.filter_by(id=1).first()
|
|
assert f not in chal.files
|
|
|
|
# Make sure the API call deleted the file
|
|
assert os.path.exists(path) is False
|
|
finally:
|
|
# Always make sure the file is deleted
|
|
shutil.rmtree(os.path.dirname(path), ignore_errors=True)
|
|
|
|
destroy_ctfd(app)
|