Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 37fb198

Browse files
committed
Fix some types in the CAS code.
1 parent 79bfe96 commit 37fb198

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

changelog.d/8784.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix type hints in CAS handler.

synapse/handlers/cas_handler.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
import logging
1616
import urllib
17-
from typing import Dict, Optional, Tuple
17+
from typing import TYPE_CHECKING, Dict, Optional, Tuple
1818
from xml.etree import ElementTree as ET
1919

2020
from twisted.web.client import PartialDownloadError
@@ -23,6 +23,9 @@
2323
from synapse.http.site import SynapseRequest
2424
from synapse.types import UserID, map_username_to_mxid_localpart
2525

26+
if TYPE_CHECKING:
27+
from synapse.app.homeserver import HomeServer
28+
2629
logger = logging.getLogger(__name__)
2730

2831

@@ -31,10 +34,10 @@ class CasHandler:
3134
Utility class for to handle the response from a CAS SSO service.
3235
3336
Args:
34-
hs (synapse.server.HomeServer)
37+
hs
3538
"""
3639

37-
def __init__(self, hs):
40+
def __init__(self, hs: "HomeServer"):
3841
self.hs = hs
3942
self._hostname = hs.hostname
4043
self._auth_handler = hs.get_auth_handler()
@@ -205,11 +208,16 @@ async def handle_ticket(
205208
registered_user_id = await self._auth_handler.check_user_exists(user_id)
206209

207210
if session:
211+
# If there's a session then the user must already exist.
212+
assert registered_user_id
213+
208214
await self._auth_handler.complete_sso_ui_auth(
209215
registered_user_id, session, request,
210216
)
211-
212217
else:
218+
# If this not a UI auth request than there must be a redirect URL.
219+
assert client_redirect_url
220+
213221
if not registered_user_id:
214222
# Pull out the user-agent and IP from the request.
215223
user_agent = request.get_user_agent("")
@@ -221,6 +229,8 @@ async def handle_ticket(
221229
user_agent_ips=(user_agent, ip_address),
222230
)
223231

232+
assert registered_user_id
233+
224234
await self._auth_handler.complete_sso_login(
225235
registered_user_id, request, client_redirect_url
226236
)

synapse/handlers/register.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def register_user(
152152
bind_emails=[],
153153
by_admin=False,
154154
user_agent_ips=None,
155-
):
155+
) -> str:
156156
"""Registers a new client on the server.
157157
158158
Args:

synapse/handlers/saml_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from synapse.util.iterutils import chunk_seq
4040

4141
if TYPE_CHECKING:
42-
import synapse.server
42+
from synapse.server import HomeServer
4343

4444
logger = logging.getLogger(__name__)
4545

@@ -56,7 +56,7 @@ class Saml2SessionData:
5656

5757

5858
class SamlHandler(BaseHandler):
59-
def __init__(self, hs: "synapse.server.HomeServer"):
59+
def __init__(self, hs: "HomeServer"):
6060
super().__init__(hs)
6161
self._saml_client = Saml2Client(hs.config.saml2_sp_config)
6262
self._saml_idp_entityid = hs.config.saml2_idp_entityid

0 commit comments

Comments
 (0)