Skip to content

Commit bf0ddaf

Browse files
committed
Add test for large blob size bound
1 parent 591fb17 commit bf0ddaf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/device/test_largeblobs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fido2.ctap2.blob import LargeBlobs
44
from fido2.server import Fido2Server
55
from fido2.utils import websafe_encode, websafe_decode
6+
from fido2 import cbor
67
from . import TEST_PIN
78

89
import os
@@ -49,6 +50,27 @@ def test_read_write(ctap2, pin_protocol):
4950
assert len(lb.read_blob_array()) == 0
5051

5152

53+
def test_size_bounds(ctap2, pin_protocol):
54+
lb = get_lb(ctap2, pin_protocol)
55+
assert len(lb.read_blob_array()) == 0
56+
57+
size = ctap2.info.max_large_blob
58+
59+
# Create data which when cbor-encoded is exactly size bytes
60+
array = [{1: os.urandom(size - 8)}]
61+
array.extend([0] * (size - len(cbor.encode(array))))
62+
63+
lb.write_blob_array(array)
64+
65+
# Ensure writing larger data fails:
66+
array.append(1)
67+
with pytest.raises(CtapError, match="LARGE_BLOB_STORAGE_FULL"):
68+
lb.write_blob_array(array)
69+
70+
# Clear the data
71+
lb.write_blob_array([])
72+
73+
5274
def test_missing_permissions(ctap2, pin_protocol):
5375
key = os.urandom(32)
5476
data = b"test data"

0 commit comments

Comments
 (0)