Fixing a python test (#1154)

* fixing a test, it now *should* fail, which is nice
* running `black` on code
This commit is contained in:
James Hodgkinson 2022-10-31 22:23:24 +10:00 committed by GitHub
parent db75a0b344
commit 58155c613f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 8 deletions

View file

@ -1,4 +1,3 @@
""" kanidm RADIUS module """ """ kanidm RADIUS module """
import asyncio import asyncio
from functools import reduce from functools import reduce
@ -33,7 +32,6 @@ def instantiate(_: Any) -> Any:
) )
logging.info("Starting up!") logging.info("Starting up!")
config_path = None config_path = None
for config_file_path in CONFIG_PATHS: for config_file_path in CONFIG_PATHS:
config_path = Path(config_file_path).expanduser().resolve() config_path = Path(config_file_path).expanduser().resolve()
@ -54,6 +52,7 @@ def instantiate(_: Any) -> Any:
logging.info("Config file: %s", config_path.as_posix()) logging.info("Config file: %s", config_path.as_posix())
return radiusd.RLM_MODULE_OK return radiusd.RLM_MODULE_OK
async def _get_radius_token( async def _get_radius_token(
username: Optional[str] = None, username: Optional[str] = None,
) -> Optional[Dict[str, Any]]: ) -> Optional[Dict[str, Any]]:
@ -74,6 +73,7 @@ async def _get_radius_token(
logging.debug(response.data) logging.debug(response.data)
return response.data return response.data
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
def authorize( def authorize(
args: Any = Dict[Any, Any], args: Any = Dict[Any, Any],
@ -120,7 +120,9 @@ def authorize(
except Exception as error_message: # pylint: disable=broad-except except Exception as error_message: # pylint: disable=broad-except
logging.error("kanidm exception: %s, %s", type(error_message), error_message) logging.error("kanidm exception: %s, %s", type(error_message), error_message)
if tok is None: if tok is None:
logging.info("kanidm RLM_MODULE_REJECT - unable to retrieve radius information token") logging.info(
"kanidm RLM_MODULE_REJECT - unable to retrieve radius information token"
)
return radiusd.RLM_MODULE_REJECT return radiusd.RLM_MODULE_REJECT
# Get values out of the token # Get values out of the token
@ -164,8 +166,6 @@ def authorize(
return (radiusd.RLM_MODULE_OK, reply, config_object) return (radiusd.RLM_MODULE_OK, reply, config_object)
def authenticate( def authenticate(
acct: str, acct: str,
password: str, password: str,

View file

@ -7,6 +7,7 @@ import os
from .. import KanidmClient from .. import KanidmClient
from ..types import RadiusTokenGroup from ..types import RadiusTokenGroup
def check_vlan( def check_vlan(
acc: int, acc: int,
group: RadiusTokenGroup, group: RadiusTokenGroup,
@ -25,7 +26,9 @@ def check_vlan(
for radius_group in kanidm_client.config.radius_groups: for radius_group in kanidm_client.config.radius_groups:
logging.debug( logging.debug(
"Checking vlan group '%s' against user group %s", radius_group.spn, group.spn "Checking vlan group '%s' against user group %s",
radius_group.spn,
group.spn,
) )
if radius_group.spn == group.spn: if radius_group.spn == group.spn:
logging.info("returning new vlan: %s", radius_group.vlan) logging.info("returning new vlan: %s", radius_group.vlan)

View file

@ -22,7 +22,9 @@ async def test_radius_call(client_configfile: KanidmClient) -> None:
print("Doing auth_init using token") print("Doing auth_init using token")
if client_configfile.config.auth_token is None: if client_configfile.config.auth_token is None:
pytest.skip("You can't test auth if you don't have an auth_token in ~/.config/kanidm") pytest.skip(
"You can't test auth if you don't have an auth_token in ~/.config/kanidm"
)
result = await client_configfile.get_radius_token(RADIUS_TEST_USER) result = await client_configfile.get_radius_token(RADIUS_TEST_USER)
print(f"{result=}") print(f"{result=}")

View file

@ -112,10 +112,19 @@ async def test_ssl_wrong_hostname_verify_certificate() -> None:
@pytest.mark.network @pytest.mark.network
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_ssl_revoked() -> None: async def test_ssl_revoked() -> None:
"""tests with a revoked certificate, it'll pass but one day this should be a thing""" """tests with a revoked certificate"""
with pytest.raises(aiohttp.ClientConnectorCertificateError):
client = KanidmClient(
uri="https://revoked.badssl.com/",
verify_certificate=True,
)
result = await client.call_get("/")
assert result.content
client = KanidmClient( client = KanidmClient(
uri="https://revoked.badssl.com/", uri="https://revoked.badssl.com/",
verify_certificate=False,
) )
result = await client.call_get("/") result = await client.call_get("/")
assert result.content assert result.content