mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +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
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import os
|
|
|
|
import boto3
|
|
from moto import mock_s3
|
|
from six import BytesIO
|
|
|
|
from CTFd.utils.uploads import S3Uploader, rmdir
|
|
from tests.helpers import create_ctfd, destroy_ctfd
|
|
|
|
|
|
@mock_s3
|
|
def test_s3_uploader():
|
|
conn = boto3.resource("s3", region_name="us-east-1")
|
|
conn.create_bucket(Bucket="bucket")
|
|
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
app.config["UPLOAD_PROVIDER"] = "s3"
|
|
app.config["AWS_ACCESS_KEY_ID"] = "AKIAIOSFODNN7EXAMPLE"
|
|
app.config["AWS_SECRET_ACCESS_KEY"] = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
|
|
app.config["AWS_S3_BUCKET"] = "bucket"
|
|
|
|
uploader = S3Uploader()
|
|
|
|
assert uploader.s3
|
|
assert uploader.bucket == "bucket"
|
|
|
|
fake_file = BytesIO("fakedfile".encode())
|
|
path = uploader.upload(fake_file, "fake_file.txt")
|
|
|
|
assert "fake_file.txt" in uploader.download(path).location
|
|
destroy_ctfd(app)
|
|
|
|
|
|
@mock_s3
|
|
def test_s3_sync():
|
|
conn = boto3.resource("s3", region_name="us-east-1")
|
|
conn.create_bucket(Bucket="bucket")
|
|
|
|
app = create_ctfd()
|
|
with app.app_context():
|
|
app.config["UPLOAD_PROVIDER"] = "s3"
|
|
app.config["AWS_ACCESS_KEY_ID"] = "AKIAIOSFODNN7EXAMPLE"
|
|
app.config["AWS_SECRET_ACCESS_KEY"] = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
|
|
app.config["AWS_S3_BUCKET"] = "bucket"
|
|
|
|
uploader = S3Uploader()
|
|
uploader.sync()
|
|
|
|
fake_file = BytesIO("fakedfile".encode())
|
|
path = uploader.upload(fake_file, "fake_file.txt")
|
|
full_path = os.path.join(app.config["UPLOAD_FOLDER"], path)
|
|
|
|
try:
|
|
uploader.sync()
|
|
with open(full_path) as f:
|
|
assert f.read() == "fakedfile"
|
|
finally:
|
|
rmdir(os.path.dirname(full_path))
|
|
destroy_ctfd(app)
|