canaille-globuzma/tests/test_client_admin.py

104 lines
3.6 KiB
Python
Raw Normal View History

2020-10-21 12:04:40 +00:00
from canaille.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")
2020-08-26 13:37:15 +00:00
assert client.oauthClientName in res.text
def test_client_add(testclient, logged_admin, slapd_connection):
2020-08-26 15:23:53 +00:00
res = testclient.get("/admin/client/add")
2020-08-26 13:37:15 +00:00
data = {
"oauthClientName": "foobar",
"oauthClientContact": "foo@bar.com",
"oauthClientURI": "https://foo.bar",
"oauthRedirectURIs": ["https:/foo.bar/callback"],
"oauthGrantType": ["password", "authorization_code"],
"oauthScope": "openid profile",
"oauthResponseType": ["code", "token"],
"oauthTokenEndpointAuthMethod": "none",
"oauthLogoURI": "https://foo.bar/logo.png",
"oauthTermsOfServiceURI": "https://foo.bar/tos",
"oauthPolicyURI": "https://foo.bar/policy",
"oauthSoftwareID": "software",
"oauthSoftwareVersion": "1",
"oauthJWK": "jwk",
"oauthJWKURI": "https://foo.bar/jwks.json",
2021-10-13 09:52:02 +00:00
"oauthAudience": [],
2021-10-20 10:05:08 +00:00
"oauthPreconsent": False,
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"]["oauthClientID"].value
client = Client.get(client_id, conn=slapd_connection)
2021-10-13 09:52:02 +00:00
data["oauthAudience"] = [client.dn]
2020-08-26 13:37:15 +00:00
for k, v in data.items():
client_value = getattr(client, k)
if k == "oauthScope":
assert v == " ".join(client_value)
2021-10-20 10:05:08 +00:00
elif k == "oauthPreconsent":
assert v is False
2020-08-26 13:37:15 +00:00
else:
assert v == client_value
2021-10-13 09:52:02 +00:00
def test_client_edit(testclient, client, logged_admin, slapd_connection, other_client):
2020-08-26 15:23:53 +00:00
res = testclient.get("/admin/client/edit/" + client.oauthClientID)
2020-08-26 13:37:15 +00:00
data = {
"oauthClientName": "foobar",
"oauthClientContact": "foo@bar.com",
"oauthClientURI": "https://foo.bar",
"oauthRedirectURIs": ["https:/foo.bar/callback"],
"oauthGrantType": ["password", "authorization_code"],
"oauthScope": "openid profile",
"oauthResponseType": ["code", "token"],
"oauthTokenEndpointAuthMethod": "none",
"oauthLogoURI": "https://foo.bar/logo.png",
"oauthTermsOfServiceURI": "https://foo.bar/tos",
"oauthPolicyURI": "https://foo.bar/policy",
"oauthSoftwareID": "software",
"oauthSoftwareVersion": "1",
"oauthJWK": "jwk",
"oauthJWKURI": "https://foo.bar/jwks.json",
2021-10-13 09:52:02 +00:00
"oauthAudience": [client.dn, other_client.dn],
2021-10-20 10:05:08 +00:00
"oauthPreconsent": True,
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, conn=slapd_connection)
2020-08-26 13:37:15 +00:00
for k, v in data.items():
client_value = getattr(client, k)
if k == "oauthScope":
assert v == " ".join(client_value)
2021-10-20 10:05:08 +00:00
elif k == "oauthPreconsent":
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.oauthClientID, conn=slapd_connection) is None