2023-02-25 17:11:19 +00:00
|
|
|
from werkzeug.security import gen_salt
|
|
|
|
|
2024-03-15 18:58:06 +00:00
|
|
|
from canaille.app import models
|
|
|
|
|
2023-02-25 17:11:19 +00:00
|
|
|
|
2020-08-26 14:27:08 +00:00
|
|
|
def test_no_logged_no_access(testclient):
|
2020-08-26 15:23:53 +00:00
|
|
|
testclient.get("/admin/authorization", status=403)
|
2020-08-26 14:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_no_admin_no_access(testclient, logged_user):
|
2020-08-26 15:23:53 +00:00
|
|
|
testclient.get("/admin/authorization", status=403)
|
2020-08-26 14:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_authorizaton_list(testclient, authorization, logged_admin):
|
2020-08-26 15:23:53 +00:00
|
|
|
res = testclient.get("/admin/authorization")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain(authorization.authorization_code_id)
|
2020-08-26 14:27:08 +00:00
|
|
|
|
|
|
|
|
2023-02-25 17:11:19 +00:00
|
|
|
def test_authorization_list_pagination(testclient, logged_admin, client):
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("0 items")
|
2023-02-25 17:11:19 +00:00
|
|
|
authorizations = []
|
|
|
|
for _ in range(26):
|
2023-04-09 09:37:04 +00:00
|
|
|
code = models.AuthorizationCode(
|
2023-05-11 14:02:32 +00:00
|
|
|
authorization_code_id=gen_salt(48), client=client, subject=logged_admin
|
2023-02-25 17:11:19 +00:00
|
|
|
)
|
|
|
|
code.save()
|
|
|
|
authorizations.append(code)
|
|
|
|
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("26 items")
|
2023-02-25 17:11:19 +00:00
|
|
|
authorization_code_id = res.pyquery(
|
|
|
|
".codes tbody tr:nth-of-type(1) td:nth-of-type(1) a"
|
|
|
|
).text()
|
|
|
|
assert authorization_code_id
|
|
|
|
|
2023-08-31 20:34:12 +00:00
|
|
|
form = res.forms["tableform"]
|
|
|
|
res = form.submit(name="page", value="2")
|
2023-03-09 19:46:04 +00:00
|
|
|
assert authorization_code_id not in res.pyquery(
|
|
|
|
".codes tbody tr td:nth-of-type(1) a"
|
|
|
|
).text().split(" ")
|
2023-02-25 17:11:19 +00:00
|
|
|
for authorization in authorizations:
|
|
|
|
authorization.delete()
|
|
|
|
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("0 items")
|
2023-02-25 17:11:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_authorization_list_bad_pages(testclient, logged_admin):
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-08-31 20:34:12 +00:00
|
|
|
form = res.forms["tableform"]
|
2023-02-25 17:11:19 +00:00
|
|
|
testclient.post(
|
|
|
|
"/admin/authorization",
|
2023-03-28 18:30:29 +00:00
|
|
|
{"csrf_token": form["csrf_token"].value, "page": "2"},
|
2023-02-25 17:11:19 +00:00
|
|
|
status=404,
|
|
|
|
)
|
|
|
|
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-08-31 20:34:12 +00:00
|
|
|
form = res.forms["tableform"]
|
2023-02-25 17:11:19 +00:00
|
|
|
testclient.post(
|
|
|
|
"/admin/authorization",
|
2023-03-28 18:30:29 +00:00
|
|
|
{"csrf_token": form["csrf_token"].value, "page": "-1"},
|
2023-02-25 17:11:19 +00:00
|
|
|
status=404,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-07 17:29:18 +00:00
|
|
|
def test_authorization_list_search(testclient, logged_admin, client):
|
|
|
|
id1 = gen_salt(48)
|
2023-04-09 09:37:04 +00:00
|
|
|
auth1 = models.AuthorizationCode(
|
2023-05-11 14:02:32 +00:00
|
|
|
authorization_code_id=id1, client=client, subject=logged_admin
|
|
|
|
)
|
2023-03-07 17:29:18 +00:00
|
|
|
auth1.save()
|
|
|
|
|
|
|
|
id2 = gen_salt(48)
|
2023-04-09 09:37:04 +00:00
|
|
|
auth2 = models.AuthorizationCode(
|
2023-05-11 14:02:32 +00:00
|
|
|
authorization_code_id=id2, client=client, subject=logged_admin
|
|
|
|
)
|
2023-03-07 17:29:18 +00:00
|
|
|
auth2.save()
|
|
|
|
|
|
|
|
res = testclient.get("/admin/authorization")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("2 items")
|
|
|
|
res.mustcontain(id1)
|
|
|
|
res.mustcontain(id2)
|
2023-03-07 17:29:18 +00:00
|
|
|
|
|
|
|
form = res.forms["search"]
|
|
|
|
form["query"] = id1
|
|
|
|
res = form.submit()
|
|
|
|
|
2023-06-30 15:42:16 +00:00
|
|
|
res.mustcontain("1 item")
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain(id1)
|
|
|
|
res.mustcontain(no=id2)
|
2023-03-07 17:29:18 +00:00
|
|
|
|
|
|
|
|
2020-08-26 14:27:08 +00:00
|
|
|
def test_authorizaton_view(testclient, authorization, logged_admin):
|
2022-02-16 17:00:30 +00:00
|
|
|
res = testclient.get("/admin/authorization/" + authorization.authorization_code_id)
|
2023-05-16 20:18:38 +00:00
|
|
|
for attr in authorization.attributes:
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain(attr)
|