TOTP auth not functional in python3

Fixing a byte>str conversion bug present in the TOTP
passcode generation function that was only present in python3
which rendered TOTP auth non-functional in python3.

Also adding a test to check passcode generation returns the
correct format.

Closes-Bug: #1607119

Change-Id: Ie052d559c4eb2577d35caa9f6e240664cf4cf399
This commit is contained in:
adriant 2016-07-28 11:24:58 +12:00
parent 9d54eb33c1
commit b2cb4c403f
2 changed files with 8 additions and 1 deletions

View File

@ -62,7 +62,7 @@ def _generate_totp_passcode(secret):
decoded = base64.b32decode(secret)
totp = crypto_totp.TOTP(
decoded, 6, hashes.SHA1(), 30, backend=default_backend())
return six.text_type(totp.generate(timeutils.utcnow_ts(microsecond=True)))
return totp.generate(timeutils.utcnow_ts(microsecond=True)).decode('utf-8')
@dependency.requires('credential_api')

View File

@ -16,6 +16,7 @@ import copy
import datetime
import itertools
import operator
import re
import uuid
from keystoneclient.common import cms
@ -5070,6 +5071,12 @@ class TestAuthTOTP(test_v3.RestfulTestCase):
self.v3_create_token(auth_data, expected_status=http_client.CREATED)
def test_generated_passcode_is_correct_format(self):
secret = self._make_credentials('totp')[-1]['blob']
passcode = totp._generate_totp_passcode(secret)
reg = re.compile(r'^-?[0-9]+$')
self.assertTrue(reg.match(passcode))
class TestFetchRevocationList(object):
"""Test fetch token revocation list on the v3 Identity API."""