mirror of
https://github.com/zulip/zulip.git
synced 2026-06-27 21:01:32 +08:00
redirect_and_log_into_subdomain: Handle is_signup.
This commit is contained in:
parent
4ab783134e
commit
8b88cfc84b
@ -18,7 +18,8 @@ from zilencer.models import Deployment
|
||||
from zerver.forms import HomepageForm, WRONG_SUBDOMAIN_ERROR
|
||||
from zerver.lib.actions import do_change_password
|
||||
from zerver.views.invite import get_invitee_emails_set
|
||||
from zerver.views.registration import confirmation_key
|
||||
from zerver.views.registration import (confirmation_key,
|
||||
redirect_and_log_into_subdomain)
|
||||
from zerver.models import (
|
||||
get_realm, get_prereg_user_by_email, get_user_profile_by_email,
|
||||
get_unique_open_realm, completely_open,
|
||||
@ -44,7 +45,7 @@ from zerver.lib.digest import send_digest_email
|
||||
from zerver.lib.notifications import (
|
||||
enqueue_welcome_emails, one_click_unsubscribe_link, send_local_email_template_with_delay)
|
||||
from zerver.lib.test_helpers import find_pattern_in_email, find_key_by_email, queries_captured, \
|
||||
HostRequestMock
|
||||
HostRequestMock, unsign_subdomain_cookie
|
||||
from zerver.lib.test_classes import (
|
||||
ZulipTestCase,
|
||||
)
|
||||
@ -62,6 +63,25 @@ from six.moves import range
|
||||
from typing import Any, Text
|
||||
import os
|
||||
|
||||
class RedirectAndLogIntoSubdomainTestCase(ZulipTestCase):
|
||||
def test_cookie_data(self):
|
||||
# type: () -> None
|
||||
realm = Realm.objects.all().first()
|
||||
name = 'Hamlet'
|
||||
email = 'hamlet@zulip.com'
|
||||
response = redirect_and_log_into_subdomain(realm, name, email)
|
||||
data = unsign_subdomain_cookie(response)
|
||||
self.assertDictEqual(data, {'name': name, 'email': email,
|
||||
'subdomain': realm.subdomain,
|
||||
'is_signup': False})
|
||||
|
||||
response = redirect_and_log_into_subdomain(realm, name, email,
|
||||
is_signup=True)
|
||||
data = unsign_subdomain_cookie(response)
|
||||
self.assertDictEqual(data, {'name': name, 'email': email,
|
||||
'subdomain': realm.subdomain,
|
||||
'is_signup': True})
|
||||
|
||||
class AddNewUserHistoryTest(ZulipTestCase):
|
||||
def test_add_new_user_history_race(self):
|
||||
# type: () -> None
|
||||
|
||||
@ -40,8 +40,9 @@ import ujson
|
||||
|
||||
from six.moves import urllib
|
||||
|
||||
def redirect_and_log_into_subdomain(realm, full_name, email_address):
|
||||
# type: (Realm, Text, Text) -> HttpResponse
|
||||
def redirect_and_log_into_subdomain(realm, full_name, email_address,
|
||||
is_signup=False):
|
||||
# type: (Realm, Text, Text, bool) -> HttpResponse
|
||||
subdomain_login_uri = ''.join([
|
||||
realm.uri,
|
||||
reverse('zerver.views.auth.log_into_subdomain')
|
||||
@ -50,7 +51,8 @@ def redirect_and_log_into_subdomain(realm, full_name, email_address):
|
||||
domain = '.' + settings.EXTERNAL_HOST.split(':')[0]
|
||||
response = redirect(subdomain_login_uri)
|
||||
|
||||
data = {'name': full_name, 'email': email_address, 'subdomain': realm.subdomain}
|
||||
data = {'name': full_name, 'email': email_address, 'subdomain': realm.subdomain,
|
||||
'is_signup': is_signup}
|
||||
# Creating a singed cookie so that it cannot be tampered with.
|
||||
# Cookie and the signature expire in 15 seconds.
|
||||
response.set_signed_cookie('subdomain.signature',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user