Skip to content

Commit decc312

Browse files
committed
Merge tag '24.07.3' into develop
[ENG-6096] Fix incorrectly generated CAS login URL #10763
2 parents 835eb2e + 6cb0fb1 commit decc312

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

framework/auth/cas.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from furl import furl
2-
from urllib.parse import unquote_plus
32

43
from django.utils import timezone
54
from rest_framework import status as http_status
@@ -304,11 +303,11 @@ def make_response_from_ticket(ticket, service_url):
304303
f'CAS response - redirect existing external IdP login to verification key login: user=[{user._id}]',
305304
LogLevel.INFO
306305
)
307-
return redirect(get_logout_url(unquote_plus(get_login_url(
306+
return redirect(get_logout_url(get_login_url(
308307
service_url,
309308
username=user.username,
310309
verification_key=user.verification_key
311-
))))
310+
)))
312311

313312
# if user is authenticated by CAS
314313
print_cas_log(f'CAS response - finalizing authentication: user=[{user._id}]', LogLevel.INFO)

tests/test_auth.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ def test_successful_external_login_cas_redirect(self, mock_service_validate, moc
135135
resp = cas.make_response_from_ticket(ticket, service_url)
136136
assert resp.status_code == 302, 'redirect to CAS login'
137137
assert quote_plus('/login?service=') in resp.location
138-
139-
# the valid username will be double quoted as it is furl quoted in both get_login_url and get_logout_url in order
140-
assert quote_plus(f'username={user.username}') in resp.location
141-
assert quote_plus(f'verification_key={user.verification_key}') in resp.location
138+
# the valid username and verification key should be double-quoted
139+
assert quote_plus(f'username={quote_plus(user.username)}') in resp.location
140+
assert quote_plus(f'verification_key={quote_plus(user.verification_key)}') in resp.location
142141

143142
@mock.patch('framework.auth.cas.get_user_from_cas_resp')
144143
@mock.patch('framework.auth.cas.CasClient.service_validate')

tests/test_views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ def test_claim_user_when_user_is_registered_with_orcid(self, mock_response_from_
26112611
assert res1.status_code == 302
26122612
res = self.app.resolve_redirect(self.app.get(url))
26132613
service_url = f'http://localhost{url}'
2614-
expected = cas.get_logout_url(service_url=unquote_plus(cas.get_login_url(service_url=service_url)))
2614+
expected = cas.get_logout_url(service_url=cas.get_login_url(service_url=service_url))
26152615
assert res1.location == expected
26162616

26172617
# user logged in with orcid automatically becomes a contributor
@@ -2631,7 +2631,7 @@ def test_claim_user_when_user_is_registered_with_orcid(self, mock_response_from_
26312631
# And the redirect URL must equal to the originial service URL
26322632
assert res.status_code == 302
26332633
redirect_url = res.headers['Location']
2634-
assert unquote_plus(redirect_url) == url
2634+
assert redirect_url == url
26352635
# The response of this request is expected have the `Set-Cookie` header with OSF cookie.
26362636
# And the cookie must belong to the ORCiD user.
26372637
raw_set_cookie = res.headers['Set-Cookie']

website/project/views/contributor.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from urllib.parse import unquote_plus
2-
31
from rest_framework import status as http_status
42

53
from flask import request
@@ -669,7 +667,7 @@ def claim_user_registered(auth, node, **kwargs):
669667
current_user = auth.user
670668
current_session = get_session()
671669

672-
sign_out_url = cas.get_logout_url(service_url=unquote_plus(cas.get_login_url(service_url=request.url)))
670+
sign_out_url = cas.get_logout_url(service_url=cas.get_login_url(service_url=request.url))
673671
if not current_user:
674672
return redirect(sign_out_url)
675673

0 commit comments

Comments
 (0)