From b62bdde3034bb618365ba8e3160f34fc5b928d2f Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Mon, 12 Mar 2018 18:38:12 +0530 Subject: [PATCH] login_redirects: Make redirects to narrows from login page work. --- templates/zerver/dev_login.html | 8 +++++++- templates/zerver/login.html | 12 +++++++++--- zerver/tests/test_auth_backends.py | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/templates/zerver/dev_login.html b/templates/zerver/dev_login.html index a32db335dd..01988ebcf6 100644 --- a/templates/zerver/dev_login.html +++ b/templates/zerver/dev_login.html @@ -57,7 +57,13 @@ {% endblock %} diff --git a/templates/zerver/login.html b/templates/zerver/login.html index 10ba8c9470..0e4fbe6b93 100644 --- a/templates/zerver/login.html +++ b/templates/zerver/login.html @@ -125,7 +125,7 @@ {% if google_auth_enabled %}
-
+
@@ -134,7 +134,7 @@ {% if github_auth_enabled %} diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 43a60a93a9..0f4dd07723 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -642,6 +642,12 @@ class GitHubAuthBackendTest(ZulipTestCase): self.assertIn('is_signup=0', result.url) self.assertIn('image_path', result.url) + result = self.client_get('/accounts/login/social/github', + {'next': '/#narrow/stream/7-test-here'}) + self.assertIn(reverse('social:begin', args=['github']), result.url) + self.assertIn('is_signup=0', result.url) + self.assertIn('narrow', result.url) + def test_signup_url(self) -> None: result = self.client_get('/accounts/register/social/github') self.assertIn(reverse('social:begin', args=['github']), result.url) @@ -830,6 +836,10 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest): self.assertEqual(res.status_code, 302) self.assertEqual(res.url, 'http://zulip.testserver/user_uploads/path_to_image') + res = test_redirect_to_next_url('/#narrow/stream/7-test-here') + self.assertEqual(res.status_code, 302) + self.assertEqual(res.url, 'http://zulip.testserver/#narrow/stream/7-test-here') + def test_log_into_subdomain(self) -> None: data = {'name': 'Full Name', 'email': self.example_email("hamlet"), @@ -1507,6 +1517,14 @@ class TestDevAuthBackend(ZulipTestCase): self.assertEqual(res.status_code, 302) self.assertEqual(res.url, 'http://zulip.testserver/user_uploads/path_to_image') + # In local Email based authentication we never make browser send the hash + # to the backend. Rather we depend upon the browser's behaviour of persisting + # hash anchors in between redirect requests. See below stackoverflow conversation + # https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects + res = do_local_login('/accounts/login/local/?next=#narrow/stream/7-test-here') + self.assertEqual(res.status_code, 302) + self.assertEqual(res.url, 'http://zulip.testserver') + def test_login_with_subdomain(self) -> None: user_profile = self.example_user('hamlet') email = user_profile.email