def test_send_confirmation_of_already_confirmed_account(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        self.client.get('/confirm/' + token, follow_redirects=True)
        self.logout()
        r = self._post('/confirm', data=dict(email=e))
        self.assertIn(self.get_message('ALREADY_CONFIRMED'), r.data)
    def test_confirm_email(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        r = self.client.get('/confirm/' + token, follow_redirects=True)

        msg = self.app.config['SECURITY_MSG_EMAIL_CONFIRMED'][0]
        self.assertIn(msg, r.data)
Example #3
0
    def test_send_confirmation_of_already_confirmed_account(self):
        e = "*****@*****.**"

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]["confirm_token"]

        self.client.get("/confirm/" + token, follow_redirects=True)
        self.logout()
        r = self.client.post("/confirm", data=dict(email=e))
        self.assertIn(self.get_message("ALREADY_CONFIRMED"), r.data)
Example #4
0
    def test_confirm_email(self):
        e = "*****@*****.**"

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]["confirm_token"]

        r = self.client.get("/confirm/" + token, follow_redirects=True)

        msg = self.app.config["SECURITY_MSG_EMAIL_CONFIRMED"][0]
        self.assertIn(msg, r.data)
    def test_confirm_email(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        r = self.client.get('/confirm/' + token, follow_redirects=True)

        msg = self.app.config['SECURITY_MSG_EMAIL_CONFIRMED'][0]
        self.assertIn(msg, r.data)
    def test_send_confirmation_of_already_confirmed_account(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        self.client.get('/confirm/' + token, follow_redirects=True)
        self.logout()
        r = self._post('/confirm', data=dict(email=e))
        self.assertIn(self.get_message('ALREADY_CONFIRMED'), r.data)
Example #7
0
    def test_confirm_email_twice_flashes_already_confirmed_message(self):
        e = "*****@*****.**"

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]["confirm_token"]

        url = "/confirm/" + token
        self.client.get(url, follow_redirects=True)
        r = self.client.get(url, follow_redirects=True)

        msg = self.app.config["SECURITY_MSG_ALREADY_CONFIRMED"][0]
        self.assertIn(msg, r.data)
    def test_user_deleted_before_confirmation(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            user = registrations[0]['user']
            token = registrations[0]['confirm_token']

        with self.app.app_context():
            from flask_security.core import _security
            _security.datastore.delete(user)
            _security.datastore.commit()

        r = self.client.get('/confirm/' + token, follow_redirects=True)
        msg = self.app.config['SECURITY_MSG_INVALID_CONFIRMATION_TOKEN'][0]
        self.assertIn(msg, r.data)
    def test_user_deleted_before_confirmation(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            user = registrations[0]['user']
            token = registrations[0]['confirm_token']

        with self.app.app_context():
            from flask_security.core import _security
            _security.datastore.delete(user)
            _security.datastore.commit()

        r = self.client.get('/confirm/' + token, follow_redirects=True)
        msg = self.app.config['SECURITY_MSG_INVALID_CONFIRMATION_TOKEN'][0]
        self.assertIn(msg, r.data)
    def test_confirm_email_of_user_different_than_current_user(self):
        e1 = '*****@*****.**'
        e2 = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e1)
            self.register(e2)
            token1 = registrations[0]['confirm_token']
            token2 = registrations[1]['confirm_token']

        self.client.get('/confirm/' + token1, follow_redirects=True)
        self.client.get('/logout')
        self.authenticate(email=e1)
        r = self.client.get('/confirm/' + token2, follow_redirects=True)
        msg = self.app.config['SECURITY_MSG_EMAIL_CONFIRMED'][0]
        self.assertIn(msg, r.data)
        self.assertIn('Hello %s' % e2, r.data)
Example #11
0
    def test_confirm_email_of_user_different_than_current_user(self):
        e1 = '*****@*****.**'
        e2 = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e1)
            self.register(e2)
            token1 = registrations[0]['confirm_token']
            token2 = registrations[1]['confirm_token']

        self.client.get('/confirm/' + token1, follow_redirects=True)
        self.client.get('/logout')
        self.authenticate(email=e1)
        r = self.client.get('/confirm/' + token2, follow_redirects=True)
        msg = self.app.config['SECURITY_MSG_EMAIL_CONFIRMED'][0]
        self.assertIn(msg, r.data)
        self.assertIn('Hello %s' % e2, r.data)
    def test_expired_confirmation_token_sends_email(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        time.sleep(1.25)

        with self.app.extensions['mail'].record_messages() as outbox:
            r = self.client.get('/confirm/' + token, follow_redirects=True)

            self.assertEqual(len(outbox), 1)
            self.assertNotIn(token, outbox[0].html)

            expire_text = self.AUTH_CONFIG['SECURITY_CONFIRM_EMAIL_WITHIN']
            msg = self.app.config['SECURITY_MSG_CONFIRMATION_EXPIRED'][0]
            msg = msg % dict(within=expire_text, email=e)
            self.assertIn(msg, r.data)
Example #13
0
    def test_expired_confirmation_token_sends_email(self):
        e = "*****@*****.**"

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]["confirm_token"]

        time.sleep(3)

        with self.app.extensions["mail"].record_messages() as outbox:
            r = self.client.get("/confirm/" + token, follow_redirects=True)

            self.assertEqual(len(outbox), 1)
            self.assertIn(e, outbox[0].html)
            self.assertNotIn(token, outbox[0].html)

            expire_text = self.AUTH_CONFIG["SECURITY_CONFIRM_EMAIL_WITHIN"]
            msg = self.app.config["SECURITY_MSG_CONFIRMATION_EXPIRED"][0] % dict(within=expire_text, email=e)
            self.assertIn(msg, r.data)
    def test_expired_confirmation_token_sends_email(self):
        e = '*****@*****.**'

        with capture_registrations() as registrations:
            self.register(e)
            token = registrations[0]['confirm_token']

        time.sleep(1.25)

        with self.app.extensions['mail'].record_messages() as outbox:
            r = self.client.get('/confirm/' + token, follow_redirects=True)

            self.assertEqual(len(outbox), 1)
            self.assertNotIn(token, outbox[0].html)

            expire_text = self.AUTH_CONFIG['SECURITY_CONFIRM_EMAIL_WITHIN']
            msg = self.app.config['SECURITY_MSG_CONFIRMATION_EXPIRED'][0]
            msg = msg % dict(within=expire_text, email=e)
            self.assertIn(msg, r.data)