canaille-globuzma/tests/oidc/test_client_admin.py

106 lines
3.4 KiB
Python
Raw Normal View History

2022-01-11 18:49:06 +00:00
from canaille.oidc.models import Client
2020-08-26 13:37:15 +00:00
def test_no_logged_no_access(testclient):
2020-08-26 15:23:53 +00:00
testclient.get("/admin/client", status=403)
2020-08-26 13:37:15 +00:00
def test_no_admin_no_access(testclient, logged_user):
2020-08-26 15:23:53 +00:00
testclient.get("/admin/client", status=403)
2020-08-26 13:37:15 +00:00
2021-10-20 10:05:08 +00:00
def test_invalid_client_edition(testclient, logged_admin):
testclient.get("/admin/client/edit/invalid", status=404)
2020-08-26 13:37:15 +00:00
def test_client_list(testclient, client, logged_admin):
2020-08-26 15:23:53 +00:00
res = testclient.get("/admin/client")
assert client.name in res.text
2020-08-26 13:37:15 +00:00
def test_client_add(testclient, logged_admin):
2020-08-26 15:23:53 +00:00
res = testclient.get("/admin/client/add")
2020-08-26 13:37:15 +00:00
data = {
"name": "foobar",
"contact": "foo@bar.com",
"uri": "https://foo.bar",
"redirect_uris": ["https:/foo.bar/callback"],
"grant_type": ["password", "authorization_code"],
"scope": "openid profile",
"response_type": ["code", "token"],
"token_endpoint_auth_method": "none",
"logo_uri": "https://foo.bar/logo.png",
"tos_uri": "https://foo.bar/tos",
"policy_uri": "https://foo.bar/policy",
"software_id": "software",
"software_version": "1",
"jwk": "jwk",
"jwk_uri": "https://foo.bar/jwks.json",
"audience": [],
"preconsent": False,
2022-05-20 12:07:56 +00:00
"post_logout_redirect_uris": ["https://foo.bar/disconnected"],
2020-08-26 13:37:15 +00:00
}
for k, v in data.items():
2021-10-13 09:52:02 +00:00
res.form[k].force_value(v)
2020-08-26 13:37:15 +00:00
2020-11-23 16:32:40 +00:00
res = res.form.submit(status=302, name="action", value="edit")
2020-10-30 22:41:02 +00:00
res = res.follow(status=200)
2020-08-26 13:37:15 +00:00
client_id = res.forms["readonly"]["client_id"].value
client = Client.get(client_id)
data["audience"] = [client.dn]
2020-08-26 13:37:15 +00:00
for k, v in data.items():
client_value = getattr(client, k)
if k == "scope":
2020-08-26 13:37:15 +00:00
assert v == " ".join(client_value)
elif k == "preconsent":
2021-10-20 10:05:08 +00:00
assert v is False
2020-08-26 13:37:15 +00:00
else:
assert v == client_value
def test_client_edit(testclient, client, logged_admin, other_client):
res = testclient.get("/admin/client/edit/" + client.client_id)
2020-08-26 13:37:15 +00:00
data = {
"name": "foobar",
"contact": "foo@bar.com",
"uri": "https://foo.bar",
"redirect_uris": ["https:/foo.bar/callback"],
"grant_type": ["password", "authorization_code"],
"scope": "openid profile",
"response_type": ["code", "token"],
"token_endpoint_auth_method": "none",
"logo_uri": "https://foo.bar/logo.png",
"tos_uri": "https://foo.bar/tos",
"policy_uri": "https://foo.bar/policy",
"software_id": "software",
"software_version": "1",
"jwk": "jwk",
"jwk_uri": "https://foo.bar/jwks.json",
"audience": [client.dn, other_client.dn],
"preconsent": True,
2022-05-20 12:07:56 +00:00
"post_logout_redirect_uris": ["https://foo.bar/disconnected"],
2020-08-26 13:37:15 +00:00
}
for k, v in data.items():
2021-10-13 09:52:02 +00:00
res.forms["clientadd"][k].force_value(v)
2020-11-23 16:32:40 +00:00
res = res.forms["clientadd"].submit(status=200, name="action", value="edit")
2020-08-26 13:37:15 +00:00
2021-10-13 09:52:02 +00:00
assert (
"The client has not been edited. Please check your information." not in res.text
)
client = Client.get(client.dn)
2020-08-26 13:37:15 +00:00
for k, v in data.items():
client_value = getattr(client, k)
if k == "scope":
2020-08-26 13:37:15 +00:00
assert v == " ".join(client_value)
elif k == "preconsent":
2021-10-20 10:05:08 +00:00
assert v is True
2020-08-26 13:37:15 +00:00
else:
assert v == client_value
2020-11-23 16:32:40 +00:00
res.forms["clientadd"].submit(status=302, name="action", value="delete").follow(
status=200
)
assert Client.get(client.client_id) is None