CoolFace
Apppublic

vishalbhat07/ctfd

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_setup.py57 linesDownload Raw Back to users
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3 4from tests.helpers import create_ctfd, destroy_ctfd, gen_user5 6 7def test_ctfd_setup_redirect():8    """Test that a fresh CTFd instance redirects to /setup"""9    app = create_ctfd(setup=False)10    with app.app_context():11        with app.test_client() as client:12            r = client.get("/users")13            assert r.status_code == 30214            assert r.location == "/setup"15 16            # Files in /themes load properly17            r = client.get("/themes/core/static/manifest.json")18            r = client.get("/themes/core/static/img/favicon.ico")19            assert r.status_code == 20020    destroy_ctfd(app)21 22 23def test_ctfd_setup_verification():24    app = create_ctfd(setup=False)25    with app.app_context():26        with app.test_client() as client:27            r = client.get("/setup")28            assert r.status_code == 20029 30            with client.session_transaction() as sess:31                data = {32                    "ctf_name": "CTFd",33                    "ctf_description": "CTF description",34                    "name": "test",35                    "email": "test@examplectf.com",36                    "password": "",37                    "user_mode": "users",38                    "nonce": sess.get("nonce"),39                }40            r = client.post("/setup", data=data)41            assert "longer password" in r.get_data(as_text=True)42 43            gen_user(app.db, name="test", email="test@examplectf.com")44 45            data["password"] = "password"46            r = client.post("/setup", data=data)47            resp = r.get_data(as_text=True)48            assert "email has already been used" in resp49            assert "name is already taken" in resp50 51            data["name"] = "admin"52            data["email"] = "admin@examplectf.com"53            r = client.post("/setup", data=data)54            assert r.status_code == 30255            assert r.location == "/"56    destroy_ctfd(app)57