mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 19:43:47 +00:00 
			
		
		
		
	auth: Avoid unchecked casts.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							5733a1bcd4
						
					
				
				
					commit
					f6c73ed45a
				
			| @@ -1,5 +1,5 @@ | ||||
| import re | ||||
| from typing import Any, Dict, Optional | ||||
| from typing import Any, Dict, Mapping, Optional | ||||
|  | ||||
| import redis | ||||
| import ujson | ||||
| @@ -25,7 +25,7 @@ def get_redis_client() -> redis.StrictRedis: | ||||
|                              password=settings.REDIS_PASSWORD, db=0) | ||||
|  | ||||
| def put_dict_in_redis(redis_client: redis.StrictRedis, key_format: str, | ||||
|                       data_to_store: Dict[str, Any], | ||||
|                       data_to_store: Mapping[str, Any], | ||||
|                       expiration_seconds: int, | ||||
|                       token_length: int=64, | ||||
|                       token: Optional[str]=None) -> str: | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import logging | ||||
| import os | ||||
| import urllib | ||||
| from functools import wraps | ||||
| from typing import Any, Dict, List, Mapping, Optional, cast | ||||
| from typing import Any, Dict, List, Mapping, Optional | ||||
|  | ||||
| import jwt | ||||
| from cryptography.hazmat.primitives.ciphers.aead import AESGCM | ||||
| @@ -224,7 +224,7 @@ def register_remote_user(request: HttpRequest, result: ExternalAuthResult) -> Ht | ||||
|     # We have verified the user controls an email address, but | ||||
|     # there's no associated Zulip user account.  Consider sending | ||||
|     # the request to registration. | ||||
|     kwargs = cast(Dict[str, Any], result.copy_data_dict()) | ||||
|     kwargs: Dict[str, Any] = dict(result.data_dict) | ||||
|     # maybe_send_to_registration doesn't take these arguments, so delete them. | ||||
|     kwargs.pop('subdomain', None) | ||||
|     kwargs.pop('redirect_to', None) | ||||
|   | ||||
| @@ -985,7 +985,7 @@ class ExternalAuthResult: | ||||
|                                                                 "with login_token is disallowed.") | ||||
|             self.instantiate_with_token(login_token, delete_stored_data) | ||||
|         else: | ||||
|             self.data_dict = cast(ExternalAuthDataDict, {**data_dict}) | ||||
|             self.data_dict = data_dict.copy() | ||||
|             self.user_profile = user_profile | ||||
|  | ||||
|         if self.user_profile is not None: | ||||
| @@ -1005,11 +1005,8 @@ class ExternalAuthResult: | ||||
|             if not self.user_profile.is_mirror_dummy: | ||||
|                 self.data_dict['is_signup'] = False | ||||
|  | ||||
|     def copy_data_dict(self) -> ExternalAuthDataDict: | ||||
|         return self.data_dict.copy() | ||||
|  | ||||
|     def store_data(self) -> str: | ||||
|         key = put_dict_in_redis(redis_client, self.LOGIN_KEY_FORMAT, cast(Dict[str, Any], self.data_dict), | ||||
|         key = put_dict_in_redis(redis_client, self.LOGIN_KEY_FORMAT, self.data_dict, | ||||
|                                 expiration_seconds=self.LOGIN_KEY_EXPIRATION_SECONDS, | ||||
|                                 token_length=self.LOGIN_TOKEN_LENGTH) | ||||
|         token = key.split(self.LOGIN_KEY_PREFIX, 1)[1]  # remove the prefix | ||||
|   | ||||
		Reference in New Issue
	
	Block a user