Relax team requirement when challenges are publicly visible (#1832)

* Don't require a team for viewing challenges if Challenge visibility is set to public
* Closes #1831
This commit is contained in:
Kevin Chung
2021-03-18 02:35:03 -04:00
committed by GitHub
parent e5dbd62a66
commit 8a70d9527f
2 changed files with 42 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from CTFd.utils import set_config
from CTFd.utils.scores import get_standings
from tests.helpers import (
create_ctfd,
@@ -10,6 +11,7 @@ from tests.helpers import (
gen_team,
gen_user,
login_as_user,
register_user,
)
@@ -38,3 +40,26 @@ def test_challenge_team_submit():
assert standings[0][2] == "team_name"
assert standings[0][3] == 100
destroy_ctfd(app)
def test_anonymous_users_view_public_challenges_without_team():
"""Test that if challenges are public, users without team can still view them"""
app = create_ctfd(user_mode="teams")
with app.app_context():
register_user(app)
gen_challenge(app.db)
with app.test_client() as client:
r = client.get("/challenges")
assert r.status_code == 302
assert r.location.startswith("http://localhost/login")
set_config("challenge_visibility", "public")
with app.test_client() as client:
r = client.get("/challenges")
assert r.status_code == 200
with login_as_user(app) as client:
r = client.get("/challenges")
assert r.status_code == 302
assert r.location.startswith("http://localhost/team")
destroy_ctfd(app)