mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 07:54:59 -04:00
Refactor OIDC tests to better mimic an actual OIDC provider. (#13910)
This implements a fake OIDC server, which intercepts calls to the HTTP client. Improves accuracy of tests by covering more internal methods. One particular example was the ID token validation, which previously mocked. This uncovered an incorrect dependency: Synapse actually requires at least authlib 0.15.1, not 0.14.0.
This commit is contained in:
parent
2d0ba3f89a
commit
9192d74b0b
10 changed files with 747 additions and 460 deletions
|
@ -275,6 +275,7 @@ class OidcProvider:
|
|||
provider: OidcProviderConfig,
|
||||
):
|
||||
self._store = hs.get_datastores().main
|
||||
self._clock = hs.get_clock()
|
||||
|
||||
self._macaroon_generaton = macaroon_generator
|
||||
|
||||
|
@ -673,6 +674,13 @@ class OidcProvider:
|
|||
Returns:
|
||||
The decoded claims in the ID token.
|
||||
"""
|
||||
id_token = token.get("id_token")
|
||||
logger.debug("Attempting to decode JWT id_token %r", id_token)
|
||||
|
||||
# That has been theoritically been checked by the caller, so even though
|
||||
# assertion are not enabled in production, it is mainly here to appease mypy
|
||||
assert id_token is not None
|
||||
|
||||
metadata = await self.load_metadata()
|
||||
claims_params = {
|
||||
"nonce": nonce,
|
||||
|
@ -688,9 +696,6 @@ class OidcProvider:
|
|||
|
||||
claim_options = {"iss": {"values": [metadata["issuer"]]}}
|
||||
|
||||
id_token = token["id_token"]
|
||||
logger.debug("Attempting to decode JWT id_token %r", id_token)
|
||||
|
||||
# Try to decode the keys in cache first, then retry by forcing the keys
|
||||
# to be reloaded
|
||||
jwk_set = await self.load_jwks()
|
||||
|
@ -715,7 +720,9 @@ class OidcProvider:
|
|||
|
||||
logger.debug("Decoded id_token JWT %r; validating", claims)
|
||||
|
||||
claims.validate(leeway=120) # allows 2 min of clock skew
|
||||
claims.validate(
|
||||
now=self._clock.time(), leeway=120
|
||||
) # allows 2 min of clock skew
|
||||
|
||||
return claims
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue