Skip to content

Commit e9ba64b

Browse files
author
Rebecka Gulliksson
committed
Cleanup of tests expecting an exception (using py.test instead or rewritten).
1 parent 42b52e7 commit e9ba64b

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/jwkest/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ def b64d(b):
166166
:param b: bytes
167167
"""
168168

169-
if b.endswith(b'='): # shouldn't but there you are
170-
cb = b.split(b'=')[0]
171-
else:
172-
cb = b
169+
cb = b.rstrip(b"=") # shouldn't but there you are
173170

174171
# Python's base64 functions ignore invalid characters, so we need to
175172
# check for them explicitly.

tests/test_0_jwkest.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import base64
12
import os
23
import struct
3-
from jwkest import long2intarr
4+
from jwkest import long2intarr, b64d, b64e
45
from jwkest import intarr2long
56
from jwkest import base64_to_long
67
from jwkest import long_to_base64
@@ -14,11 +15,13 @@
1415
def full_path(local_file):
1516
return os.path.join(BASEDIR, local_file)
1617

18+
1719
CERT = full_path("cert.pem")
1820
KEY = full_path("server.key")
1921

2022
_CKEY = pem_cert2rsa(CERT)
2123

24+
2225
def test_long_intarr_long():
2326
ia = long2intarr(_CKEY.n)
2427
_n = intarr2long(ia)
@@ -39,5 +42,16 @@ def test_long_base64_long():
3942
assert _CKEY.n == l
4043

4144

45+
def test_b64d_with_padded_data():
46+
data = "abcd".encode("utf-8")
47+
encoded = base64.urlsafe_b64encode(data)
48+
assert b64d(encoded) == data
49+
50+
51+
def test_b64_encode_decode():
52+
data = "abcd".encode("utf-8")
53+
assert b64d(b64e(data)) == data
54+
55+
4256
if __name__ == "__main__":
43-
test_long_base64_long()
57+
test_long_base64_long()

0 commit comments

Comments
 (0)