Skip to content

Commit

Permalink
CR followup
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Apr 17, 2024
1 parent bbd4437 commit 74a045f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 6 additions & 4 deletions addons/base/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from waffle.testutils import override_flag
from urllib.parse import (
urlencode,
urlparse,
parse_qsl,
urlunparse,
)

Expand Down Expand Up @@ -75,9 +75,11 @@ def test_oauth_finish_enable_gv(self, mock_requests_get):
with override_flag(ENABLE_GV, active=True):
request_url = urlunparse(urlparse(url)._replace(query=urlencode(query_params)))
res = self.app.get(request_url, auth=self.user.auth)
mock_requests_get.assert_called_with(
urlunparse(urlparse(GRAVYVALET_URL)._replace(path='callback', query=urlencode(query_params)))
)
gv_callback_url = mock_requests_get.call_args[0][0]
parsed_callback_url = urlparse(gv_callback_url)
assert parsed_callback_url.netloc == urlparse(GRAVYVALET_URL).netloc
assert parsed_callback_url.path == '/v1/oauth/callback'
assert dict(parse_qsl(parsed_callback_url.query)) == query_params

def test_delete_external_account(self):
url = api_url_for(
Expand Down
19 changes: 11 additions & 8 deletions website/oauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ def oauth_connect(service_name, auth):
@must_be_logged_in
def oauth_callback(service_name, auth):
if waffle.flag_is_active(request, features.ENABLE_GV):
code = request.args.get('code')
state = request.args.get('state')
query_params = {
'code': code,
'state': state,
}
gv_url = urlunparse(urlparse(GRAVYVALET_URL)._replace(path='callback', query=urlencode(query_params)))
requests.get(gv_url)
_forward_to_addon_service()
else:
user = auth.user
provider = get_service(service_name)
Expand All @@ -74,3 +67,13 @@ def oauth_callback(service_name, auth):
oauth_complete.send(provider, account=provider.account, user=user)

return {}

def _forward_to_addon_service():
code = request.args.get('code')
state = request.args.get('state')
query_params = {
'code': code,
'state': state,
}
gv_url = urlunparse(urlparse(GRAVYVALET_URL)._replace(path='/v1/oauth/callback', query=urlencode(query_params)))
requests.get(gv_url)

0 comments on commit 74a045f

Please sign in to comment.