Skip to content

Commit fd01efe

Browse files
committed
Fix off by one error in metadata tests [skip ci]
1 parent 98f14bc commit fd01efe

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/mock_vws/_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,8 @@ def validate_metadata_size(
906906
return wrapped(*args, **kwargs)
907907
decoded = base64.b64decode(application_metadata)
908908

909-
if len(decoded) <= 1024 * 1024:
909+
max_metadata_bytes = 1024 * 1024 - 1
910+
if len(decoded) <= max_metadata_bytes:
910911
return wrapped(*args, **kwargs)
911912

912913
context.status_code = codes.UNPROCESSABLE_ENTITY

tests/mock_vws/test_add_target.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,13 @@ class TestApplicationMetadata:
645645
Tests for the application metadata parameter.
646646
"""
647647

648+
_MAX_METADATA_BYTES = 1024 * 1024 - 1
649+
648650
@pytest.mark.parametrize(
649651
'metadata',
650652
[
651653
b'a',
652-
b'a' * (1024 * 1024),
654+
b'a' * _MAX_METADATA_BYTES,
653655
],
654656
ids=['Short', 'Max length'],
655657
)
@@ -781,12 +783,12 @@ def test_metadata_too_large(
781783
png_rgb: io.BytesIO,
782784
) -> None:
783785
"""
784-
A base64 encoded string of up to 1024 * 1024 bytes is valid application
785-
metadata.
786+
A base64 encoded string of greater than 1024 * 1024 bytes is too large
787+
for application metadata.
786788
"""
787789
image_data = png_rgb.read()
788790
image_data_encoded = base64.b64encode(image_data).decode('ascii')
789-
metadata = b'a' * (1024 * 1024 + 1)
791+
metadata = b'a' * (self._MAX_METADATA_BYTES + 1)
790792
metadata_encoded = base64.b64encode(metadata).decode('ascii')
791793

792794
data = {

0 commit comments

Comments
 (0)