|
3 | 3 |
|
4 | 4 | from tests.helpers import *
|
5 | 5 | from CTFd.models import ip2long, long2ip
|
6 |
| -from CTFd.plugins import register_plugin_assets_directory, register_plugin_asset |
| 6 | +from CTFd.plugins import ( |
| 7 | + register_plugin_assets_directory, |
| 8 | + register_plugin_asset, |
| 9 | + register_plugin_script, |
| 10 | + register_plugin_stylesheet, |
| 11 | + override_template |
| 12 | +) |
7 | 13 | from freezegun import freeze_time
|
8 | 14 | from mock import patch
|
9 | 15 | import json
|
@@ -37,3 +43,58 @@ def test_register_plugin_assets_directory():
|
37 | 43 | assert len(r.get_data(as_text=True)) > 0
|
38 | 44 | assert r.status_code == 200
|
39 | 45 | destroy_ctfd(app)
|
| 46 | + |
| 47 | + |
| 48 | +def test_override_template(): |
| 49 | + """Does override_template work properly for regular themes when used from a plugin""" |
| 50 | + app = create_ctfd() |
| 51 | + with app.app_context(): |
| 52 | + override_template('login.html', 'LOGIN OVERRIDE') |
| 53 | + with app.test_client() as client: |
| 54 | + r = client.get('/login') |
| 55 | + assert r.status_code == 200 |
| 56 | + output = r.get_data(as_text=True) |
| 57 | + assert 'LOGIN OVERRIDE' in output |
| 58 | + destroy_ctfd(app) |
| 59 | + |
| 60 | + |
| 61 | +def test_admin_override_template(): |
| 62 | + """Does override_template work properly for the admin panel when used from a plugin""" |
| 63 | + app = create_ctfd() |
| 64 | + with app.app_context(): |
| 65 | + override_template('admin/team.html', 'ADMIN TEAM OVERRIDE') |
| 66 | + |
| 67 | + client = login_as_user(app, name="admin", password="password") |
| 68 | + r = client.get('/admin/team/1') |
| 69 | + assert r.status_code == 200 |
| 70 | + output = r.get_data(as_text=True) |
| 71 | + assert 'ADMIN TEAM OVERRIDE' in output |
| 72 | + destroy_ctfd(app) |
| 73 | + |
| 74 | + |
| 75 | +def test_register_plugin_script(): |
| 76 | + '''Test that register_plugin_script adds script paths to the original theme when used from a plugin''' |
| 77 | + app = create_ctfd() |
| 78 | + with app.app_context(): |
| 79 | + register_plugin_script('/fake/script/path.js') |
| 80 | + register_plugin_script('http://ctfd.io/fake/script/path.js') |
| 81 | + with app.test_client() as client: |
| 82 | + r = client.get('/') |
| 83 | + output = r.get_data(as_text=True) |
| 84 | + assert '/fake/script/path.js' in output |
| 85 | + assert 'http://ctfd.io/fake/script/path.js' in output |
| 86 | + destroy_ctfd(app) |
| 87 | + |
| 88 | + |
| 89 | +def test_register_plugin_stylesheet(): |
| 90 | + '''Test that register_plugin_stylesheet adds stylesheet paths to the original theme when used from a plugin''' |
| 91 | + app = create_ctfd() |
| 92 | + with app.app_context(): |
| 93 | + register_plugin_script('/fake/stylesheet/path.css') |
| 94 | + register_plugin_script('http://ctfd.io/fake/stylesheet/path.css') |
| 95 | + with app.test_client() as client: |
| 96 | + r = client.get('/') |
| 97 | + output = r.get_data(as_text=True) |
| 98 | + assert '/fake/stylesheet/path.css' in output |
| 99 | + assert 'http://ctfd.io/fake/stylesheet/path.css' in output |
| 100 | + destroy_ctfd(app) |
0 commit comments