forked from claw/flaskpaste
entropy: exempt small content from check
Small data has unreliable entropy measurement due to sample size. MIN_ENTROPY_SIZE (default 256 bytes) sets the threshold.
This commit is contained in:
@@ -250,9 +250,11 @@ class TestEntropyEnforcement:
|
||||
|
||||
def test_plaintext_rejected(self, entropy_client):
|
||||
"""Plaintext content should be rejected when entropy required."""
|
||||
# Must be >= MIN_ENTROPY_SIZE (256 bytes) to trigger check
|
||||
plaintext = b"Hello, this is plain English text. " * 10 # ~350 bytes
|
||||
response = entropy_client.post(
|
||||
"/",
|
||||
data=b"Hello, this is plain English text with low entropy.",
|
||||
data=plaintext,
|
||||
content_type="text/plain",
|
||||
)
|
||||
assert response.status_code == 400
|
||||
@@ -287,12 +289,23 @@ class TestEntropyEnforcement:
|
||||
|
||||
def test_repeated_bytes_rejected(self, entropy_client):
|
||||
"""Repeated bytes have zero entropy and should be rejected."""
|
||||
# Must be >= MIN_ENTROPY_SIZE (256 bytes) to trigger check
|
||||
response = entropy_client.post(
|
||||
"/",
|
||||
data=b"a" * 1000,
|
||||
data=b"a" * 500,
|
||||
content_type="text/plain",
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
data = response.get_json()
|
||||
assert data["entropy"] == 0.0
|
||||
|
||||
def test_small_content_exempt(self, entropy_client):
|
||||
"""Small content should be exempt from entropy check."""
|
||||
# Content < MIN_ENTROPY_SIZE (256 bytes) should pass
|
||||
response = entropy_client.post(
|
||||
"/",
|
||||
data=b"Small plaintext content",
|
||||
content_type="text/plain",
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
Reference in New Issue
Block a user