Skip to content

Commit

Permalink
Implement fix and test for x_token_server error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JonMerlevede committed Sep 17, 2024
1 parent a875667 commit e1ce8bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions tests/unit/oauth_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ def __call__(self, request, uri, response_headers):
if authorization and authorization.replace("Bearer ", "") in self.tokens:
return [200, response_headers, json.dumps(self.sample_post_response_data)]
elif self.redirect_server is None and self.token_server is not None:
return [401, {'Www-Authenticate': f'Bearer x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'}, ""]
return [401, {'Www-Authenticate': f'Bearer x_redirect_server="{self.redirect_server}", '
f'x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'}, ""]
return [401,
{'Www-Authenticate': f'Bearer realm="Trino", token_type="JWT", Bearer x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'},
""]
return [401,
{'Www-Authenticate': f'Bearer realm="Trino", token_type="JWT", Bearer x_redirect_server="{self.redirect_server}", x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'},
""]


class GetTokenCallback:
Expand Down
2 changes: 1 addition & 1 deletion trino/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def _attempt_oauth(self, response: Response, **kwargs: Any) -> None:
auth_info_headers = self._parse_authenticate_header(auth_info)

auth_server = auth_info_headers.get('bearer x_redirect_server', auth_info_headers.get('x_redirect_server'))
token_server = auth_info_headers.get('x_token_server')
token_server = auth_info_headers.get('bearer x_token_server', auth_info_headers.get('x_token_server'))
if token_server is None:
raise exceptions.TrinoAuthError("Error: header info didn't have x_token_server")

Expand Down

0 comments on commit e1ce8bc

Please sign in to comment.