Пример #1
0
 def test_checking_hotp_validity_for_unicode_secret(self):
     """
     Validity check should also work if secret passed to valid_hotp is
     unicode.
     """
     secret = six.u('MFRGGZDFMZTWQ2LK')
     self.assertTrue(valid_hotp(get_hotp(secret, 123), secret))
Пример #2
0
 def test_validating_correct_hotp_after_exhaustion(self):
     """
     Validating token created for old interval number should fail
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     # Act as if the given token was created for previous interval
     self.assertFalse(valid_hotp(get_hotp(secret, 123), secret, last=123))
Пример #3
0
 def test_hotp_for_range_preceding_match(self):
     """
     Check behaviour of validation of values that precede the proper
     interval value
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertFalse(valid_hotp(713385, secret, last=1, trials=2))
Пример #4
0
 def test_validating_correct_totp_as_hotp(self):
     """
     Check if valid TOTP will work as HOTP - should not work, unless for
     very big interval number (matching Unix epoch timestamp)
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertFalse(valid_hotp(get_totp(secret), secret))
Пример #5
0
 def test_validating_correct_totp_as_hotp(self):
     """
     Check if valid TOTP will work as HOTP - should not work, unless for
     very big interval number (matching Unix epoch timestamp)
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertFalse(valid_hotp(get_totp(secret), secret))
Пример #6
0
 def test_hotp_for_range_preceding_match(self):
     """
     Check behaviour of validation of values that precede the proper
     interval value
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertFalse(valid_hotp(713385, secret, last=1, trials=2))
Пример #7
0
 def test_validating_correct_hotp_after_exhaustion(self):
     """
     Validating token created for old interval number should fail
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     # Act as if the given token was created for previous interval
     self.assertFalse(valid_hotp(get_hotp(secret, 123), secret, last=123))
Пример #8
0
 def test_checking_hotp_validity_for_unicode_secret(self):
     """
     Validity check should also work if secret passed to valid_hotp is
     unicode.
     """
     secret = six.u('MFRGGZDFMZTWQ2LK')
     self.assertTrue(valid_hotp(get_hotp(secret, 123), secret))
Пример #9
0
 def test_retrieving_proper_interval_from_validator(self):
     """
     Check, if returns valid interval when checking the valid HOTP
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     totp = 713385
     result = valid_hotp(totp, secret, last=1, trials=5)
     # Should be 4, as HOTP is valid for 4th interval
     self.assertEqual(result, 4)
     # Re-generate HOTP for this specific interval and check again
     self.assertEqual(get_hotp(secret, intervals_no=4), totp)
Пример #10
0
 def test_retrieving_proper_interval_from_validator(self):
     """
     Check, if returns valid interval when checking the valid HOTP
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     totp = 713385
     result = valid_hotp(totp, secret, last=1, trials=5)
     # Should be 4, as HOTP is valid for 4th interval
     self.assertEqual(result, 4)
     # Re-generate HOTP for this specific interval and check again
     self.assertEqual(get_hotp(secret, intervals_no=4), totp)
Пример #11
0
def verifyOTP():

    token = request.args.get('otp', None)
    email = request.args.get('email', None)

    user = User.query.filter_by(email=email).first()
    is_valid = otp.valid_hotp(token=token, secret=user.secKey)

    response = {}
    if (not is_valid):
        response['success'] = False
    else:
        response['success'] = True
    return jsonify(response)
Пример #12
0
 def test_checking_hotp_validity_without_range(self):
     """
     Check if validating HOTP without giving any interval works properly
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertTrue(valid_hotp(get_hotp(secret, 123), secret))
Пример #13
0
 def test_checking_hotp_validity_without_range(self):
     """
     Check if validating HOTP without giving any interval works properly
     """
     secret = b'MFRGGZDFMZTWQ2LK'
     self.assertTrue(valid_hotp(get_hotp(secret, 123), secret))