Пример #1
0
    def test_no_token(self):
        data = {
            'username': '******',
            'password': '******',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        self.assertTrue(form.get_user().get_username() == 'alice')
Пример #2
0
    def test_no_token(self):
        data = {
            'username': '******',
            'password': '******',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.get_user().get_username(), 'alice')
Пример #3
0
    def test_bad_password(self):
        data = {
            'username': '******',
            'password': '******',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        self.assertTrue(form.get_user() is None)
        self.assertEqual(list(form.errors.keys()), ['__all__'])
Пример #4
0
    def test_bad_password(self):
        data = {
            'username': '******',
            'password': '******',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        self.assertTrue(form.get_user() is None)
        self.assertEqual(list(form.errors.keys()), ['__all__'])
Пример #5
0
    def test_email_interaction(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'otp_email.emaildevice/1',
            'otp_token': '',
            'otp_challenge': '1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertFalse(form.is_valid())
        alice = form.get_user()
        self.assertEqual(alice.get_username(), 'alice')
        self.assertIsNone(alice.otp_device)
        self.assertEqual(len(mail.outbox), 1)

        data['otp_token'] = mail.outbox[0].body
        del data['otp_challenge']
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        self.assertIsInstance(form.get_user().otp_device, EmailDevice)
Пример #6
0
    def test_specific_device(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'django_otp.plugins.otp_static.models.StaticDevice/1',
            'otp_token': 'alice1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        alice = form.get_user()
        self.assertTrue(alice.get_username() == 'alice')
        self.assertTrue(alice.otp_device is not None)
Пример #7
0
    def test_passive_token(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_token': 'alice1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        alice = form.get_user()
        self.assertTrue(alice.get_username() == 'alice')
        self.assertTrue(isinstance(alice.otp_device, StaticDevice))
        self.assertEqual(alice.otp_device.token_set.count(), 2)
Пример #8
0
    def test_specific_device(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'otp_static.staticdevice/1',
            'otp_token': 'alice1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        alice = form.get_user()
        self.assertEqual(alice.get_username(), 'alice')
        self.assertIsNotNone(alice.otp_device)
Пример #9
0
    def test_passive_token(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_token': 'alice1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        alice = form.get_user()
        self.assertEqual(alice.get_username(), 'alice')
        self.assertIsInstance(alice.otp_device, StaticDevice)
        self.assertEqual(alice.otp_device.token_set.count(), 2)
Пример #10
0
    def test_email_interaction(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'django_otp.plugins.otp_email.models.EmailDevice/1',
            'otp_token': '',
            'otp_challenge': '1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        alice = form.get_user()
        self.assertTrue(alice.get_username() == 'alice')
        self.assertTrue(alice.otp_device is None)
        self.assertEqual(len(mail.outbox), 1)

        data['otp_token'] = mail.outbox[0].body
        del data['otp_challenge']
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        self.assertTrue(isinstance(form.get_user().otp_device, EmailDevice))
Пример #11
0
    def test_specific_device_fail(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'django_otp.plugins.otp_email.models.StaticDevice/1',
            'otp_token': 'bogus',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        alice = form.get_user()
        self.assertTrue(alice.get_username() == 'alice')
        self.assertTrue(alice.otp_device is None)
Пример #12
0
    def test_email_interaction(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'django_otp.plugins.otp_email.models.EmailDevice/1',
            'otp_token': '',
            'otp_challenge': '1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        alice = form.get_user()
        self.assertTrue(alice.get_username() == 'alice')
        self.assertTrue(alice.otp_device is None)
        self.assertEqual(len(mail.outbox), 1)

        data['otp_token'] = mail.outbox[0].body
        del data['otp_challenge']
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(form.is_valid())
        self.assertTrue(isinstance(form.get_user().otp_device, EmailDevice))
Пример #13
0
    def test_custom_user(self):
        data = {
            'username': '******',
            'password': '******',
            'otp_device': 'django_otp.plugins.otp_static.models.StaticDevice/1',
            'otp_token': 'alice1',
        }
        form = OTPAuthenticationForm(None, data)

        self.assert_(form.is_valid())
        alice = form.get_user()
        self.assert_(isinstance(alice, TestUser))
        if hasattr(alice, 'get_username'):
            self.assertEqual(alice.get_username(), 'alice')
        else:
            self.assertEqual(alice.username, 'alice')
        self.assert_(alice.otp_device is not None)
Пример #14
0
    def test_empty(self):
        data = {}
        form = OTPAuthenticationForm(None, data)

        self.assertTrue(not form.is_valid())
        self.assertEqual(form.get_user(), None)
Пример #15
0
    def test_empty(self):
        data = {}
        form = OTPAuthenticationForm(None, data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.get_user(), None)