mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	zerver/decorator.py: Correctly encode/decode strings.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							4e698ab1f6
						
					
				
				
					commit
					6a63870136
				
			@@ -40,7 +40,6 @@ zerver/tests/test_narrow.py
 | 
				
			|||||||
exclude_py2 = []
 | 
					exclude_py2 = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exclude_py3 = """
 | 
					exclude_py3 = """
 | 
				
			||||||
zerver/decorator.py
 | 
					 | 
				
			||||||
zerver/lib/actions.py
 | 
					zerver/lib/actions.py
 | 
				
			||||||
zerver/lib/bugdown/__init__.py
 | 
					zerver/lib/bugdown/__init__.py
 | 
				
			||||||
zerver/lib/bugdown/codehilite.py
 | 
					zerver/lib/bugdown/codehilite.py
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -348,11 +348,11 @@ def authenticated_rest_api_view(is_webhook=False):
 | 
				
			|||||||
            try:
 | 
					            try:
 | 
				
			||||||
                # Grab the base64-encoded authentication string, decode it, and split it into
 | 
					                # Grab the base64-encoded authentication string, decode it, and split it into
 | 
				
			||||||
                # the email and API key
 | 
					                # the email and API key
 | 
				
			||||||
                auth_type, encoded_value = request.META['HTTP_AUTHORIZATION'].split()
 | 
					                auth_type, b64encoded_credentials = request.META['HTTP_AUTHORIZATION'].split()
 | 
				
			||||||
                # case insensitive per RFC 1945
 | 
					                # case insensitive per RFC 1945
 | 
				
			||||||
                if auth_type.lower() != "basic":
 | 
					                if auth_type.lower() != "basic":
 | 
				
			||||||
                    return json_error(_("Only Basic authentication is supported."))
 | 
					                    return json_error(_("Only Basic authentication is supported."))
 | 
				
			||||||
                role, api_key = base64.b64decode(encoded_value).split(":")
 | 
					                role, api_key = base64.b64decode(b64encoded_credentials.encode('utf-8')).decode('utf-8').split(":")
 | 
				
			||||||
            except ValueError:
 | 
					            except ValueError:
 | 
				
			||||||
                json_error(_("Invalid authorization header for basic auth"))
 | 
					                json_error(_("Invalid authorization header for basic auth"))
 | 
				
			||||||
            except KeyError:
 | 
					            except KeyError:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user