Esempio n. 1
0
 def test_confirm_bad_token(self):
     e = '*****@*****.**'
     with capture_registrations() as registrations:
         self.register(e)
         token = registrations[0]['confirm_token']
     with capture_signals() as mocks:
         self.client.get('/confirm/bogus', follow_redirects=True)
     self.assertEqual(mocks.signals_sent(), set())
Esempio n. 2
0
 def test_confirm_twice(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()
     with capture_signals() as mocks:
         self.client.get('/confirm/' + token, follow_redirects=True)
     self.assertEqual(mocks.signals_sent(), set([user_confirmed]))
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
 def test_confirm(self):
     e = '*****@*****.**'
     with capture_registrations() as registrations:
         self.register(e)
         token = registrations[0]['confirm_token']
     with capture_signals() as mocks:
         self.client.get('/confirm/' + token, follow_redirects=True)
     user = self.app.security.datastore.find_user(email='*****@*****.**')
     self.assertTrue(mocks.signals_sent(), set([user_confirmed]))
     calls = mocks[user_confirmed]
     self.assertEqual(len(calls), 1)
     args, kwargs = calls[0]
     self.assertEqual(args[0].id, user.id)
     self.assertEqual(kwargs['app'], self.app)
Esempio n. 6
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(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)