def test_verify_valid_core_drift(self):
        # use a code from 30 seconds in the future
        assert_true(
            self.user_settings.verify_code(
                _valid_code(self.TOTP_SECRET, drift=1)
            )
        )

        # make sure drift is updated.
        assert_equal(self.user_settings.totp_drift, 1)

        # use a code from 60 seconds in the future
        assert_true(
            self.user_settings.verify_code(
                _valid_code(self.TOTP_SECRET, drift=2)
            )
        )

        # make sure drift is updated.
        assert_equal(self.user_settings.totp_drift, 2)

        # use the current code (which is now 2 periods away from the drift)
        assert_false(
            self.user_settings.verify_code(_valid_code(self.TOTP_SECRET))
        )
示例#2
0
    def test_verify_valid_core_drift(self):
        # use a code from 30 seconds in the future
        assert_true(
            self.user_settings.verify_code(
                _valid_code(self.TOTP_SECRET, drift=1)))

        # make sure drift is updated.
        assert_equal(self.user_settings.totp_drift, 1)

        # use a code from 60 seconds in the future
        assert_true(
            self.user_settings.verify_code(
                _valid_code(self.TOTP_SECRET, drift=2)))

        # make sure drift is updated.
        assert_equal(self.user_settings.totp_drift, 2)

        # use the current code (which is now 2 periods away from the drift)
        assert_false(
            self.user_settings.verify_code(_valid_code(self.TOTP_SECRET)))
示例#3
0
    def test_update_two_factor_verification(self, app, user_one, url, payload):
        TOTP_SECRET = 'b8f85986068f8079aa9d'
        # Two factor not enabled
        payload['data']['attributes']['two_factor_verification'] = 123456
        res = app.patch_json_api(url,
                                 payload,
                                 auth=user_one.auth,
                                 expect_errors=True)
        assert res.status_code == 400
        assert res.json['errors'][0][
            'detail'] == 'Two-factor authentication is not enabled.'

        # Two factor invalid code
        payload['data']['attributes']['two_factor_enabled'] = True
        payload['data']['attributes']['two_factor_verification'] = 123456
        res = app.patch_json_api(url,
                                 payload,
                                 auth=user_one.auth,
                                 expect_errors=True)
        assert res.status_code == 403
        assert res.json['errors'][0][
            'detail'] == 'The two-factor verification code you provided is invalid.'

        # Test invalid data type
        payload['data']['attributes']['two_factor_verification'] = 'abcd123'
        res = app.patch_json_api(url,
                                 payload,
                                 auth=user_one.auth,
                                 expect_errors=True)
        assert res.status_code == 400
        assert res.json['errors'][0][
            'detail'] == 'A valid integer is required.'

        # Test two factor valid code
        del payload['data']['attributes']['two_factor_verification']
        res = app.patch_json_api(url,
                                 payload,
                                 auth=user_one.auth,
                                 expect_errors=True)
        addon = user_one.get_addon('twofactor')
        addon.totp_secret = TOTP_SECRET
        addon.save()
        payload['data']['attributes']['two_factor_verification'] = _valid_code(
            TOTP_SECRET)
        res = app.patch_json_api(url,
                                 payload,
                                 auth=user_one.auth,
                                 expect_errors=True)
        assert res.json['data']['attributes']['two_factor_enabled'] is True
        assert res.status_code == 200
        user_one.reload()
        addon = user_one.get_addon('twofactor')
        assert addon.deleted is False
        assert addon.is_confirmed is True
 def test_verify_valid_code(self):
     assert_true(
         self.user_settings.verify_code(_valid_code(self.TOTP_SECRET))
     )
示例#5
0
 def test_verify_valid_code(self):
     assert_true(
         self.user_settings.verify_code(_valid_code(self.TOTP_SECRET)))