fix(auth): accept SSO callback without trailing slash
This commit is contained in:
@@ -118,6 +118,53 @@ class SsoCallbackViewTest(APITestCase):
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
|
||||
@override_settings(DEBUG=False)
|
||||
def test_callback_without_slash_preserves_form_and_creates_session(self):
|
||||
response = self.client.post(
|
||||
self.callback_url.rstrip("/"),
|
||||
urlencode({"sso_token": self._token(), "redirect_path": "/open-data"}),
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
self.assertEqual(response.status_code, 303)
|
||||
self.assertEqual(response["Location"], "/open-data")
|
||||
self.assertIn("sessionid", response.cookies)
|
||||
self.assertIn("csrftoken", response.cookies)
|
||||
self.assertTrue(response.cookies["sessionid"]["secure"])
|
||||
self.assertTrue(response.cookies["sessionid"]["httponly"])
|
||||
self.assertEqual(self.client.get("/api/v1/users/me/").status_code, 200)
|
||||
|
||||
@override_settings(DEBUG=False)
|
||||
def test_both_callback_urls_reject_invalid_forms_and_get(self):
|
||||
for url in (self.callback_url, self.callback_url.rstrip("/")):
|
||||
with self.subTest(url=url):
|
||||
self.assertEqual(self.client.get(url).status_code, 405)
|
||||
missing = self.client.post(
|
||||
url, "", content_type="application/x-www-form-urlencoded"
|
||||
)
|
||||
self.assertEqual(missing.status_code, 400)
|
||||
unsafe = self.client.post(
|
||||
url,
|
||||
urlencode(
|
||||
{
|
||||
"sso_token": self._token(),
|
||||
"redirect_path": "https://attacker.example/",
|
||||
}
|
||||
),
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
self.assertEqual(unsafe.status_code, 400)
|
||||
|
||||
@override_settings(DEBUG=False)
|
||||
def test_callback_alias_cannot_replay_token_used_on_canonical_url(self):
|
||||
token = self._token()
|
||||
self.assertEqual(self._post_callback(token).status_code, 303)
|
||||
response = self.client.post(
|
||||
self.callback_url.rstrip("/"),
|
||||
urlencode({"sso_token": token}),
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_valid_token_creates_regular_user_identity_and_session(self):
|
||||
response = self._post_callback(self._token())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user