Exemplo n.º 1
0
    def test_non_ascii_login(self):
        """
        You can log in even if your password contain non-ASCII characters.
        """
        email = "*****@*****.**"
        password = u"hümbüǵ"

        # Registering succeeds.
        self.register("test", password)
        user_profile = get_user_profile_by_email(email)
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
        self.client.post('/accounts/logout/')
        self.assertIsNone(get_session_dict_user(self.client.session))

        # Logging in succeeds.
        self.client.post('/accounts/logout/')
        self.login(email, password)
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 2
0
    def test_non_ascii_login(self):
        """
        You can log in even if your password contain non-ASCII characters.
        """
        email = "*****@*****.**"
        password = u"hümbüǵ"

        # Registering succeeds.
        self.register("test", password)
        user_profile = get_user_profile_by_email(email)
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
        self.client.post('/accounts/logout/')
        self.assertIsNone(get_session_dict_user(self.client.session))

        # Logging in succeeds.
        self.client.post('/accounts/logout/')
        self.login(email, password)
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 3
0
    def test_google_oauth2_no_fullname(self):
        # type: () -> None
        token_response = ResponseMock(200, {'access_token': "unique_token"})
        account_data = dict(name=dict(givenName="Test", familyName="User"),
                            emails=[dict(type="account",
                                         value="*****@*****.**")])
        account_response = ResponseMock(200, account_data)
        self.google_oauth2_test(token_response, account_response)

        user_profile = get_user_profile_by_email('*****@*****.**')
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 4
0
    def test_register(self):
        realm = get_realm("zulip.com")
        streams = ["stream_%s" % i for i in range(40)]
        for stream in streams:
            create_stream_if_needed(realm, stream)

        set_default_streams(realm, streams)
        with queries_captured() as queries:
            self.register("test", "test")
        # Ensure the number of queries we make is not O(streams)
        self.assert_length(queries, 74)
        user_profile = get_user_profile_by_email('*****@*****.**')
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 5
0
    def test_register(self):
        realm = get_realm("zulip.com")
        streams = ["stream_%s" % i for i in range(40)]
        for stream in streams:
            create_stream_if_needed(realm, stream)

        set_default_streams(realm, streams)
        with queries_captured() as queries:
            self.register("test", "test")
        # Ensure the number of queries we make is not O(streams)
        self.assert_length(queries, 67)
        user_profile = get_user_profile_by_email('*****@*****.**')
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 6
0
    def test_password_reset(self):
        # type: () -> None
        email = '*****@*****.**'
        old_password = initial_password(email)

        self.login(email)

        # start the password reset process by supplying an email address
        result = self.client_post('/accounts/password/reset/', {'email': email})

        # check the redirect link telling you to check mail for password reset link
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith(
                "/accounts/password/reset/done/"))
        result = self.client_get(result["Location"])

        self.assert_in_response("Check your email to finish the process.", result)

        # visit password reset link
        from django.core.mail import outbox
        for message in reversed(outbox):
            if email in message.to:
                password_reset_pattern = re.compile(settings.EXTERNAL_HOST + "(\S+)")
                password_reset_url = password_reset_pattern.search(
                    message.body).groups()[0]
                break
        else:
            raise ValueError("Couldn't find a password reset email.")

        result = self.client_get(password_reset_url)
        self.assertEquals(result.status_code, 200)

        # Reset your password
        result = self.client_post(password_reset_url,
                                  {'new_password1': 'new_password',
                                   'new_password2': 'new_password'})

        # password reset succeeded
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith("/password/done/"))

        # log back in with new password
        self.login(email, password='******')
        user_profile = get_user_profile_by_email('*****@*****.**')
        self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)

        # make sure old password no longer works
        self.login(email, password=old_password, fails=True)
Exemplo n.º 7
0
 def test_logout(self):
     self.login("*****@*****.**")
     self.client.post('/accounts/logout/')
     self.assertIsNone(get_session_dict_user(self.client.session))
Exemplo n.º 8
0
 def test_login_bad_password(self):
     self.login("*****@*****.**", "wrongpassword")
     self.assertIsNone(get_session_dict_user(self.client.session))
Exemplo n.º 9
0
 def test_login(self):
     self.login("*****@*****.**")
     user_profile = get_user_profile_by_email('*****@*****.**')
     self.assertEqual(get_session_dict_user(self.client.session),
                      user_profile.id)
Exemplo n.º 10
0
 def test_logout(self):
     # type: () -> None
     self.login("*****@*****.**")
     self.client_post('/accounts/logout/')
     self.assertIsNone(get_session_dict_user(self.client.session))
Exemplo n.º 11
0
 def test_login_bad_password(self):
     # type: () -> None
     self.login("*****@*****.**", password="******", fails=True)
     self.assertIsNone(get_session_dict_user(self.client.session))
Exemplo n.º 12
0
 def test_login(self):
     # type: () -> None
     self.login("*****@*****.**")
     user_profile = get_user_profile_by_email('*****@*****.**')
     self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
Exemplo n.º 13
0
 def test_login_bad_password(self):
     self.login("*****@*****.**", "wrongpassword")
     self.assertIsNone(get_session_dict_user(self.client.session))