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")
|
2022-10-17 15:49:52 +00:00
|
|
|
assert client.client_name in res.text
|
2020-08-26 13:37:15 +00:00
|
|
|
|
|
|
|
|
2022-05-19 10:36:39 +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 = {
|
2022-10-17 15:49:52 +00:00
|
|
|
"client_name": "foobar",
|
|
|
|
"contacts": "foo@bar.com",
|
|
|
|
"client_uri": "https://foo.bar",
|
2022-01-11 16:57:58 +00:00
|
|
|
"redirect_uris": ["https:/foo.bar/callback"],
|
2022-10-17 15:49:52 +00:00
|
|
|
"grant_types": ["password", "authorization_code"],
|
2022-01-11 16:57:58 +00:00
|
|
|
"scope": "openid profile",
|
2022-10-17 15:49:52 +00:00
|
|
|
"response_types": ["code", "token"],
|
2022-01-11 16:57:58 +00:00
|
|
|
"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",
|
2022-10-17 15:49:52 +00:00
|
|
|
"jwks_uri": "https://foo.bar/jwks.json",
|
2022-01-11 16:57:58 +00:00
|
|
|
"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
|
|
|
|
2022-01-11 16:57:58 +00:00
|
|
|
client_id = res.forms["readonly"]["client_id"].value
|
2022-05-08 14:31:17 +00:00
|
|
|
client = Client.get(client_id)
|
2022-01-11 16:57:58 +00:00
|
|
|
data["audience"] = [client.dn]
|
2020-08-26 13:37:15 +00:00
|
|
|
for k, v in data.items():
|
|
|
|
client_value = getattr(client, k)
|
2022-01-11 16:57:58 +00:00
|
|
|
if k == "scope":
|
2020-08-26 13:37:15 +00:00
|
|
|
assert v == " ".join(client_value)
|
2022-01-11 16:57:58 +00:00
|
|
|
elif k == "preconsent":
|
2021-10-20 10:05:08 +00:00
|
|
|
assert v is False
|
2022-10-17 15:49:52 +00:00
|
|
|
elif k == "contacts":
|
|
|
|
assert [v] == client_value
|
2020-08-26 13:37:15 +00:00
|
|
|
else:
|
|
|
|
assert v == client_value
|
2022-12-04 12:41:09 +00:00
|
|
|
client.delete()
|
2020-08-26 13:37:15 +00:00
|
|
|
|
|
|
|
|
2022-12-14 18:29:59 +00:00
|
|
|
def test_add_missing_fields(testclient, logged_admin):
|
|
|
|
res = testclient.get("/admin/client/add")
|
|
|
|
res = res.form.submit(status=200, name="action", value="edit")
|
|
|
|
assert "The client has not been added. Please check your information." in res
|
|
|
|
|
|
|
|
|
2022-05-19 10:36:39 +00:00
|
|
|
def test_client_edit(testclient, client, logged_admin, other_client):
|
2022-01-11 16:57:58 +00:00
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
2020-08-26 13:37:15 +00:00
|
|
|
data = {
|
2022-10-17 15:49:52 +00:00
|
|
|
"client_name": "foobar",
|
|
|
|
"contacts": "foo@bar.com",
|
|
|
|
"client_uri": "https://foo.bar",
|
2022-01-11 16:57:58 +00:00
|
|
|
"redirect_uris": ["https:/foo.bar/callback"],
|
2022-10-17 15:49:52 +00:00
|
|
|
"grant_types": ["password", "authorization_code"],
|
2022-01-11 16:57:58 +00:00
|
|
|
"scope": "openid profile",
|
2022-10-17 15:49:52 +00:00
|
|
|
"response_types": ["code", "token"],
|
2022-01-11 16:57:58 +00:00
|
|
|
"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",
|
2022-10-17 15:49:52 +00:00
|
|
|
"jwks_uri": "https://foo.bar/jwks.json",
|
2022-01-11 16:57:58 +00:00
|
|
|
"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)
|
2023-01-28 18:02:00 +00:00
|
|
|
res = res.forms["clientadd"].submit(status=302, name="action", value="edit")
|
2020-08-26 13:37:15 +00:00
|
|
|
|
2021-10-13 09:52:02 +00:00
|
|
|
assert (
|
2023-01-28 18:02:00 +00:00
|
|
|
"error",
|
|
|
|
"The client has not been edited. Please check your information.",
|
|
|
|
) not in res.flashes
|
|
|
|
assert ("success", "The client has been edited.") in res.flashes
|
2021-10-13 09:52:02 +00:00
|
|
|
|
2022-05-08 14:31:17 +00:00
|
|
|
client = Client.get(client.dn)
|
2020-08-26 13:37:15 +00:00
|
|
|
for k, v in data.items():
|
|
|
|
client_value = getattr(client, k)
|
2022-01-11 16:57:58 +00:00
|
|
|
if k == "scope":
|
2020-08-26 13:37:15 +00:00
|
|
|
assert v == " ".join(client_value)
|
2022-01-11 16:57:58 +00:00
|
|
|
elif k == "preconsent":
|
2021-10-20 10:05:08 +00:00
|
|
|
assert v is True
|
2022-10-17 15:49:52 +00:00
|
|
|
elif k == "contacts":
|
|
|
|
assert [v] == client_value
|
2020-08-26 13:37:15 +00:00
|
|
|
else:
|
|
|
|
assert v == client_value
|
2020-11-23 16:32:40 +00:00
|
|
|
|
2022-11-16 16:36:16 +00:00
|
|
|
|
2022-12-14 18:29:59 +00:00
|
|
|
def test_client_edit_missing_fields(testclient, client, logged_admin, other_client):
|
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
|
|
|
res.forms["clientadd"]["client_name"] = ""
|
|
|
|
res = res.forms["clientadd"].submit(name="action", value="edit")
|
|
|
|
assert "The client has not been edited. Please check your information." in res
|
|
|
|
client.reload()
|
|
|
|
assert client.client_name
|
|
|
|
|
|
|
|
|
2022-12-13 18:14:25 +00:00
|
|
|
def test_client_delete(testclient, logged_admin):
|
|
|
|
client = Client(client_id="client_id")
|
|
|
|
client.save()
|
|
|
|
|
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
|
|
|
res = res.forms["clientadd"].submit(name="action", value="delete").follow()
|
|
|
|
|
2022-12-14 20:03:35 +00:00
|
|
|
|
|
|
|
def test_client_delete_invalid_client(testclient, logged_admin):
|
|
|
|
testclient.post("/admin/client/edit/invalid", {"action": "delete"}, status=404)
|
2022-12-13 18:14:25 +00:00
|
|
|
|
|
|
|
|
2022-12-13 18:15:54 +00:00
|
|
|
def test_invalid_request(testclient, logged_admin, client):
|
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
|
|
|
res = res.forms["clientadd"].submit(name="action", value="invalid", status=400)
|
|
|
|
|
|
|
|
|
2022-11-16 16:36:16 +00:00
|
|
|
def test_client_edit_preauth(testclient, client, logged_admin, other_client):
|
|
|
|
assert not client.preconsent
|
|
|
|
|
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
|
|
|
res.forms["clientadd"]["preconsent"] = True
|
2023-01-28 18:02:00 +00:00
|
|
|
res = res.forms["clientadd"].submit(name="action", value="edit")
|
2022-11-16 16:36:16 +00:00
|
|
|
|
2023-01-28 18:02:00 +00:00
|
|
|
assert ("success", "The client has been edited.") in res.flashes
|
2022-11-16 16:36:16 +00:00
|
|
|
client = Client.get(client.dn)
|
|
|
|
assert client.preconsent
|
|
|
|
|
|
|
|
res = testclient.get("/admin/client/edit/" + client.client_id)
|
|
|
|
res.forms["clientadd"]["preconsent"] = False
|
2023-01-28 18:02:00 +00:00
|
|
|
res = res.forms["clientadd"].submit(name="action", value="edit")
|
2022-11-16 16:36:16 +00:00
|
|
|
|
2023-01-28 18:02:00 +00:00
|
|
|
assert ("success", "The client has been edited.") in res.flashes
|
2022-11-16 16:36:16 +00:00
|
|
|
client = Client.get(client.dn)
|
|
|
|
assert not client.preconsent
|