mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Format all the things (#991)
* Format Javascript and CSS files with `prettier`: `prettier --write 'CTFd/themes/**/*'` * Format Python with `black`: `black CTFd` & `black tests` * Travis now uses xenial instead of trusty.
This commit is contained in:
@@ -3,14 +3,16 @@
|
||||
|
||||
from CTFd.models import db, Unlocks, Users
|
||||
from CTFd.utils import set_config, text_type
|
||||
from tests.helpers import (create_ctfd,
|
||||
destroy_ctfd,
|
||||
register_user,
|
||||
login_as_user,
|
||||
gen_challenge,
|
||||
gen_award,
|
||||
gen_flag,
|
||||
gen_hint)
|
||||
from tests.helpers import (
|
||||
create_ctfd,
|
||||
destroy_ctfd,
|
||||
register_user,
|
||||
login_as_user,
|
||||
gen_challenge,
|
||||
gen_award,
|
||||
gen_flag,
|
||||
gen_hint,
|
||||
)
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
@@ -24,7 +26,7 @@ def test_user_cannot_unlock_hint():
|
||||
chal = gen_challenge(app.db, value=100)
|
||||
chal_id = chal.id
|
||||
|
||||
gen_flag(app.db, challenge_id=chal.id, content='flag')
|
||||
gen_flag(app.db, challenge_id=chal.id, content="flag")
|
||||
|
||||
hint = gen_hint(db, chal_id, cost=10)
|
||||
hint_id = hint.id
|
||||
@@ -32,10 +34,10 @@ def test_user_cannot_unlock_hint():
|
||||
client = login_as_user(app, name="user1", password="password")
|
||||
|
||||
with client.session_transaction():
|
||||
r = client.get('/api/v1/hints/{}'.format(hint_id))
|
||||
r = client.get("/api/v1/hints/{}".format(hint_id))
|
||||
resp = r.get_json()
|
||||
assert resp['data'].get('content') is None
|
||||
assert resp['data'].get('cost') == 10
|
||||
assert resp["data"].get("content") is None
|
||||
assert resp["data"].get("cost") == 10
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
@@ -49,7 +51,7 @@ def test_user_can_unlock_hint():
|
||||
chal = gen_challenge(app.db, value=100)
|
||||
chal_id = chal.id
|
||||
|
||||
gen_flag(app.db, challenge_id=chal.id, content='flag')
|
||||
gen_flag(app.db, challenge_id=chal.id, content="flag")
|
||||
|
||||
hint = gen_hint(app.db, chal_id, cost=10)
|
||||
hint_id = hint.id
|
||||
@@ -62,22 +64,19 @@ def test_user_can_unlock_hint():
|
||||
assert user.score == 15
|
||||
|
||||
with client.session_transaction():
|
||||
r = client.get('/api/v1/hints/{}'.format(hint_id))
|
||||
r = client.get("/api/v1/hints/{}".format(hint_id))
|
||||
resp = r.get_json()
|
||||
assert resp['data'].get('content') is None
|
||||
assert resp["data"].get("content") is None
|
||||
|
||||
params = {
|
||||
"target": hint_id,
|
||||
"type": "hints"
|
||||
}
|
||||
params = {"target": hint_id, "type": "hints"}
|
||||
|
||||
r = client.post('/api/v1/unlocks', json=params)
|
||||
r = client.post("/api/v1/unlocks", json=params)
|
||||
resp = r.get_json()
|
||||
assert resp['success'] is True
|
||||
assert resp["success"] is True
|
||||
|
||||
r = client.get('/api/v1/hints/{}'.format(hint_id))
|
||||
r = client.get("/api/v1/hints/{}".format(hint_id))
|
||||
resp = r.get_json()
|
||||
assert resp['data'].get('content') == "This is a hint"
|
||||
assert resp["data"].get("content") == "This is a hint"
|
||||
|
||||
user = Users.query.filter_by(name="user1").first()
|
||||
assert user.score == 5
|
||||
@@ -93,9 +92,9 @@ def test_unlocking_hints_with_no_cost():
|
||||
chal_id = chal.id
|
||||
gen_hint(app.db, chal_id)
|
||||
client = login_as_user(app)
|
||||
r = client.get('/api/v1/hints/1')
|
||||
resp = r.get_json()['data']
|
||||
assert resp.get('content') == 'This is a hint'
|
||||
r = client.get("/api/v1/hints/1")
|
||||
resp = r.get_json()["data"]
|
||||
assert resp.get("content") == "This is a hint"
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
@@ -110,16 +109,13 @@ def test_unlocking_hints_with_cost_during_ctf_with_points():
|
||||
gen_award(app.db, user_id=2)
|
||||
|
||||
client = login_as_user(app)
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json()['data'].get('content') is None
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json()["data"].get("content") is None
|
||||
|
||||
client.post('/api/v1/unlocks', json={
|
||||
'target': 1,
|
||||
'type': 'hints'
|
||||
})
|
||||
client.post("/api/v1/unlocks", json={"target": 1, "type": "hints"})
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json()['data'].get('content') == 'This is a hint'
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json()["data"].get("content") == "This is a hint"
|
||||
|
||||
user = Users.query.filter_by(id=2).first()
|
||||
assert user.score == 90
|
||||
@@ -137,17 +133,17 @@ def test_unlocking_hints_with_cost_during_ctf_without_points():
|
||||
|
||||
client = login_as_user(app)
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json()['data'].get('content') is None
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json()["data"].get("content") is None
|
||||
|
||||
r = client.post('/api/v1/unlocks', json={
|
||||
'target': 1,
|
||||
'type': 'hints'
|
||||
})
|
||||
assert r.get_json()['errors']['score'] == 'You do not have enough points to unlock this hint'
|
||||
r = client.post("/api/v1/unlocks", json={"target": 1, "type": "hints"})
|
||||
assert (
|
||||
r.get_json()["errors"]["score"]
|
||||
== "You do not have enough points to unlock this hint"
|
||||
)
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json()['data'].get('content') is None
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json()["data"].get("content") is None
|
||||
|
||||
user = Users.query.filter_by(id=2).first()
|
||||
assert user.score == 0
|
||||
@@ -164,25 +160,26 @@ def test_unlocking_hints_with_cost_before_ctf():
|
||||
gen_hint(app.db, chal_id)
|
||||
gen_award(app.db, user_id=2)
|
||||
|
||||
set_config('start', '1507089600') # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config('end', '1507262400') # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config(
|
||||
"start", "1507089600"
|
||||
) # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config(
|
||||
"end", "1507262400"
|
||||
) # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
|
||||
with freeze_time("2017-10-1"):
|
||||
client = login_as_user(app)
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.status_code == 403
|
||||
assert r.get_json().get('data') is None
|
||||
assert r.get_json().get("data") is None
|
||||
|
||||
r = client.post('/api/v1/unlocks', json={
|
||||
'target': 1,
|
||||
'type': 'hints'
|
||||
})
|
||||
r = client.post("/api/v1/unlocks", json={"target": 1, "type": "hints"})
|
||||
assert r.status_code == 403
|
||||
assert r.get_json().get('data') is None
|
||||
assert r.get_json().get("data") is None
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json().get('data') is None
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json().get("data") is None
|
||||
assert r.status_code == 403
|
||||
|
||||
user = Users.query.filter_by(id=2).first()
|
||||
@@ -202,24 +199,25 @@ def test_unlocking_hints_with_cost_during_ended_ctf():
|
||||
gen_hint(app.db, chal_id, cost=10)
|
||||
gen_award(app.db, user_id=2)
|
||||
|
||||
set_config('start', '1507089600') # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config('end', '1507262400') # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config(
|
||||
"start", "1507089600"
|
||||
) # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config(
|
||||
"end", "1507262400"
|
||||
) # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
|
||||
with freeze_time("2017-11-4"):
|
||||
client = login_as_user(app)
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
assert r.get_json().get('data') is None
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.get_json().get("data") is None
|
||||
assert r.status_code == 403
|
||||
|
||||
r = client.post('/api/v1/unlocks', json={
|
||||
'target': 1,
|
||||
'type': 'hints'
|
||||
})
|
||||
r = client.post("/api/v1/unlocks", json={"target": 1, "type": "hints"})
|
||||
assert r.status_code == 403
|
||||
assert r.get_json()
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.status_code == 403
|
||||
|
||||
user = Users.query.filter_by(id=2).first()
|
||||
@@ -232,7 +230,9 @@ def test_unlocking_hints_with_cost_during_frozen_ctf():
|
||||
"""Test that hints with a cost are unlocked if the CTF is frozen."""
|
||||
app = create_ctfd()
|
||||
with app.app_context():
|
||||
set_config('freeze', '1507262400') # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
set_config(
|
||||
"freeze", "1507262400"
|
||||
) # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
|
||||
with freeze_time("2017-10-4"):
|
||||
register_user(app)
|
||||
chal = gen_challenge(app.db)
|
||||
@@ -243,17 +243,14 @@ def test_unlocking_hints_with_cost_during_frozen_ctf():
|
||||
with freeze_time("2017-10-8"):
|
||||
client = login_as_user(app)
|
||||
|
||||
client.get('/api/v1/hints/1')
|
||||
client.get("/api/v1/hints/1")
|
||||
|
||||
client.post('/api/v1/unlocks', json={
|
||||
'target': 1,
|
||||
'type': 'hints'
|
||||
})
|
||||
client.post("/api/v1/unlocks", json={"target": 1, "type": "hints"})
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
|
||||
resp = r.get_json()['data']
|
||||
assert resp.get('content') == 'This is a hint'
|
||||
resp = r.get_json()["data"]
|
||||
assert resp.get("content") == "This is a hint"
|
||||
|
||||
user = Users.query.filter_by(id=2).first()
|
||||
assert user.score == 100
|
||||
@@ -265,14 +262,14 @@ def test_unlocking_hint_for_unicode_challenge():
|
||||
app = create_ctfd()
|
||||
with app.app_context():
|
||||
register_user(app)
|
||||
chal = gen_challenge(app.db, name=text_type('🐺'))
|
||||
chal = gen_challenge(app.db, name=text_type("🐺"))
|
||||
chal_id = chal.id
|
||||
gen_hint(app.db, chal_id)
|
||||
|
||||
client = login_as_user(app)
|
||||
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.status_code == 200
|
||||
resp = r.get_json()['data']
|
||||
assert resp.get('content') == 'This is a hint'
|
||||
resp = r.get_json()["data"]
|
||||
assert resp.get("content") == "This is a hint"
|
||||
destroy_ctfd(app)
|
||||
|
||||
Reference in New Issue
Block a user