Browse Source

fix: applied flake linting checks

pull/358/head
Luca Paganin 2 years ago
parent
commit
96085b7b1d
  1. 8
      poetry.lock
  2. 2
      pyproject.toml
  3. 49
      src/keycloak/keycloak_admin.py
  4. 4
      tests/conftest.py
  5. 7
      tests/test_keycloak_admin.py

8
poetry.lock

@ -102,7 +102,7 @@ python-versions = ">=3.6"
name = "cffi"
version = "1.15.1"
description = "Foreign Function Interface for Python calling C code."
category = "main"
category = "dev"
optional = false
python-versions = "*"
@ -197,7 +197,7 @@ toml = ["tomli"]
name = "cryptography"
version = "37.0.4"
description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
category = "main"
category = "dev"
optional = false
python-versions = ">=3.6"
@ -544,7 +544,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
name = "pycparser"
version = "2.21"
description = "C parser in Python"
category = "main"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
@ -1039,7 +1039,7 @@ docs = ["mock", "alabaster", "commonmark", "recommonmark", "Sphinx", "sphinx-rtd
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "add6d6f1a2e9ec5cf7aae027fd49d5fcafd212963daa3257d363909aedb380be"
content-hash = "b6851001fb6b3e331a39e6bab1fa2ed99fdc555e9683137c20c9c593c0e1c040"
[metadata.files]
alabaster = [

2
pyproject.toml

@ -43,7 +43,6 @@ readthedocs-sphinx-ext = {version = "^2.1.8", optional = true}
m2r2 = {version = "^0.3.2", optional = true}
sphinx-autoapi = {version = "^1.8.4", optional = true}
requests-toolbelt = "^0.9.1"
cryptography = "^37.0.4"
[tool.poetry.dev-dependencies]
tox = "^3.25.0"
@ -56,6 +55,7 @@ black = "^22.3.0"
flake8 = "^3.5.0"
flake8-docstrings = "^1.6.0"
commitizen = "^2.28.0"
cryptography = "^37.0.4"
[tool.poetry.extras]
docs = [

49
src/keycloak/keycloak_admin.py

@ -2815,13 +2815,13 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def get_composite_client_roles_of_group(self, client_id, group_id):
"""Get the composite client roles of the given group for the given client
"""Get the composite client roles of the given group for the given client.
:param client_id: id of the client
:param client_id: id of the client.
:type client_id: str
:param group_id: id of the group
:param group_id: id of the group.
:type group_id: str
:return: the composite client roles of the group (list of RoleRepresentation)
:return: the composite client roles of the group (list of RoleRepresentation).
:rtype: list
"""
params_path = {"realm-name": self.realm_name, "id": group_id, "client-id": client_id}
@ -2831,13 +2831,13 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakGetError)
def get_role_client_level_children(self, client_id, role_id):
"""Get the child roles of which the given composite client role is composed of
"""Get the child roles of which the given composite client role is composed of.
:param client_id: id of the client
:param client_id: id of the client.
:type client_id: str
:param role_id: id of the role
:param role_id: id of the role.
:type role_id: str
:return: the child roles (list of RoleRepresentation)
:return: the child roles (list of RoleRepresentation).
:rtype: list
"""
params_path = {"realm-name": self.realm_name, "role-id": role_id, "client-id": client_id}
@ -2845,11 +2845,11 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakGetError)
def get_user_credentials(self, user_id):
"""Get the credentials of the given user
"""Get the credentials of the given user.
:param user_id: id of the user
:param user_id: id of the user.
:type user_id: str
:return: the user credentials (list of CredentialsRepresentation)
:return: the user credentials (list of CredentialsRepresentation).
:rtype: list
"""
params_path = {"realm-name": self.realm_name, "id": user_id}
@ -2857,13 +2857,14 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakGetError)
def upload_certificate(self, client_id, certcont):
"""Upload a new certificate for the client
"""Upload a new certificate for the client.
:param client_id: id of the client
:param client_id: id of the client.
:type client_id: str
:param certcont: the content of the certificate
:param certcont: the content of the certificate.
:type certcont: str
:return: dictionary {"certificate": "<certcont>"}, where <certcont> is the content of the uploaded certificate
:return: dictionary {"certificate": "<certcont>"},
where <certcont> is the content of the uploaded certificate.
:rtype: dict
"""
params_path = {"realm-name": self.realm_name, "id": client_id, "attr": "jwt.credential"}
@ -2879,11 +2880,11 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakPostError)
def get_required_action_by_alias(self, action_alias):
"""Get a required action by its alias
"""Get a required action by its alias.
:param action_alias: the alias of the requried action
:param action_alias: the alias of the requried action.
:type action_alias: str
:return: the required action (RequiredActionProviderRepresentation)
:return: the required action (RequiredActionProviderRepresentation).
:rtype: dict
"""
actions = self.get_required_actions()
@ -2893,9 +2894,9 @@ class KeycloakAdmin:
return a
def get_required_actions(self):
"""Get the required actions for the realms
"""Get the required actions for the realms.
:return: the required actions (list of RequiredActionProviderRepresentation)
:return: the required actions (list of RequiredActionProviderRepresentation).
:rtype: list
"""
params_path = {"realm-name": self.realm_name}
@ -2903,13 +2904,13 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakGetError)
def update_required_action(self, action_alias, payload):
"""Update a required action
"""Update a required action.
:param action_alias: the action alias
:param action_alias: the action alias.
:type action_alias: str
:param payload: the new required action (RequiredActionProviderRepresentation)
:param payload: the new required action (RequiredActionProviderRepresentation).
:type payload: dict
:return: empty dictionary
:return: empty dictionary.
:rtype: dict
"""
if not isinstance(payload, str):

4
tests/conftest.py

@ -283,7 +283,7 @@ def composite_client_role(admin: KeycloakAdmin, realm: str, client: str, client_
@pytest.fixture
def selfsigned_cert():
"""Generates self signed certificate for a hostname, and optional IP addresses."""
"""Generate self signed certificate for a hostname, and optional IP addresses."""
import ipaddress
from datetime import datetime, timedelta
@ -303,8 +303,6 @@ def selfsigned_cert():
)
name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, hostname)])
# best practice seem to be to include the hostname in the SAN, which *SHOULD* mean COMMON_NAME is ignored.
alt_names = [x509.DNSName(hostname)]
# allow addressing by IP, for when you don't have real DNS (common in most testing scenarios

7
tests/test_keycloak_admin.py

@ -1820,6 +1820,7 @@ def test_auto_refresh(admin: KeycloakAdmin, realm: str):
def test_get_required_actions(admin: KeycloakAdmin, realm: str):
"""Test requried actions."""
admin.realm_name = realm
ractions = admin.get_required_actions()
assert isinstance(ractions, list)
@ -1837,6 +1838,7 @@ def test_get_required_actions(admin: KeycloakAdmin, realm: str):
def test_get_required_action_by_alias(admin: KeycloakAdmin, realm: str):
"""Test get required action by alias."""
admin.realm_name = realm
ractions = admin.get_required_actions()
ra = admin.get_required_action_by_alias("UPDATE_PASSWORD")
@ -1845,6 +1847,7 @@ def test_get_required_action_by_alias(admin: KeycloakAdmin, realm: str):
def test_update_required_action(admin: KeycloakAdmin, realm: str):
"""Test update required action."""
admin.realm_name = realm
ra = admin.get_required_action_by_alias("UPDATE_PASSWORD")
old = copy.deepcopy(ra)
@ -1858,6 +1861,7 @@ def test_update_required_action(admin: KeycloakAdmin, realm: str):
def test_get_composite_client_roles_of_group(
admin: KeycloakAdmin, realm: str, client: str, group: str, composite_client_role: str
):
"""Test get composite client roles of group."""
admin.realm_name = realm
role = admin.get_client_role(client, composite_client_role)
admin.assign_group_client_roles(group_id=group, client_id=client, roles=[role])
@ -1868,6 +1872,7 @@ def test_get_composite_client_roles_of_group(
def test_get_role_client_level_children(
admin: KeycloakAdmin, realm: str, client: str, composite_client_role: str, client_role: str
):
"""Test get children of composite client role."""
admin.realm_name = realm
child = admin.get_client_role(client, client_role)
parent = admin.get_client_role(client, composite_client_role)
@ -1876,6 +1881,7 @@ def test_get_role_client_level_children(
def test_get_user_credentials(admin: KeycloakAdmin, realm: str, user: str):
"""Test get user credentials."""
admin.realm_name = realm
admin.set_user_password(user, "pwd", temporary=False)
res = admin.get_user_credentials(user)
@ -1885,6 +1891,7 @@ def test_get_user_credentials(admin: KeycloakAdmin, realm: str, user: str):
def test_upload_certificate(admin: KeycloakAdmin, realm: str, client: str, selfsigned_cert: tuple):
"""Test upload certificate."""
admin.realm_name = realm
cert, _ = selfsigned_cert
cert = cert.decode("utf-8").strip()

Loading…
Cancel
Save