fix: minor edge case in `long_to_base64` utility function.

This was detected by mypy.
This commit is contained in:
Régis Behmo 2021-02-25 09:54:46 +01:00
parent 59e368a449
commit de872282b2
3 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,8 @@ Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- [Bugfix] Fix minor edge case in `long_to_base64` utility function.
## v11.2.3 (2021-02-20)
- [Bugfix] Make LMS celery workers actually process LMS tasks, and not CMS tasks.

View File

@ -1,3 +1,4 @@
import base64
import unittest
from tutor import utils
@ -30,3 +31,6 @@ class UtilsTests(unittest.TestCase):
self.assertNotEqual(encrypted1, encrypted2)
self.assertTrue(utils.verify_encrypted(encrypted1, password))
self.assertTrue(utils.verify_encrypted(encrypted2, password))
def test_long_to_base64(self):
self.assertEqual(b"\x00", base64.urlsafe_b64decode(utils.long_to_base64(0) + "=="))

View File

@ -112,7 +112,7 @@ def long_to_base64(n):
bys = long2intarr(n)
data = struct.pack("%sB" % len(bys), *bys)
if not data:
data = "\x00"
data = b"\x00"
s = base64.urlsafe_b64encode(data).rstrip(b"=")
return s.decode("ascii")