Permalink
Browse files

Merge pull request #1423 from privacyidea/python3_update_daplug_test

Update daplug token tests to work with Python 3
  • Loading branch information...
cornelinux committed Feb 5, 2019
2 parents 367f334 + 913b996 commit fe367df7963a202a0f1990f1f7a1a6c374ab3754
Showing with 15 additions and 9 deletions.
  1. +13 −6 privacyidea/lib/tokens/daplugtoken.py
  2. +0 −1 tests/conftest.py
  3. +2 −2 tests/test_lib_tokens_daplug.py
@@ -26,6 +26,8 @@
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from privacyidea.lib.crypto import hexlify_and_unicode

__doc__ = """
This is the token module for the daplug token. It behaves like HOTP,
but uses another OTP format/mapping.
@@ -38,6 +40,7 @@
from privacyidea.lib.log import log_with
from privacyidea.lib.config import get_prepend_pin
from privacyidea.lib.decorators import check_token_locked
from privacyidea.lib.utils import to_bytes, to_unicode
from privacyidea.lib import _
optional = True
required = False
@@ -55,29 +58,33 @@
"i": "7",
"j": "8",
"k": "9"}



REVERSE_MAPPING = {v: k for k, v in MAPPING.items()}


def _daplug2digit(daplug_otp):
hex_otp = ""
for i in daplug_otp:
digit = MAPPING.get(i)
hex_otp += digit
otp = binascii.unhexlify(hex_otp)
# we know the result is a string of digits
otp = to_unicode(binascii.unhexlify(hex_otp))
return otp


def _digi2daplug(normal_otp):
"""
convert "497096" to 34 39 37 30 39 36, which is efekeiebekeh
This function is only used for testing purposes
:param normal_otp:
:type normal_otp: bytes or str
:return:
"""
daplug_otp = ""
hex_otp = binascii.hexlify(normal_otp)
REVERSE_MAP = {v: k for k,v in MAPPING.items()}
hex_otp = hexlify_and_unicode(to_bytes(normal_otp))
for i in hex_otp:
daplug_otp += REVERSE_MAP.get(i)
daplug_otp += REVERSE_MAPPING.get(i)
return daplug_otp

class DaplugTokenClass(HotpTokenClass):
@@ -25,7 +25,6 @@
'test_lib_challenges.py',
'test_lib_importotp.py',
'test_lib_smsprovider.py',
'test_lib_tokens_daplug.py',
'test_lib_tokens_foureyes.py',
'test_lib_tokens_motp.py',
'test_lib_tokens_passwordtoken.py',
@@ -333,10 +333,10 @@ def test_13_check_otp(self):
"pin": "test",
"otplen": 6})
# OTP does not exist
self.assertTrue(token.check_otp_exist(_digi2daplug("222333")) == -1)
self.assertEquals(token.check_otp_exist(_digi2daplug("222333")), -1)
# OTP does exist
res = token.check_otp_exist(_digi2daplug("969429"))
self.assertTrue(res == 3, res)
self.assertEquals(res, 3, res)

def test_14_split_pin_pass(self):
db_token = Token.query.filter_by(serial=self.serial1).first()

0 comments on commit fe367df

Please sign in to comment.