canaille-globuzma/tests/test_client_admin.py

87 lines
3.1 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
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",
}
for k, v in data.items():
res.form[k] = v
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)
for k, v in data.items():
client_value = getattr(client, k)
if k == "oauthScope":
assert v == " ".join(client_value)
else:
assert v == client_value
def test_client_edit(testclient, client, logged_admin, slapd_connection):
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",
}
for k, v in data.items():
res.forms["clientadd"][k] = 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
client.reload(conn=slapd_connection)
for k, v in data.items():
client_value = getattr(client, k)
if k == "oauthScope":
assert v == " ".join(client_value)
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